mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
Added LED row to display transponder mode
* made LEDs clickable * component for LED rows / transponder mode which will later be reused elsewhere
This commit is contained in:
committed by
Roland Winklmeier
parent
09ecb419dd
commit
671bb294ae
@@ -471,7 +471,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="1">
|
||||
<widget class="BlackGui::Components::CCockpitTransponderModeLedsComponent" name="comp_TransponderLeds">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QFrame" name="fr_ComPanelTransponder">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@@ -618,17 +628,17 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::CTransponderModeSelector</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>blackgui/transpondermodeselector.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::CLedWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>blackgui/led.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::CTransponderModeSelector</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>blackgui/transpondermodeselector.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::CTransponderCodeSpinBox</class>
|
||||
<extends>QSpinBox</extends>
|
||||
@@ -640,6 +650,12 @@
|
||||
<header>blackgui/selcalcodeselector.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CCockpitTransponderModeLedsComponent</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/cockpittranspondermodeledscomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
|
||||
144
src/blackgui/components/cockpittranspondermodeledscomponent.cpp
Normal file
144
src/blackgui/components/cockpittranspondermodeledscomponent.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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 "cockpittranspondermodeledscomponent.h"
|
||||
#include "blackcore/context_ownaircraft.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackCore;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CCockpitTransponderModeLedsComponent::CCockpitTransponderModeLedsComponent(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
m_ledStandby(new CLedWidget(false, CLedWidget::Blue, CLedWidget::Black, CLedWidget::Rounded, "standby", "", LedWidth, this)),
|
||||
m_ledModes(new CLedWidget(false, CLedWidget::Green, CLedWidget::Black, CLedWidget::Rounded, "mode C", "", LedWidth, this)),
|
||||
m_ledIdent(new CLedWidget(false, CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Rounded, "ident", "", LedWidth, this))
|
||||
{
|
||||
this->init(true);
|
||||
}
|
||||
|
||||
void CCockpitTransponderModeLedsComponent::runtimeHasBeenSet()
|
||||
{
|
||||
Q_ASSERT(this->getIContextOwnAircraft());
|
||||
connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitTransponderModeLedsComponent::ps_onAircraftCockpitChanged);
|
||||
this->setMode(getOwnTransponder().getTransponderMode());
|
||||
}
|
||||
|
||||
void CCockpitTransponderModeLedsComponent::ps_onAircraftCockpitChanged(const CAircraft &aircraft, const QString &originator)
|
||||
{
|
||||
if (ledsOriginator() == originator) { return; }
|
||||
this->setMode(aircraft.getTransponderMode());
|
||||
}
|
||||
|
||||
void CCockpitTransponderModeLedsComponent::ps_onLedClicked()
|
||||
{
|
||||
QWidget *w = qobject_cast<QWidget *>(QObject::sender());
|
||||
if (!w) { return; }
|
||||
if (!this->getIContextOwnAircraft()) { return; }
|
||||
CTransponder::TransponderMode mode;
|
||||
if (this->m_ledStandby.data() == w)
|
||||
{
|
||||
mode = CTransponder::StateStandby;
|
||||
}
|
||||
else if (this->m_ledIdent.data() == w)
|
||||
{
|
||||
mode = CTransponder::StateIdent;
|
||||
}
|
||||
else if (this->m_ledModes.data() == w)
|
||||
{
|
||||
mode = CTransponder::ModeC;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
CAircraft ownAircraft = this->getOwnAircraft();
|
||||
if (ownAircraft.getTransponderMode() == mode) { return; }
|
||||
|
||||
this->setMode(mode);
|
||||
CTransponder xpdr = ownAircraft.getTransponder();
|
||||
xpdr.setTransponderMode(mode);
|
||||
this->getIContextOwnAircraft()->updateOwnCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), xpdr, ledsOriginator());
|
||||
}
|
||||
|
||||
void CCockpitTransponderModeLedsComponent::init(bool horizontal)
|
||||
{
|
||||
QBoxLayout *ledLayout = nullptr;
|
||||
if (horizontal) { ledLayout = new QHBoxLayout(this); }
|
||||
else { ledLayout = new QVBoxLayout(this); }
|
||||
|
||||
ledLayout->setMargin(0);
|
||||
ledLayout->addWidget(m_ledStandby.data());
|
||||
ledLayout->addWidget(m_ledModes.data());
|
||||
ledLayout->addWidget(m_ledIdent.data());
|
||||
connect(this->m_ledIdent.data(), &CLedWidget::clicked, this, &CCockpitTransponderModeLedsComponent::ps_onLedClicked);
|
||||
connect(this->m_ledModes.data(), &CLedWidget::clicked, this, &CCockpitTransponderModeLedsComponent::ps_onLedClicked);
|
||||
connect(this->m_ledStandby.data(), &CLedWidget::clicked, this, &CCockpitTransponderModeLedsComponent::ps_onLedClicked);
|
||||
this->setLayout(ledLayout);
|
||||
|
||||
// if context is already available set mode
|
||||
if (this->getIContextOwnAircraft()) { this->setMode(getOwnTransponder().getTransponderMode()); }
|
||||
}
|
||||
|
||||
void CCockpitTransponderModeLedsComponent::setMode(BlackMisc::Aviation::CTransponder::TransponderMode mode)
|
||||
{
|
||||
m_ledStandby->setOn(false);
|
||||
m_ledModes->setOn(false);
|
||||
m_ledIdent->setOn(false);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case CTransponder::ModeA:
|
||||
case CTransponder::ModeC:
|
||||
case CTransponder::ModeS:
|
||||
case CTransponder::ModeMil1:
|
||||
case CTransponder::ModeMil2:
|
||||
case CTransponder::ModeMil3:
|
||||
case CTransponder::ModeMil4:
|
||||
case CTransponder::ModeMil5:
|
||||
m_ledModes->setOn(true);
|
||||
break;
|
||||
case CTransponder::StateIdent:
|
||||
m_ledModes->setOn(true);
|
||||
m_ledIdent->setOn(true);
|
||||
break;
|
||||
default:
|
||||
case CTransponder::StateStandby:
|
||||
m_ledStandby->setOn(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CTransponder CCockpitTransponderModeLedsComponent::getOwnTransponder() const
|
||||
{
|
||||
Q_ASSERT(getIContextOwnAircraft());
|
||||
return getIContextOwnAircraft()->getOwnAircraft().getTransponder();
|
||||
}
|
||||
|
||||
CAircraft CCockpitTransponderModeLedsComponent::getOwnAircraft() const
|
||||
{
|
||||
Q_ASSERT(getIContextOwnAircraft());
|
||||
return getIContextOwnAircraft()->getOwnAircraft();
|
||||
}
|
||||
|
||||
const QString &CCockpitTransponderModeLedsComponent::ledsOriginator()
|
||||
{
|
||||
// string is generated once, the timestamp allows to use multiple
|
||||
// components (as long as they are not generated at the same ms)
|
||||
static const QString o = QString("XPDRLEDSCOMCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||
return o;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -0,0 +1,73 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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 BLACKMISC_COCKPITTRANSPONDERMODELEDSCOMPONENT_H
|
||||
#define BLACKMISC_COCKPITTRANSPONDERMODELEDSCOMPONENT_H
|
||||
|
||||
#include "enableforruntime.h"
|
||||
#include "../led.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/aviotransponder.h"
|
||||
#include <QFrame>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
|
||||
//! LEDs representing transponder mode state
|
||||
class CCockpitTransponderModeLedsComponent : public QFrame, public CEnableForRuntime
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CCockpitTransponderModeLedsComponent(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
//! \copydoc CEnableForRuntime::runtimeHasBeenSet
|
||||
virtual void runtimeHasBeenSet() override;
|
||||
|
||||
private slots:
|
||||
//! \copydoc IContextOwnAircraft::changedAircraftCockpit
|
||||
void ps_onAircraftCockpitChanged(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
|
||||
|
||||
//! LED clicked
|
||||
void ps_onLedClicked();
|
||||
|
||||
private:
|
||||
const int LedWidth = 14; //!< LED width
|
||||
|
||||
//! Init either in horizontal or vertical layout
|
||||
void init(bool horizontal);
|
||||
|
||||
//! Set the mode
|
||||
void setMode(BlackMisc::Aviation::CTransponder::TransponderMode mode);
|
||||
|
||||
//! Own Transponder
|
||||
BlackMisc::Aviation::CTransponder getOwnTransponder() const;
|
||||
|
||||
//! Own Aircraft
|
||||
BlackMisc::Aviation::CAircraft getOwnAircraft() const;
|
||||
|
||||
//! Identifies sender of cockpit updates
|
||||
static const QString &ledsOriginator();
|
||||
|
||||
QScopedPointer<BlackGui::CLedWidget> m_ledStandby;
|
||||
QScopedPointer<BlackGui::CLedWidget> m_ledIdent;
|
||||
QScopedPointer<BlackGui::CLedWidget> m_ledModes;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
@@ -26,9 +26,9 @@ namespace BlackGui
|
||||
this->setLed();
|
||||
}
|
||||
|
||||
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, QWidget *parent) :
|
||||
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, int targetWidth, QWidget *parent) :
|
||||
m_value(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
||||
m_shape(shape), m_tooltipOn(onName), m_tooltipOff(offName),
|
||||
m_shape(shape), m_widthTarget(targetWidth), m_tooltipOn(onName), m_tooltipOff(offName),
|
||||
m_renderer(new QSvgRenderer(parent))
|
||||
{
|
||||
this->setLed();
|
||||
@@ -62,7 +62,6 @@ namespace BlackGui
|
||||
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOff));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,10 +91,7 @@ namespace BlackGui
|
||||
this->m_whRatio = s.width() / s.height();
|
||||
|
||||
// size
|
||||
if (this->m_widthTarget < 0)
|
||||
{
|
||||
this->m_widthTarget = widths().at(static_cast<int>(m_shape));
|
||||
}
|
||||
if (this->m_widthTarget < 0) { this->m_widthTarget = widths().at(static_cast<int>(m_shape)); }
|
||||
double h = this->m_widthTarget / this->m_whRatio;
|
||||
this->m_heightCalculated = qRound(h);
|
||||
|
||||
@@ -243,6 +239,19 @@ namespace BlackGui
|
||||
m_renderer->render(&painter);
|
||||
}
|
||||
|
||||
void CLedWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
emit clicked();
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList &CLedWidget::shapes()
|
||||
{
|
||||
static const QStringList shapes( {":/qled/icons/qled/circle_" , ":/qled/icons/qled/square_" , ":/qled/icons/qled/triang_" , ":/qled/icons/qled/round_"});
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackGui
|
||||
CLedWidget(QWidget *parent = nullptr);
|
||||
|
||||
//! Constructor
|
||||
CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName = "on", const QString &offName = "off", QWidget *parent = nullptr);
|
||||
CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName = "on", const QString &offName = "off", int targetWidth = -1, QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CLedWidget();
|
||||
@@ -87,7 +87,7 @@ namespace BlackGui
|
||||
void setShape(LedShape);
|
||||
|
||||
//! Target width
|
||||
void setTargetWidth(int width) { this->m_widthTarget = width; }
|
||||
void setTargetWidth(int width) { this->m_widthTarget = width; this->setLed(); }
|
||||
|
||||
//! Tool tip
|
||||
QString getOnToolTip() const { return m_tooltipOn; }
|
||||
@@ -119,6 +119,10 @@ namespace BlackGui
|
||||
//! Render as pixmap, so it can be used with TableViews
|
||||
QPixmap asPixmap() const;
|
||||
|
||||
signals:
|
||||
//! LED clicked
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
State m_value = Off; //!< current value
|
||||
LedColor m_colorOn = Yellow; //!< On color
|
||||
@@ -138,6 +142,9 @@ namespace BlackGui
|
||||
//! Paint event
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
//! Mouse pressed
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
//! Set / init LED
|
||||
void setLed(LedColor ledColor = NoColor);
|
||||
|
||||
@@ -156,10 +163,6 @@ namespace BlackGui
|
||||
//! Color string
|
||||
static const QString &colorString(LedColor color); //!<Color string
|
||||
|
||||
private:
|
||||
//! Fix widget after widths calculated
|
||||
void firstTimeReInit();
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user