From 6adfc6b93f79ef967f665b64ba47d0da6d02163e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 19 Mar 2019 05:34:03 +0100 Subject: [PATCH] Ref T573, small XPDR mode selector/display --- .../components/transpondermodecomponent.cpp | 80 +++++++++++++++++++ .../components/transpondermodecomponent.h | 55 +++++++++++++ .../components/transpondermodecomponent.ui | 46 +++++++++++ 3 files changed, 181 insertions(+) create mode 100644 src/blackgui/components/transpondermodecomponent.cpp create mode 100644 src/blackgui/components/transpondermodecomponent.h create mode 100644 src/blackgui/components/transpondermodecomponent.ui diff --git a/src/blackgui/components/transpondermodecomponent.cpp b/src/blackgui/components/transpondermodecomponent.cpp new file mode 100644 index 000000000..c22fd75a7 --- /dev/null +++ b/src/blackgui/components/transpondermodecomponent.cpp @@ -0,0 +1,80 @@ +/* Copyright (C) 2019 + * 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. 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 "transpondermodecomponent.h" +#include "ui_transpondermodecomponent.h" +#include "guiapplication.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackmisc/aviation/transponder.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; +using namespace BlackCore::Context; + +namespace BlackGui +{ + namespace Components + { + CTransponderModeComponent::CTransponderModeComponent(QWidget *parent) : + QFrame(parent), CIdentifiable(this), + ui(new Ui::CTransponderModeComponent) + { + ui->setupUi(this); + + connect(ui->tb_TransponderMode, &QToolButton::released, this, &CTransponderModeComponent::onClicked, Qt::QueuedConnection); + connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTransponderModeComponent::onChangedAircraftCockpit, Qt::QueuedConnection); + + this->onChangedAircraftCockpit(sGui->getIContextOwnAircraft()->getOwnAircraft(), CIdentifier::null()); + this->init(); + + QPointer myself(this); + QTimer::singleShot(10 * 1000, this, [ = ] + { + if (!myself) { return; } + myself->onChangedAircraftCockpit(sGui->getIContextOwnAircraft()->getOwnAircraft(), CIdentifier::null()); + }); + } + + CTransponderModeComponent::~CTransponderModeComponent() + { } + + void CTransponderModeComponent::init() + { + if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui->supportsContexts() || !sGui->getIContextOwnAircraft()) { this->setVisible(false); return; } + + this->setVisible(true); + ui->tb_TransponderMode->setText(m_transponder.getModeAsShortString()); + + this->setProperty("xpdrmode", m_transponder.getTransponderMode()); + this->setProperty("xpdrmodeshort", m_transponder.getModeAsShortString()); + + this->setToolTip(m_transponder.toQString()); + } + + void CTransponderModeComponent::onClicked() + { + if (!sGui || sGui->isShuttingDown()) { return; } + CTransponder xpdr = m_transponder; + xpdr.toggleTransponderMode(); + sGui->getIContextOwnAircraft()->setTransponderMode(xpdr.getTransponderMode()); + } + + void CTransponderModeComponent::onChangedAircraftCockpit(const CSimulatedAircraft &aircraft, const CIdentifier &originator) + { + if (this->identifier() == originator) { return; } + if (m_transponder == aircraft.getTransponder()) { return; } + m_transponder = aircraft.getTransponder(); + this->init(); + } + } // ns +} // ns diff --git a/src/blackgui/components/transpondermodecomponent.h b/src/blackgui/components/transpondermodecomponent.h new file mode 100644 index 000000000..60281f216 --- /dev/null +++ b/src/blackgui/components/transpondermodecomponent.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2019 + * 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. 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_TRANSPONDERMODECOMPONENT_H +#define BLACKGUI_COMPONENTS_TRANSPONDERMODECOMPONENT_H + +#include "blackmisc/aviation/transponder.h" +#include "blackmisc/identifiable.h" +#include +#include + +namespace Ui { class CTransponderModeComponent; } +namespace BlackMisc { class CIdentifier; namespace Simulation { class CSimulatedAircraft; }} +namespace BlackGui +{ + namespace Components + { + /** + * Small component to display XPDR mode + */ + class CTransponderModeComponent : public QFrame, BlackMisc::CIdentifiable + { + Q_OBJECT + + public: + //! Ctor + explicit CTransponderModeComponent(QWidget *parent = nullptr); + + //! Dtor + virtual ~CTransponderModeComponent() override; + + private: + QScopedPointer ui; + BlackMisc::Aviation::CTransponder m_transponder; + + //! Init + void init(); + + //! Clicked + void onClicked(); + + //! Changed cockpit data + void onChangedAircraftCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/transpondermodecomponent.ui b/src/blackgui/components/transpondermodecomponent.ui new file mode 100644 index 000000000..7e1c47a22 --- /dev/null +++ b/src/blackgui/components/transpondermodecomponent.ui @@ -0,0 +1,46 @@ + + + CTransponderModeComponent + + + + 0 + 0 + 25 + 25 + + + + + 25 + 25 + + + + Transponder mode + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + S + + + + + + + +