diff --git a/src/blackgui/editors/voicesetupform.cpp b/src/blackgui/editors/voicesetupform.cpp new file mode 100644 index 000000000..65ac2a825 --- /dev/null +++ b/src/blackgui/editors/voicesetupform.cpp @@ -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 + +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 diff --git a/src/blackgui/editors/voicesetupform.h b/src/blackgui/editors/voicesetupform.h new file mode 100644 index 000000000..6e94566c7 --- /dev/null +++ b/src/blackgui/editors/voicesetupform.h @@ -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 +#include + +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; + bool m_visibleEnableInfo = true; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/editors/voicesetupform.ui b/src/blackgui/editors/voicesetupform.ui new file mode 100644 index 000000000..e800c9bd7 --- /dev/null +++ b/src/blackgui/editors/voicesetupform.ui @@ -0,0 +1,85 @@ + + + CVoiceSetupForm + + + + 0 + 0 + 217 + 45 + + + + Frame + + + + 0 + + + 0 + + + 0 + + + 0 + + + 4 + + + + + VATSIM UDP Port: + + + + + + + Voice setup: + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + override + + + + + + + set defaults + + + + + + + + + + +