From 7805e2315cb6606ac4cc402ea959fe621f913aca Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 12 Aug 2018 03:02:47 +0200 Subject: [PATCH] Ref T301, keypad and infobar init themself and can be re-connect (to core) --- .../components/infobarstatuscomponent.cpp | 49 ++++++++++++++++++- .../components/infobarstatuscomponent.h | 6 +++ .../components/mainkeypadareacomponent.cpp | 37 ++++++++++++-- .../components/mainkeypadareacomponent.h | 4 +- .../components/mainkeypadareacomponent.ui | 12 ++--- 5 files changed, 96 insertions(+), 12 deletions(-) diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index 10e879ee2..0a9a9746e 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include using namespace BlackConfig; using namespace BlackCore; @@ -48,6 +50,7 @@ namespace BlackGui ui->lbl_Audio->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatusComponent::onCustomAudioContextMenuRequested); + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui"); if (sGui->getIContextSimulator()) { connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::onSimulatorStatusChanged); @@ -74,6 +77,13 @@ namespace BlackGui ui->led_Audio->setOn(!sGui->getIContextAudio()->isMuted()); connect(sGui->getIContextAudio(), &IContextAudio::changedMute, this, &CInfoBarStatusComponent::onMuteChanged); } + + QPointer myself(this); + QTimer::singleShot(5000, this, [ = ] + { + if (!myself) { return; } + this->updateValues(); + }); } CInfoBarStatusComponent::~CInfoBarStatusComponent() @@ -210,6 +220,7 @@ namespace BlackGui void CInfoBarStatusComponent::onMapperReady() { + if (sGui && sGui->isShuttingDown()) { return; } if (!sGui || !sGui->getIContextSimulator()) { ui->led_MapperReady->setOn(false); @@ -245,9 +256,45 @@ namespace BlackGui } } + void CInfoBarStatusComponent::updateValues() + { + if (!sGui || sGui->isShuttingDown()) { return; } + + IContextSimulator *simCon = sGui->getIContextSimulator(); + if (sGui->getIContextSimulator()) + { + + this->onSimulatorStatusChanged(simCon->getSimulatorStatus()); + if (simCon->getModelSetCount() > 0) + { + this->onMapperReady(); + } + } + + if (sGui->getIContextNetwork()) + { + ui->led_Network->setOn(sGui->getIContextNetwork()->isConnected()); + } + + if (sGui->getIContextApplication()) + { + ui->led_DBus->setOn(sGui->getIContextApplication()->isUsingImplementingObject()); + } + + // audio context can be empty depending on which side it is called + if (sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject()) + { + ui->led_Audio->setOn(!sGui->getIContextAudio()->isMuted()); + } + else + { + ui->led_Audio->setOn(false); + } + } + void CInfoBarStatusComponent::updateSpacing() { - if (!sGui || !sGui->mainApplicationWidget()) { return; } + if (!sGui || sGui->isShuttingDown() || !sGui->mainApplicationWidget()) { return; } const int w = sGui->mainApplicationWidget()->width(); const int s = (w >= 400) ? 6 : 2; this->setSpacing(s); diff --git a/src/blackgui/components/infobarstatuscomponent.h b/src/blackgui/components/infobarstatuscomponent.h index 061f749d4..6fb3e5e48 100644 --- a/src/blackgui/components/infobarstatuscomponent.h +++ b/src/blackgui/components/infobarstatuscomponent.h @@ -53,6 +53,9 @@ namespace BlackGui QScopedPointer ui; BlackCore::CActionBind m_actionPtt { "/Voice/Activate push-to-talk", BlackMisc::CIcons::radio16(), this, &CInfoBarStatusComponent::onPttChanged }; + //! Init the LEDs + void initLeds(); + //! Simulator connection has been changed void onSimulatorStatusChanged(int status); @@ -74,6 +77,9 @@ namespace BlackGui //! Internet accessible? void onInternetAccessibleChanged(bool access); + //! Update values + void updateValues(); + //! Update spacing based on main window size void updateSpacing(); }; diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index e5171b0b8..30374076b 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -73,6 +74,13 @@ namespace BlackGui connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ownAircraftCockpitChanged); connect(sGui->getIContextAudio(), &IContextAudio::changedMute, this, &CMainKeypadAreaComponent::muteChanged); connect(this, &CMainKeypadAreaComponent::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine); + + QPointer myself(this); + QTimer::singleShot(5000, this, [ = ] + { + if (!myself || !sGui) { return; } + this->update(); + }); } CMainKeypadAreaComponent::~CMainKeypadAreaComponent() @@ -145,7 +153,7 @@ namespace BlackGui } } - void CMainKeypadAreaComponent::connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to) + void CMainKeypadAreaComponent::connectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to) { Q_UNUSED(from); @@ -153,12 +161,14 @@ namespace BlackGui if (to == INetwork::Connected) { ui->pb_Connect->setText("Discon."); // full terms some too wide - ui->pb_Connect->setStyleSheet("background-color: green"); + ui->pb_Connect->setChecked(true); + // moved to stylesheet: ui->pb_Connect->setStyleSheet("background-color: green"); } else { ui->pb_Connect->setText("Connect"); - ui->pb_Connect->setStyleSheet("background-color: "); + ui->pb_Connect->setChecked(false); + // moved to stylesheet: ui->pb_Connect->setStyleSheet("background-color: "); } } @@ -242,7 +252,26 @@ namespace BlackGui QPushButton *pb = qobject_cast(QObject::sender()); if (!pb) { return; } pb->setEnabled(false); - QTimer::singleShot(750, [pb] { pb->setEnabled(true); }); + QPointer myself(this); + QTimer::singleShot(750, [ = ] + { + if (!sGui || sGui->isShuttingDown() || !myself) { return; } + pb->setEnabled(true); + }); + } + + void CMainKeypadAreaComponent::update() + { + if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts()) { return; } + if (sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject()) + { + this->muteChanged(sGui->getIContextAudio()->isMuted()); + } + + if (sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected()) + { + this->connectionStatusChanged(INetwork::Connected, INetwork::Connected); + } } } // namespace } // namespace diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index 9f2c734f2..9fee0dfbe 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -24,7 +24,6 @@ #include class QPushButton; -class QWidget; namespace BlackMisc { namespace Simulation { class CSimulatedAircraft; } } namespace Ui { class CMainKeypadAreaComponent; } @@ -96,6 +95,9 @@ namespace BlackGui //! Disable button for some (short) time to avoid double click void disableButtonBriefly(); + //! Update values + void update(); + QScopedPointer ui; BlackMisc::CIdentifier m_identifier { "MainKeypadAreaComponent", this }; }; diff --git a/src/blackgui/components/mainkeypadareacomponent.ui b/src/blackgui/components/mainkeypadareacomponent.ui index 5f5ed98b2..61a5f2278 100644 --- a/src/blackgui/components/mainkeypadareacomponent.ui +++ b/src/blackgui/components/mainkeypadareacomponent.ui @@ -13,12 +13,6 @@ Main keypad area - - QFrame::StyledPanel - - - QFrame::Raised - 0 @@ -204,6 +198,9 @@ Connect + + true + @@ -361,6 +358,9 @@ Mute + + true +