diff --git a/src/blackgui/aircraftcombinedtypeselector.cpp b/src/blackgui/aircraftcombinedtypeselector.cpp new file mode 100644 index 000000000..5492279f3 --- /dev/null +++ b/src/blackgui/aircraftcombinedtypeselector.cpp @@ -0,0 +1,102 @@ +/* Copyright (C) 2015 + * 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 "aircraftcombinedtypeselector.h" +#include "ui_aircraftcombinedtypeselector.h" +#include "blackgui/guiutility.h" + +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + + CAircraftCombinedTypeSelector::CAircraftCombinedTypeSelector(QWidget *parent) : + QFrame(parent), + ui(new Ui::CAircraftCombinedTypeSelector) + { + ui->setupUi(this); + this->connect(ui->le_CombinedType, &QLineEdit::editingFinished, this, &CAircraftCombinedTypeSelector::ps_CombinedTypeEntered); + this->connect(ui->le_CombinedType, &QLineEdit::returnPressed, this, &CAircraftCombinedTypeSelector::ps_CombinedTypeEntered); + + this->connect(ui->cb_EngineCount, &QComboBox::currentTextChanged, this, &CAircraftCombinedTypeSelector::ps_ChangedComboBox); + this->connect(ui->cb_EngineType, &QComboBox::currentTextChanged, this, &CAircraftCombinedTypeSelector::ps_ChangedComboBox); + this->connect(ui->cb_Type, &QComboBox::currentTextChanged, this, &CAircraftCombinedTypeSelector::ps_ChangedComboBox); + } + + CAircraftCombinedTypeSelector::~CAircraftCombinedTypeSelector() + { } + + void CAircraftCombinedTypeSelector::setCombinedType(const QString &combinedCode) + { + QString engineCount, engineType, aircraftType; + QString cc(combinedCode.trimmed().toUpper().left(3)); + if (cc.length() > 0) { aircraftType = cc.left(1); } + if (cc.length() > 1) { engineCount = cc.mid(1, 1); } + if (cc.length() > 2) { engineType = cc.mid(2, 1); } + + CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_EngineCount, engineCount, "unspecified"); + CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_EngineType, engineType, "unspecified"); + CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_Type, aircraftType, "unspecified"); + + this->ui->le_CombinedType->setText(cc); + } + + void CAircraftCombinedTypeSelector::setCombinedType(const BlackMisc::Aviation::CAircraftIcaoCode &icao) + { + this->setCombinedType(icao.getCombinedType()); + } + + void CAircraftCombinedTypeSelector::clear() + { + this->setCombinedType(""); + this->ui->le_CombinedType->clear(); + } + + void CAircraftCombinedTypeSelector::setReadOnly(bool readOnly) + { + ui->le_CombinedType->setReadOnly(readOnly); + ui->cb_EngineCount->setEnabled(!readOnly); + ui->cb_EngineType->setEnabled(!readOnly); + ui->cb_Type->setEnabled(!readOnly); + } + + QString CAircraftCombinedTypeSelector::getCombinedType() const + { + QString ct(ui->le_CombinedType->text().trimmed().toUpper()); + if (CAircraftIcaoCode::isValidCombinedType(ct)) { return ct; } + + QString ct2(getCombinedTypeFromComboBoxes()); + return ct2; + } + + void CAircraftCombinedTypeSelector::ps_CombinedTypeEntered() + { + QString cc(ui->le_CombinedType->text().trimmed().toUpper()); + this->setCombinedType(cc); + } + + void CAircraftCombinedTypeSelector::ps_ChangedComboBox(const QString &text) + { + Q_UNUSED(text); + QString ct(getCombinedTypeFromComboBoxes()); + ui->le_CombinedType->setText(ct); + } + + QString CAircraftCombinedTypeSelector::getCombinedTypeFromComboBoxes() const + { + // try to get from combox boxes instead + QString ec = ui->cb_EngineCount->currentText().left(1); + QString t = ui->cb_Type->currentText().left(1); + QString et = ui->cb_EngineType->currentText().left(1); + + QString ct2(QString(t + ec + et).toUpper()); + return ct2.replace('U', '-'); + } + +} // ns diff --git a/src/blackgui/aircraftcombinedtypeselector.h b/src/blackgui/aircraftcombinedtypeselector.h new file mode 100644 index 000000000..01ebc01be --- /dev/null +++ b/src/blackgui/aircraftcombinedtypeselector.h @@ -0,0 +1,69 @@ +/* Copyright (C) 2015 + * 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_AIRCRAFTCOMBINEDTYPESELECTOR_H +#define BLACKGUI_AIRCRAFTCOMBINEDTYPESELECTOR_H + +#include "blackmisc/aviation/aircrafticaocode.h" +#include +#include + +namespace Ui { class CAircraftCombinedTypeSelector; } + +namespace BlackGui +{ + + /*! + * Select by comined type ("L2J", "H1T", ...) + */ + class CAircraftCombinedTypeSelector : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CAircraftCombinedTypeSelector(QWidget *parent = nullptr); + + //! Destructor + ~CAircraftCombinedTypeSelector(); + + //! Set comined code, e.g. L1P + void setCombinedType(const QString &combinedCode); + + //! Combined code from aircraft ICAO + void setCombinedType(const BlackMisc::Aviation::CAircraftIcaoCode &icao); + + //! Clear + void clear(); + + //! Read only + void setReadOnly(bool readOnly); + + //! Get the combined type, e.g. "L2P" + QString getCombinedType() const; + + private slots: + //! Code has been entered + void ps_CombinedTypeEntered(); + + //! Changed combobox + void ps_ChangedComboBox(const QString &text); + + private: + //! Combined type from comboboxes + QString getCombinedTypeFromComboBoxes() const; + + QScopedPointer ui; + }; + +} // ns + +#endif // guard diff --git a/src/blackgui/aircraftcombinedtypeselector.ui b/src/blackgui/aircraftcombinedtypeselector.ui new file mode 100644 index 000000000..6102afb5d --- /dev/null +++ b/src/blackgui/aircraftcombinedtypeselector.ui @@ -0,0 +1,187 @@ + + + CAircraftCombinedTypeSelector + + + + 0 + 0 + 341 + 22 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 4 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 40 + 16777215 + + + + Enter combined type, e.g. L2J, S1P + + + 3 + + + L1P + + + + + + + Type + + + + Helicopter + + + + + Glider + + + + + Seaplane + + + + + Landplane + + + + + Tilt wing + + + + + Unspecified + + + + + + + + Engines count + + + + 0 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + + + + Engine + + + + Electric + + + + + Jet + + + + + Piston + + + + + Turboprop + + + + + Unspecified + + + + + + + + +