Ref T376, voice setup form

This commit is contained in:
Klaus Basan
2018-09-28 05:03:37 +02:00
parent b5cf65cefa
commit 0c3a89f1b5
3 changed files with 273 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
/* Copyright (C) 2018
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "voicesetupform.h"
#include "ui_voicesetupform.h"
#include <QIntValidator>
using namespace BlackMisc;
using namespace BlackMisc::Audio;
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Editors
{
CVoiceSetupForm::CVoiceSetupForm(QWidget *parent) :
CForm(parent),
ui(new Ui::CVoiceSetupForm)
{
ui->setupUi(this);
ui->cb_Override->setChecked(true);
QIntValidator *v = new QIntValidator(0, 65535, ui->le_VatsimUdpPort);
ui->le_VatsimUdpPort->setValidator(v);
this->resetToDefaultValues();
connect(ui->cb_Override, &QCheckBox::toggled, this, &CVoiceSetupForm::enabledToggled);
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CVoiceSetupForm::resetToDefaultValues);
}
CVoiceSetupForm::~CVoiceSetupForm()
{ }
CVoiceSetup CVoiceSetupForm::getValue() const
{
const CVoiceSetup s = CVoiceSetup(ui->le_VatsimUdpPort->text().toInt());
return s;
}
const CVoiceSetup &CVoiceSetupForm::getDisabledValue() const
{
static const CVoiceSetup s;
return s;
}
void CVoiceSetupForm::setValue(const CVoiceSetup &setup)
{
ui->le_VatsimUdpPort->setText(QString::number(setup.getVatsimUdpVoicePort()));
}
bool CVoiceSetupForm::isVoiceSetupEnabled() const
{
return ui->cb_Override->isChecked();
}
void CVoiceSetupForm::setVoiceSetupEnabled(bool enabled)
{
ui->cb_Override->setChecked(enabled);
}
void CVoiceSetupForm::showEnableInfo(bool visible)
{
m_visibleEnableInfo = visible;
this->visibleEnableInfo(visible);
}
void CVoiceSetupForm::setReadOnly(bool readonly)
{
ui->pb_SetDefaults->setEnabled(!readonly);
ui->le_VatsimUdpPort->setReadOnly(readonly);
this->forceStyleSheetUpdate();
}
CStatusMessageList CVoiceSetupForm::validate(bool nested) const
{
Q_UNUSED(nested);
const CVoiceSetup val(this->getValue());
CStatusMessageList msgs(val.validate());
if (this->isReadOnly())
{
// in readonly I cannot change the data anyway, so skip warnings
msgs.removeWarningsAndBelow();
}
return msgs;
}
void CVoiceSetupForm::enabledToggled(bool enabled)
{
Q_UNUSED(enabled);
this->setReadOnly(!enabled);
}
void CVoiceSetupForm::visibleEnableInfo(bool visible)
{
ui->cb_Override->setVisible(visible);
ui->lbl_VoiceSetup->setVisible(visible);
ui->pb_SetDefaults->setVisible(visible);
}
void CVoiceSetupForm::resetToDefaultValues()
{
CVoiceSetup s;
this->setValue(s);
}
} // ns
} // ns

View File

@@ -0,0 +1,78 @@
/* Copyright (C) 2018
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_VOICESETUPFORM_H
#define BLACKGUI_COMPONENTS_VOICESETUPFORM_H
#include "blackmisc/audio/voicesetup.h"
#include "blackmisc/statusmessagelist.h"
#include "form.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CVoiceSetupForm; }
namespace BlackGui
{
namespace Editors
{
//! Voice form
class CVoiceSetupForm : public CForm
{
Q_OBJECT
public:
//! Ctor
explicit CVoiceSetupForm(QWidget *parent = nullptr);
//! Dtor
virtual ~CVoiceSetupForm() override;
//! Voice setup from GUI
BlackMisc::Audio::CVoiceSetup getValue() const;
//! Voice setup when disabled
const BlackMisc::Audio::CVoiceSetup &getDisabledValue() const;
//! Set to GUI
void setValue(const BlackMisc::Audio::CVoiceSetup &setup);
//! Enabled?
bool isVoiceSetupEnabled() const;
//! Set enabled / disabled
void setVoiceSetupEnabled(bool enabled);
//! Show the enable info
void showEnableInfo(bool visible);
//! Set default values
void resetToDefaultValues();
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
//! @}
private:
//! Enable / disable
void enabledToggled(bool enabled);
//! Show / hide visible "enable" info
void visibleEnableInfo(bool visible);
QScopedPointer<Ui::CVoiceSetupForm> ui;
bool m_visibleEnableInfo = true;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CVoiceSetupForm</class>
<widget class="QFrame" name="CVoiceSetupForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>217</width>
<height>45</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gl_VoiceSetup">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>4</number>
</property>
<item row="2" column="0">
<widget class="QLabel" name="lbl_VatsimUdpPort">
<property name="text">
<string>VATSIM UDP Port:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_VoiceSetup">
<property name="text">
<string>Voice setup:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="le_VatsimUdpPort"/>
</item>
<item row="0" column="1">
<widget class="QWidget" name="wi_Override" native="true">
<layout class="QHBoxLayout" name="hl_Override">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="cb_Override">
<property name="text">
<string>override</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QPushButton" name="pb_SetDefaults">
<property name="text">
<string>set defaults</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>