diff --git a/src/blackgui/editors/situationform.cpp b/src/blackgui/editors/situationform.cpp new file mode 100644 index 000000000..805b75506 --- /dev/null +++ b/src/blackgui/editors/situationform.cpp @@ -0,0 +1,165 @@ +/* Copyright (C) 2017 + * 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 "situationform.h" +#include "ui_situationform.h" +#include "blackmisc/pq/angle.h" +#include "blackmisc/stringutils.h" +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackGui +{ + namespace Editors + { + CSituationForm::CSituationForm(QWidget *parent) : + CForm(parent), + ui(new Ui::CSituationForm) + { + ui->setupUi(this); + + ui->le_Bank->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Bank)); + ui->le_Pitch->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Pitch)); + + connect(ui->hs_Bank, &QSlider::valueChanged, this, &CSituationForm::bankSliderChanged); + connect(ui->hs_Pitch, &QSlider::valueChanged, this, &CSituationForm::pitchSliderChanged); + connect(ui->le_Bank, &QLineEdit::editingFinished, this, &CSituationForm::bankEntered); + connect(ui->le_Pitch, &QLineEdit::editingFinished, this, &CSituationForm::pitchEntered); + connect(ui->tb_ResetBank, &QToolButton::clicked, this, &CSituationForm::resetBank); + connect(ui->tb_ResetPitch, &QToolButton::clicked, this, &CSituationForm::resetPitch); + connect(ui->pb_Set, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation); + connect(ui->comp_Coordinate, &CCoordinateForm::changeCoordinate, this, &CSituationForm::changeAircraftSituation); + } + + CSituationForm::~CSituationForm() + { } + + void CSituationForm::setSituation(const BlackMisc::Aviation::CAircraftSituation &situation) + { + ui->comp_Coordinate->setCoordinate(situation); + } + + CAircraftSituation CSituationForm::getSituation() const + { + CAircraftSituation s(ui->comp_Coordinate->getCoordinate()); + s.setBank(this->getBankAngle()); + s.setPitch(this->getPitchAngle()); + return s; + } + + CAngle CSituationForm::getBankAngle() const + { + return CAngle(getBankAngleDegrees(), CAngleUnit::deg()); + } + + double CSituationForm::getBankAngleDegrees() const + { + const QString v(ui->le_Bank->text().replace(',', '.')); + bool ok; + double vd = v.toDouble(&ok); + if (!ok) { vd = 0.0; } + return CAngle::normalizeDegrees180(vd, RoundDigits); + } + + CAngle CSituationForm::getPitchAngle() const + { + return CAngle(getPitchAngleDegrees(), CAngleUnit::deg()); + } + + double CSituationForm::getPitchAngleDegrees() const + { + const QString v(ui->le_Pitch->text().replace(',', '.')); + bool ok; + double vd = v.toDouble(&ok); + if (!ok) { vd = 0.0; } + return CAngle::normalizeDegrees180(vd, RoundDigits); + } + + void CSituationForm::setReadOnly(bool readonly) + { + ui->comp_Coordinate->setReadOnly(readonly); + } + + void CSituationForm::setSelectOnly() + { + this->setReadOnly(true); + } + + CStatusMessageList CSituationForm::validate(bool nested) const + { + CStatusMessageList ml; + if (nested) + { + ml.push_back(ui->comp_Coordinate->validate(nested)); + } + return ml; + } + + void CSituationForm::showSetButton(bool visible) + { + ui->pb_Set->setVisible(visible); + } + + int clampAngle(int in) + { + return qBound(-179, in, 180); + } + + void CSituationForm::bankSliderChanged(int value) + { + const int angle = clampAngle(qRound(this->getBankAngleDegrees())); + if (value == angle) { return; } // avoid roundtrips + ui->le_Bank->setText(QString::number(value)); + } + + void CSituationForm::pitchSliderChanged(int value) + { + const int angle = clampAngle(qRound(this->getPitchAngleDegrees())); + if (value == angle) { return; } // avoid roundtrips + ui->le_Pitch->setText(QString::number(value)); + } + + void CSituationForm::bankEntered() + { + const double ad = this->getBankAngleDegrees(); + QString n = QString::number(ad, 'g', 3 + RoundDigits); + if (ui->le_Pitch->validator()) { dotToLocaleDecimalPoint(n); } + ui->le_Bank->setText(n); + const int angle = clampAngle(qRound(ad)); + if (angle == ui->hs_Bank->value()) { return; } // avoid roundtrips + ui->hs_Bank->setValue(angle); + } + + void CSituationForm::resetBank() + { + ui->le_Bank->setText("0"); + ui->hs_Bank->setValue(0); + } + + void CSituationForm::pitchEntered() + { + const double ad = this->getPitchAngleDegrees(); + QString n = QString::number(ad, 'g', 3 + RoundDigits); + if (ui->le_Pitch->validator()) { dotToLocaleDecimalPoint(n); } + ui->le_Pitch->setText(n); + const int angle = clampAngle(qRound(ad)); + if (angle == ui->hs_Pitch->value()) { return; } // avoid roundtrips + ui->hs_Pitch->setValue(angle); + } + + void CSituationForm::resetPitch() + { + ui->le_Pitch->setText("0"); + ui->hs_Pitch->setValue(0); + } + } // ns +} // ns diff --git a/src/blackgui/editors/situationform.h b/src/blackgui/editors/situationform.h new file mode 100644 index 000000000..e53d9882b --- /dev/null +++ b/src/blackgui/editors/situationform.h @@ -0,0 +1,88 @@ +/* Copyright (C) 2017 + * 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_EDITORS_SITUATIONSFORM_H +#define BLACKGUI_EDITORS_SITUATIONSFORM_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/editors/form.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/statusmessagelist.h" +#include + +class QWidget; + +namespace Ui { class CSituationForm; } +namespace BlackGui +{ + namespace Editors + { + /** + * Selector / entry + */ + class BLACKGUI_EXPORT CSituationForm : public CForm + { + Q_OBJECT + + public: + //! Constructor + explicit CSituationForm(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSituationForm(); + + //! Set the situation + void setSituation(const BlackMisc::Aviation::CAircraftSituation &situation); + + //! Get the situation + BlackMisc::Aviation::CAircraftSituation getSituation() const; + + //! \name Form class implementations + //! @{ + virtual void setReadOnly(bool readonly) override; + virtual void setSelectOnly() override; + virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override; + //! @} + + //! Set button visible + void showSetButton(bool visible); + + signals: + //! Aircraft situation to be changed + void changeAircraftSituation(); + + private: + static constexpr int RoundDigits = 6; + + //! Get bank angle + BlackMisc::PhysicalQuantities::CAngle getBankAngle() const; + + //! Get bank angle + double getBankAngleDegrees() const; + + //! Get pitch angle + BlackMisc::PhysicalQuantities::CAngle getPitchAngle() const; + + //! Get pitch angle + double getPitchAngleDegrees() const; + + void bankSliderChanged(int value); + void pitchSliderChanged(int value); + void bankEntered(); + void resetBank(); + void pitchEntered(); + void resetPitch(); + + QScopedPointer ui; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/editors/situationform.ui b/src/blackgui/editors/situationform.ui new file mode 100644 index 000000000..f1813bb45 --- /dev/null +++ b/src/blackgui/editors/situationform.ui @@ -0,0 +1,200 @@ + + + CSituationForm + + + + 0 + 0 + 386 + 324 + + + + Frame + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Situation + + + + + + QFrame::Raised + + + + + + Bank (-179° to 180°): + + + + + + + -179 + + + 180 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 25 + + + + + + + 0 + + + deg. + + + + + + + 0 + + + deg. + + + + + + + Pitch (-179° to 180°): + + + + + + + -179 + + + 180 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 25 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + :/diagona/icons/diagona/icons/cross-white.png:/diagona/icons/diagona/icons/cross-white.png + + + + + + + ... + + + + :/diagona/icons/diagona/icons/cross-white.png:/diagona/icons/diagona/icons/cross-white.png + + + + + + + set + + + + + + + + + + + + + Coordinate + + + + + + + 0 + 100 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + BlackGui::Editors::CCoordinateForm + QFrame +
blackgui/editors/coordinateform.h
+ 1 +
+
+ + + + +
diff --git a/src/plugins/simulator/swift/simulatorswiftmonitordialog.cpp b/src/plugins/simulator/swift/simulatorswiftmonitordialog.cpp index 624e452ff..c1711444c 100644 --- a/src/plugins/simulator/swift/simulatorswiftmonitordialog.cpp +++ b/src/plugins/simulator/swift/simulatorswiftmonitordialog.cpp @@ -39,7 +39,7 @@ namespace BlackSimPlugin connect(ui->cb_Simulating, &QCheckBox::released, this, &CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged); this->setSimulatorUiValues(); - ui->comp_Position->setCoordinate(m_simulator->getOwnAircraftSituation()); + ui->comp_Situation->setSituation(m_simulator->getOwnAircraftSituation()); } CSimulatorSwiftMonitorDialog::~CSimulatorSwiftMonitorDialog() diff --git a/src/plugins/simulator/swift/simulatorswiftmonitordialog.ui b/src/plugins/simulator/swift/simulatorswiftmonitordialog.ui index 43c810360..d041e03da 100644 --- a/src/plugins/simulator/swift/simulatorswiftmonitordialog.ui +++ b/src/plugins/simulator/swift/simulatorswiftmonitordialog.ui @@ -17,7 +17,7 @@ - 1 + 0 @@ -25,7 +25,7 @@ - + 0 @@ -174,9 +174,9 @@ 1 - BlackGui::Components::CCoordinateSelector + BlackGui::Editors::CSituationForm QFrame -
blackgui/components/coordinateselector.h
+
blackgui/editors/situationform.h
1