mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
Ref T573, small XPDR mode selector/display
This commit is contained in:
committed by
Mat Sutcliffe
parent
53d5ed96af
commit
6adfc6b93f
80
src/blackgui/components/transpondermodecomponent.cpp
Normal file
80
src/blackgui/components/transpondermodecomponent.cpp
Normal file
@@ -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 <QTimer>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
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<CTransponderModeComponent> 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
|
||||||
55
src/blackgui/components/transpondermodecomponent.h
Normal file
55
src/blackgui/components/transpondermodecomponent.h
Normal file
@@ -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 <QFrame>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
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::CTransponderModeComponent> 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
|
||||||
46
src/blackgui/components/transpondermodecomponent.ui
Normal file
46
src/blackgui/components/transpondermodecomponent.ui
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CTransponderModeComponent</class>
|
||||||
|
<widget class="QFrame" name="CTransponderModeComponent">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>25</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>25</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Transponder mode</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="hl_TransponderModeComponent">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="tb_TransponderMode">
|
||||||
|
<property name="text">
|
||||||
|
<string>S</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user