diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index fbfcc196d..24abc8ab7 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -9,6 +9,10 @@ #include "mainkeypadareacomponent.h" #include "ui_mainkeypadareacomponent.h" +#include "blackcore/context_audio.h" + +using namespace BlackMisc::Aviation; +using namespace BlackCore; namespace BlackGui { @@ -33,18 +37,63 @@ namespace BlackGui connect(this->ui->pb_MainTextMessages, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainUsers, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainWeather, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + + // non info areas + connect(this->ui->pb_Connect, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + connect(this->ui->pb_CockpitIdent, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + connect(this->ui->pb_Opacity050, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + connect(this->ui->pb_Opacity100, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + connect(this->ui->pb_SoundMaxVolume, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + connect(this->ui->pb_SoundMute, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); + + // command line + this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered); } CMainKeypadAreaComponent::~CMainKeypadAreaComponent() { } + void CMainKeypadAreaComponent::runtimeHasBeenSet() + { + Q_ASSERT(this->getIContextOwnAircraft()); + Q_ASSERT(this->getIContextNetwork()); + connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged); + connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged); + } + void CMainKeypadAreaComponent::ps_buttonPressed() { const QObject *sender = QObject::sender(); CMainInfoAreaComponent::InfoArea ia = buttonToMainInfoArea(sender); if (ia != CMainInfoAreaComponent::InfoAreaNone) { - emit selectMainInfoAreaDockWidget(ia); + emit selectedMainInfoAreaDockWidget(ia); + return; + } + else if (sender == this->ui->pb_CockpitIdent && this->getIContextOwnAircraft()) + { + emit identPressed(); + } + else if (sender == this->ui->pb_Opacity050) + { + emit changedOpacity(50); + } + else if (sender == this->ui->pb_Opacity100) + { + emit changedOpacity(100); + } + else if (sender == this->ui->pb_SoundMaxVolume && this->getIContextAudio()) + { + this->getIContextAudio()->setVolumes(100, 100); + } + else if (sender == this->ui->pb_SoundMute && this->getIContextAudio()) + { + bool mute = this->getIContextAudio()->isMuted(); + this->getIContextAudio()->setMute(!mute); + } + else if (sender == this->ui->pb_Connect) + { + emit connectPressed(); } } @@ -53,6 +102,47 @@ namespace BlackGui } + void CMainKeypadAreaComponent::ps_connectionStatusChanged(uint from, uint to, const QString &message) + { + INetwork::ConnectionStatus statusFrom = static_cast(from); + INetwork::ConnectionStatus statusTo = static_cast(to); + + Q_UNUSED(statusFrom); + Q_UNUSED(message); + + // Connected button + if (statusTo == INetwork::Connected) + { + this->ui->pb_Connect->setText("Disconnect"); + this->ui->pb_Connect->setStyleSheet("background-color: green"); + } + else + { + this->ui->pb_Connect->setText("Connect"); + this->ui->pb_Connect->setStyleSheet("background-color: "); + } + } + + void CMainKeypadAreaComponent::ps_commandEntered() + { + QString c = this->ui->le_CommandLineInput->text().trimmed(); + if (c.isEmpty()) return; + emit this->commandEntered(c); + } + + void CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged(const CAircraft &aircraft, const QString &originator) + { + Q_UNUSED(originator); + if (aircraft.getTransponder().getTransponderMode() == CTransponder::StateIdent) + { + this->ui->pb_CockpitIdent->setStyleSheet("background-color: yellow"); + } + else + { + this->ui->pb_CockpitIdent->setStyleSheet(""); + } + } + CMainInfoAreaComponent::InfoArea CMainKeypadAreaComponent::buttonToMainInfoArea(const QObject *button) const { if (button == ui->pb_MainAircrafts) return CMainInfoAreaComponent::InfoAreaAircrafts; @@ -69,5 +159,11 @@ namespace BlackGui return CMainInfoAreaComponent::InfoAreaNone; } + Aviation::CAircraft CMainKeypadAreaComponent::getOwnAircraft() const + { + if (!this->getIContextOwnAircraft()) { return CAircraft(); } + return this->getIContextOwnAircraft()->getOwnAircraft(); + } + } // namespace } // namespace diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index d0bd125b6..ab4567aab 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -12,9 +12,12 @@ #ifndef BLACKGUI_MAINKEYPADAREACOMPONENT_H #define BLACKGUI_MAINKEYPADAREACOMPONENT_H +#include "maininfoareacomponent.h" +#include "enableforruntime.h" +#include "blackmisc/avaircraft.h" + #include #include -#include "maininfoareacomponent.h" namespace Ui { class CMainKeypadAreaComponent; } namespace BlackGui @@ -24,7 +27,9 @@ namespace BlackGui //! Main keypad area as used with main info area //! \sa CMainInfoAreaComponent - class CMainKeypadAreaComponent : public QFrame + class CMainKeypadAreaComponent : + public QFrame, + public CEnableForRuntime { Q_OBJECT @@ -38,7 +43,23 @@ namespace BlackGui signals: //! Button to select main info area has been pressed //! \sa CMainInfoAreaComponent - void selectMainInfoAreaDockWidget(CMainInfoAreaComponent::InfoArea infoArea); + void selectedMainInfoAreaDockWidget(CMainInfoAreaComponent::InfoArea infoArea); + + //! Change opacity 0..30 + void changedOpacity(int opacity); + + //! Command was entered + void commandEntered(const QString &commandLine); + + //! Connect was pressed + void connectPressed(); + + //! Ident pressed + void identPressed(); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; private slots: //! Button was clicked @@ -47,10 +68,22 @@ namespace BlackGui //! Button was double clicked void ps_buttonDoubleClicked(); + //! \copydoc BlackCore::IContextNetwork::connectionStatusChanged + void ps_connectionStatusChanged(uint from, uint to, const QString &message); + + //! Command line entered + void ps_commandEntered(); + + //! \copydoc BlackCore::IContextOwnAircraft::changedAircraftCockpit + void ps_ownAircraftCockpitChanged(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator); + private: - // if button is info area, identify it + //! If button is info area, identify it CMainInfoAreaComponent::InfoArea buttonToMainInfoArea(const QObject *button) const; + //! Own aircraft + BlackMisc::Aviation::CAircraft getOwnAircraft() const; + QScopedPointer ui; }; diff --git a/src/blackgui/components/mainkeypadareacomponent.ui b/src/blackgui/components/mainkeypadareacomponent.ui index 8449ff3ba..f6b4f33c9 100644 --- a/src/blackgui/components/mainkeypadareacomponent.ui +++ b/src/blackgui/components/mainkeypadareacomponent.ui @@ -6,12 +6,12 @@ 0 0 - 407 - 144 + 389 + 122 - Frame + Main keypad area QFrame::StyledPanel @@ -51,7 +51,7 @@ 2 - 6 + 0 2 @@ -80,7 +80,7 @@ 16777215 - 22 + 16777215 @@ -89,7 +89,7 @@ - + 0 @@ -105,7 +105,7 @@ 16777215 - 22 + 16777215 @@ -114,7 +114,7 @@ - + 0 @@ -124,7 +124,7 @@ 16777215 - 22 + 16777215 @@ -137,7 +137,7 @@ 16777215 - 22 + 16777215 @@ -149,7 +149,7 @@ - + 0 @@ -165,7 +165,7 @@ 16777215 - 22 + 16777215 @@ -184,7 +184,7 @@ 16777215 - 22 + 16777215 @@ -203,7 +203,7 @@ 16777215 - 22 + 16777215 @@ -213,6 +213,12 @@ + + + 16777215 + 16777215 + + Users @@ -229,7 +235,7 @@ 16777215 - 22 + 16777215 @@ -239,6 +245,12 @@ + + + 16777215 + 16777215 + + Ident @@ -255,7 +267,7 @@ 16777215 - 22 + 16777215 @@ -265,6 +277,12 @@ + + + 16777215 + 16777215 + + Simulator @@ -281,7 +299,7 @@ 16777215 - 22 + 16777215 @@ -300,7 +318,7 @@ 16777215 - 22 + 16777215 @@ -319,7 +337,7 @@ 16777215 - 22 + 16777215 @@ -338,7 +356,7 @@ 16777215 - 22 + 16777215 @@ -360,7 +378,7 @@ 16777215 - 22 + 16777215