From b65ace7e488d2ae567c3029913d8e36d6882fd0a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 4 Nov 2018 00:40:46 +0100 Subject: [PATCH] Ref T424, altitude dialog for flight plans --- src/blackgui/components/altitudedialog.cpp | 224 ++++++++++++++ src/blackgui/components/altitudedialog.h | 95 ++++++ src/blackgui/components/altitudedialog.ui | 325 +++++++++++++++++++++ 3 files changed, 644 insertions(+) create mode 100644 src/blackgui/components/altitudedialog.cpp create mode 100644 src/blackgui/components/altitudedialog.h create mode 100644 src/blackgui/components/altitudedialog.ui diff --git a/src/blackgui/components/altitudedialog.cpp b/src/blackgui/components/altitudedialog.cpp new file mode 100644 index 000000000..9e2f70349 --- /dev/null +++ b/src/blackgui/components/altitudedialog.cpp @@ -0,0 +1,224 @@ +/* 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 "altitudedialog.h" +#include "ui_altitudedialog.h" + +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/aviation/altitude.h" + +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + namespace Components + { + CAltitudeDialog::CAltitudeDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CAltitudeDialog) + { + ui->setupUi(this); + this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); + + /** override default button, not working + QPushButton *okBtn = ui->bb_AltitudeDialog->button(QDialogButtonBox::Ok); + okBtn->setAutoDefault(false); + okBtn->setDefault(false); + QPushButton *caBtn = ui->bb_AltitudeDialog->button(QDialogButtonBox::Cancel); + caBtn->setAutoDefault(false); + caBtn->setDefault(false); + **/ + ui->le_FLft->setFocus(); + + // levels + ui->le_FLft->setValidator(new QIntValidator(10, 999, ui->le_FLft)); + ui->le_AltitudeAFt->setValidator(new QIntValidator(10, 999, ui->le_AltitudeAFt)); + ui->le_AltitudeMm->setValidator(new QIntValidator(10, 9999, ui->le_AltitudeMm)); + ui->le_Sm->setValidator(new QIntValidator(10, 9999, ui->le_Sm)); + + // plain altitudes in ft/m + ui->le_AltitudeConvertedFt->setValidator(new QIntValidator(100, 99999, ui->le_AltitudeConvertedFt)); + ui->le_AltitudeFt->setValidator(new QIntValidator(100, 99999, ui->le_AltitudeFt)); + ui->le_AltitudeM->setValidator(new QIntValidator(100, 99999, ui->le_AltitudeM)); + + connect(ui->le_AltitudeAFt, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_AltitudeConvertedFt, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_AltitudeFt, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_AltitudeM, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_AltitudeMm, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_FLft, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + connect(ui->le_Sm, &QLineEdit::editingFinished, this, &CAltitudeDialog::onEditFinished); + + connect(ui->rb_VFR, &QRadioButton::toggled, this, &CAltitudeDialog::onVFRSelected); + connect(ui->rb_StringOnly, &QRadioButton::toggled, this, &CAltitudeDialog::onStringOnlySelected); + connect(ui->cb_SimplifiedVATSIMFormat, &QCheckBox::toggled, this, &CAltitudeDialog::onSimplifiedVATSIMFormatChanged); + + connect(ui->le_AltitudeAFt, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_AltitudeConvertedFt, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_AltitudeFt, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_AltitudeM, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_AltitudeMm, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_FLft, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + connect(ui->le_Sm, &QLineEdit::textEdited, this, &CAltitudeDialog::onTextEdit); + } + + CAltitudeDialog::~CAltitudeDialog() + { } + + CAltitudeDialog::Mode CAltitudeDialog::getMode() const + { + if (ui->rb_AltitudeAFt->isChecked()) return AltitudeInHundredsOfFeet; + if (ui->rb_VFR->isChecked()) return VFR; + if (ui->rb_AltitudeConvertedFt->isChecked()) return AltitudeInMetersConvertedToFeet; + if (ui->rb_AltitudeFt->isChecked()) return AltitudeInFeet; + if (ui->rb_AltitudeM->isChecked()) return AltitudeInMeters; + if (ui->rb_AltitudeMm->isChecked()) return AltitudeInTensOfMeters; + if (ui->rb_FLft->isChecked()) return FlightFlevelInFeet; + if (ui->rb_Sm->isChecked()) return MetricLevelInTensOfMeters; + if (ui->rb_StringOnly->isChecked()) return StringOnly; + return Unknown; + } + + void CAltitudeDialog::setVatsim(bool vatsim) + { + ui->cb_SimplifiedVATSIMFormat->setChecked(vatsim); + } + + bool CAltitudeDialog::isStringOnly() const + { + return ui->rb_StringOnly->isChecked(); + } + + void CAltitudeDialog::onEditFinished() + { + const Mode mode = this->getMode(); + switch (mode) + { + case VFR: + m_altitudeStr = QStringLiteral("VFR"); + break; + case FlightFlevelInFeet: + m_altitudeStr = QStringLiteral("FL") % ui->le_FLft->text(); + break; + case MetricLevelInTensOfMeters: + m_altitudeStr = QStringLiteral("S") % ui->le_Sm->text(); + break; + case AltitudeInHundredsOfFeet: + m_altitudeStr = QStringLiteral("A") % ui->le_AltitudeAFt->text(); + break; + case AltitudeInTensOfMeters: + m_altitudeStr = QStringLiteral("M") % ui->le_AltitudeMm->text(); + break; + case AltitudeInFeet: + m_altitudeStr = ui->le_AltitudeFt->text() % QStringLiteral("ft"); + break; + case AltitudeInMeters: + m_altitudeStr = ui->le_AltitudeM->text() % QStringLiteral("m"); + break; + case AltitudeInMetersConvertedToFeet: + m_altitudeStr = ui->le_AltitudeConvertedFt->text() % QStringLiteral("m"); + break; + case StringOnly: + return; + case Unknown: + default: + return; + } + + CStatusMessageList msgs; + m_altitude.parseFromFpAltitudeString(m_altitudeStr, &msgs); + if (msgs.hasErrorMessages()) + { + ui->le_String->setText(msgs.toSingleMessage().getMessage()); + m_altitudeStr.clear(); + } + else + { + if (mode == AltitudeInMetersConvertedToFeet) + { + m_altitude = m_altitude.roundedToNearest100ft(); + m_altitudeStr = m_altitude.valueRoundedWithUnit(0); + } + + if (ui->cb_SimplifiedVATSIMFormat->isChecked()) + { + m_altitudeStr = m_altitude.asFpVatsimAltitudeString(); + } + + ui->le_String->setText(m_altitudeStr); + } + + this->updateStyleSheet(); + } + + void CAltitudeDialog::onVFRSelected(bool selected) + { + if (!selected) { return; } + this->onEditFinished(); + } + + void CAltitudeDialog::onStringOnlySelected(bool selected) + { + ui->le_String->setReadOnly(!selected); + if (!selected) { return; } + + this->onEditFinished(); + this->updateStyleSheet(); + } + + void CAltitudeDialog::onTextEdit(const QString &text) + { + Q_UNUSED(text); + const QObject *sender = QObject::sender(); + + if (sender == ui->le_VFR) { ui->rb_VFR->setChecked(true); return; } + if (sender == ui->le_AltitudeAFt) { ui->rb_AltitudeAFt->setChecked(true); return; } + if (sender == ui->le_AltitudeConvertedFt) { ui->rb_AltitudeConvertedFt->setChecked(true); return; } + if (sender == ui->le_AltitudeFt) { ui->rb_AltitudeFt->setChecked(true); return; } + if (sender == ui->le_AltitudeM) { ui->rb_AltitudeM->setChecked(true); return; } + if (sender == ui->le_AltitudeMm) { ui->rb_AltitudeMm->setChecked(true); return; } + if (sender == ui->le_FLft) { ui->rb_FLft->setChecked(true); return; } + if (sender == ui->le_Sm) { ui->rb_Sm->setChecked(true); return; } + } + + void CAltitudeDialog::onSimplifiedVATSIMFormatChanged(bool checked) + { + ui->rb_AltitudeAFt->setEnabled(!checked); + ui->le_AltitudeAFt->setEnabled(!checked); + ui->rb_AltitudeM->setEnabled(!checked); + ui->le_AltitudeM->setEnabled(!checked); + ui->rb_AltitudeMm->setEnabled(!checked); + ui->le_AltitudeMm->setEnabled(!checked); + ui->rb_Sm->setEnabled(!checked); + ui->le_Sm->setEnabled(!checked); + ui->rb_VFR->setEnabled(!checked); + + if (checked) + { + m_altitudeStr = m_altitude.asFpVatsimAltitudeString(); + ui->le_String->setText(m_altitudeStr); + ui->rb_StringOnly->setChecked(true); + } + + this->updateStyleSheet(); + } + + void CAltitudeDialog::updateStyleSheet() + { + const QString ss = this->styleSheet(); + this->setStyleSheet(""); + this->setStyleSheet(ss); + } + } // ns +} // ns diff --git a/src/blackgui/components/altitudedialog.h b/src/blackgui/components/altitudedialog.h new file mode 100644 index 000000000..3b18e0f4a --- /dev/null +++ b/src/blackgui/components/altitudedialog.h @@ -0,0 +1,95 @@ +/* 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_ALTITUDEDIALOG_H +#define BLACKGUI_COMPONENTS_ALTITUDEDIALOG_H + +#include "blackmisc/aviation/altitude.h" + +#include +#include + +namespace Ui { class CAltitudeDialog; } +namespace BlackGui +{ + namespace Components + { + /** + * Dialog to get a correct altitude + */ + class CAltitudeDialog : public QDialog + { + Q_OBJECT + + public: + //! Which mode used to enter + enum Mode + { + Unknown, + StringOnly, + VFR, + FlightFlevelInFeet, + MetricLevelInTensOfMeters, + AltitudeInHundredsOfFeet, + AltitudeInTensOfMeters, + AltitudeInFeet, + AltitudeInMeters, + AltitudeInMetersConvertedToFeet + }; + + //! Constructor + explicit CAltitudeDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CAltitudeDialog(); + + //! Get mode + Mode getMode() const; + + //! Set VATSIM flag + void setVatsim(bool vatsim); + + //! Manual string mode + bool isStringOnly() const; + + //! Altitude string + const BlackMisc::Aviation::CAltitude &getAltitude() const { return m_altitude; } + + //! Altitude string + const QString &getAltitudeString() const { return m_altitudeStr; } + + private: + QScopedPointer ui; + BlackMisc::Aviation::CAltitude m_altitude; + QString m_altitudeStr; + + //! Edit finished + void onEditFinished(); + + //! VFR selected + void onVFRSelected(bool selected); + + //! String only selected + void onStringOnlySelected(bool selected); + + //! On text edit + void onTextEdit(const QString &text); + + //! Simplified format changed + void onSimplifiedVATSIMFormatChanged(bool checked); + + //! Update style sheet + void updateStyleSheet(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/altitudedialog.ui b/src/blackgui/components/altitudedialog.ui new file mode 100644 index 000000000..81903e380 --- /dev/null +++ b/src/blackgui/components/altitudedialog.ui @@ -0,0 +1,325 @@ + + + CAltitudeDialog + + + + 0 + 0 + 342 + 494 + + + + Altitude dialog + + + true + + + + + + ICAO formats + + + + + + meters/10 + + + + + + + feet/100 + + + + + + + M0610 altitude in tens of meters + + + bg_RadioButtons + + + + + + + level + + + + + + + A055 altitude in hundreds of feet + + + bg_RadioButtons + + + + + + + VFR + + + true + + + + + + + S0150 metric level in tens of meters + + + bg_RadioButtons + + + + + + + FL085 flight level in hecto feets + + + bg_RadioButtons + + + + + + + FL + + + + + + + VFR + + + bg_RadioButtons + + + + + + + + + + Directly as feet or meters + + + + + + Altitude in meters + + + bg_RadioButtons + + + + + + + Altitude in feet + + + bg_RadioButtons + + + + + + + feet + + + + + + + meters + + + + + + + + + + Meters converted to feet + + + + + + meters + + + + + + + Alt. in meters, will be converted to feet + + + bg_RadioButtons + + + + + + + <html><head/><body><p><img src="qrc:/misc/icons/misc/cn.png"/><img src="qrc:/misc/icons/misc/ru.png"/></p></body></html> + + + + + + + + + + Format + + + + + + not supporting "S", "A", "VFR", altitude in meters + + + Simplified VATSIM format, some formats are unavailable + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + Result used in flight plan + + + + + + true + + + value goes here + + + + + + + Override + + + bg_RadioButtons + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + rb_FLft + le_FLft + rb_Sm + le_Sm + rb_AltitudeAFt + le_AltitudeAFt + rb_AltitudeMm + le_AltitudeMm + rb_VFR + le_VFR + rb_AltitudeFt + le_AltitudeFt + rb_AltitudeM + le_AltitudeM + rb_AltitudeConvertedFt + le_AltitudeConvertedFt + cb_SimplifiedVATSIMFormat + rb_StringOnly + le_String + + + + + bb_AltitudeDialog + accepted() + CAltitudeDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_AltitudeDialog + rejected() + CAltitudeDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + + +