refs #681, GUI FSD setup

* form base class adjusted
* GUI form UI
This commit is contained in:
Klaus Basan
2016-06-26 19:47:32 +02:00
parent 0939b1f08f
commit 2d00ff42fe
7 changed files with 360 additions and 23 deletions

View File

@@ -0,0 +1,113 @@
/* Copyright (C) 2016
* 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 "fsdsetupform.h"
#include "ui_fsdsetupform.h"
#include "blackmisc/stringutils.h"
#include "blackgui/guiutility.h"
#include <QCompleter>
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Editors
{
CFsdSetupForm::CFsdSetupForm(QWidget *parent) :
CForm(parent),
ui(new Ui::CFsdSetupForm)
{
ui->setupUi(this);
this->showEnableInfo(false);
ui->cb_Enabled->setChecked(true);
ui->le_TextCodec->setCompleter(new QCompleter(textCodecNames(true, true), this));
connect(ui->cb_Enabled, &QCheckBox::toggled, this, &CFsdSetupForm::ps_enabledToggled);
}
CFsdSetupForm::~CFsdSetupForm()
{ }
CFsdSetup CFsdSetupForm::getValue() const
{
if (!this->isEnabled()) { return this->getDisabledValue(); }
CFsdSetup s(ui->le_TextCodec->text().trimmed().toLower());
s.setSendReceiveDetails(
ui->cb_AircraftPartsSend->isChecked(), ui->cb_AircraftPartsReceive->isChecked(),
ui->cb_FastPositionSend->isChecked(), ui->cb_FastPositionReceive->isChecked()
);
return s;
}
const CFsdSetup &CFsdSetupForm::getDisabledValue() const
{
static const CFsdSetup fsd;
return fsd;
}
void CFsdSetupForm::setValue(const BlackMisc::Network::CFsdSetup &setup)
{
ui->le_TextCodec->setText(setup.getTextCodec());
const CFsdSetup::SendReceiveDetails d = setup.getSendReceiveDetails();
ui->cb_AircraftPartsReceive->setChecked(d & CFsdSetup::ReceiveAircraftParts);
ui->cb_AircraftPartsSend->setChecked(d & CFsdSetup::SendAircraftParts);
ui->cb_FastPositionReceive->setChecked(d & CFsdSetup::ReceiveInterimPositions);
ui->cb_FastPositionSend->setChecked(d & CFsdSetup::SendIterimPositions);
}
bool CFsdSetupForm::isFsdSetuoEnabled() const
{
return ui->cb_Enabled->isChecked();
}
void CFsdSetupForm::setFsdSetupEnabled(bool enabled)
{
ui->cb_Enabled->setChecked(enabled);
}
void CFsdSetupForm::showEnableInfo(bool visible)
{
ui->cb_Enabled->setVisible(visible);
ui->lbl_Enabled->setVisible(visible);
}
void CFsdSetupForm::setReadOnly(bool readonly)
{
ui->le_TextCodec->setReadOnly(readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_AircraftPartsReceive, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_AircraftPartsSend, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_FastPositionReceive, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_FastPositionSend, readonly);
}
CStatusMessageList CFsdSetupForm::validate(bool nested) const
{
Q_UNUSED(nested);
const CFsdSetup val(getValue());
CStatusMessageList msgs(val.validate());
if (this->isReadOnly())
{
// in readonly I cannot change the data anyway, so skip warnings
msgs.removeWarningsAndBelow();
}
return msgs;
}
void CFsdSetupForm::ps_enabledToggled(bool enabled)
{
Q_UNUSED(enabled);
this->setReadOnly(!enabled);
if (!enabled)
{
this->setValue(CFsdSetup());
}
}
} // ns
} // ns