refs #335, highlight selected info areas in keypad

This commit is contained in:
Klaus Basan
2014-11-05 16:39:34 +01:00
committed by Roland Winklmeier
parent 9a920367b2
commit 3fd1f3c8c4
3 changed files with 144 additions and 28 deletions

View File

@@ -26,25 +26,27 @@ namespace BlackGui
ui->setupUi(this); ui->setupUi(this);
// Info areas // Info areas
connect(this->ui->pb_MainAircrafts, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); // pressed collides, as this toggles button again
connect(this->ui->pb_MainAtc, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); // using toggle collides, as checking/unchecking toggles again -> infinite loop
connect(this->ui->pb_MainCockpit, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainAircrafts, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainFlightplan, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainAtc, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainLog, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainCockpit, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainMappings, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainFlightplan, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainSettings, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainLog, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainSimulator, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainMappings, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainTextMessages, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainSettings, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainUsers, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainSimulator, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainWeather, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_MainTextMessages, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainUsers, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_MainWeather, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
// non info areas // non info areas
connect(this->ui->pb_Connect, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_Connect, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_CockpitIdent, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_CockpitIdent, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_Opacity050, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_Opacity050, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_Opacity100, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_Opacity100, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_SoundMaxVolume, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_SoundMaxVolume, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
connect(this->ui->pb_SoundMute, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonPressed); connect(this->ui->pb_SoundMute, &QPushButton::pressed, this, &CMainKeypadAreaComponent::ps_buttonSelected);
// command line // command line
this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered); this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered);
@@ -53,47 +55,77 @@ namespace BlackGui
CMainKeypadAreaComponent::~CMainKeypadAreaComponent() CMainKeypadAreaComponent::~CMainKeypadAreaComponent()
{ } { }
void CMainKeypadAreaComponent::onMainInfoAreaChanged(int currentTabIndex, QList<int> dockedIndexes, QList<int> floatingIndexes)
{
this->unsetInfoAreaButtons();
if (currentTabIndex >= 0)
{
QPushButton *pb = this->mainInfoAreaToButton(static_cast<CMainInfoAreaComponent::InfoArea>(currentTabIndex));
if (pb)
{
Q_ASSERT(pb->isCheckable());
pb->setChecked(true);
}
}
foreach(int floatingIndex, floatingIndexes)
{
QPushButton *pb = this->mainInfoAreaToButton(static_cast<CMainInfoAreaComponent::InfoArea>(floatingIndex));
if (pb) {pb->setChecked(true); }
}
Q_UNUSED(dockedIndexes);
}
void CMainKeypadAreaComponent::runtimeHasBeenSet() void CMainKeypadAreaComponent::runtimeHasBeenSet()
{ {
Q_ASSERT(this->getIContextOwnAircraft()); Q_ASSERT(this->getIContextOwnAircraft());
Q_ASSERT(this->getIContextNetwork()); Q_ASSERT(this->getIContextNetwork());
Q_ASSERT(this->getIContextAudio());
connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged); connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged);
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextNetwork(), &IContextNetwork::parseCommandLine);
connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged); connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged);
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextOwnAircraft(), &IContextOwnAircraft::parseCommandLine); connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextOwnAircraft(), &IContextOwnAircraft::parseCommandLine);
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextNetwork(), &IContextNetwork::parseCommandLine);
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextAudio(), &IContextAudio::parseCommandLine);
} }
void CMainKeypadAreaComponent::ps_buttonPressed() void CMainKeypadAreaComponent::ps_buttonSelected()
{ {
const QObject *sender = QObject::sender(); QPushButton *senderButton = static_cast<QPushButton *>(QObject::sender());
CMainInfoAreaComponent::InfoArea ia = buttonToMainInfoArea(sender); Q_ASSERT(senderButton);
if (!senderButton) { return; }
CMainInfoAreaComponent::InfoArea ia = buttonToMainInfoArea(senderButton);
if (ia != CMainInfoAreaComponent::InfoAreaNone) if (ia != CMainInfoAreaComponent::InfoAreaNone)
{ {
Q_ASSERT(senderButton->isCheckable());
emit selectedMainInfoAreaDockWidget(ia); emit selectedMainInfoAreaDockWidget(ia);
senderButton->setChecked(true); // re-check if got unchecked, we use checked buttons like normal buttons
return; return;
} }
else if (sender == this->ui->pb_CockpitIdent && this->getIContextOwnAircraft()) else if (senderButton == this->ui->pb_CockpitIdent && this->getIContextOwnAircraft())
{ {
emit identPressed(); emit identPressed();
} }
else if (sender == this->ui->pb_Opacity050) else if (senderButton == this->ui->pb_Opacity050)
{ {
emit changedOpacity(50); emit changedOpacity(50);
} }
else if (sender == this->ui->pb_Opacity100) else if (senderButton == this->ui->pb_Opacity100)
{ {
emit changedOpacity(100); emit changedOpacity(100);
} }
else if (sender == this->ui->pb_SoundMaxVolume && this->getIContextAudio()) else if (senderButton == this->ui->pb_SoundMaxVolume && this->getIContextAudio())
{ {
this->getIContextAudio()->setVolumes(100, 100); this->getIContextAudio()->setVolumes(100, 100);
} }
else if (sender == this->ui->pb_SoundMute && this->getIContextAudio()) else if (senderButton == this->ui->pb_SoundMute && this->getIContextAudio())
{ {
bool mute = this->getIContextAudio()->isMuted(); bool mute = this->getIContextAudio()->isMuted();
this->getIContextAudio()->setMute(!mute); this->getIContextAudio()->setMute(!mute);
} }
else if (sender == this->ui->pb_Connect) else if (senderButton == this->ui->pb_Connect)
{ {
emit connectPressed(); emit connectPressed();
} }
@@ -157,11 +189,47 @@ namespace BlackGui
return CMainInfoAreaComponent::InfoAreaNone; return CMainInfoAreaComponent::InfoAreaNone;
} }
QPushButton *CMainKeypadAreaComponent::mainInfoAreaToButton(CMainInfoAreaComponent::InfoArea area) const
{
switch (area)
{
case CMainInfoAreaComponent::InfoAreaAircrafts: return ui->pb_MainAircrafts;
case CMainInfoAreaComponent::InfoAreaAtc: return ui->pb_MainAtc;
case CMainInfoAreaComponent::InfoAreaCockpit: return ui->pb_MainCockpit;
case CMainInfoAreaComponent::InfoAreaFlightPlan: return ui->pb_MainFlightplan;
case CMainInfoAreaComponent::InfoAreaLog: return ui->pb_MainLog;
case CMainInfoAreaComponent::InfoAreaMappings: return ui->pb_MainMappings;
case CMainInfoAreaComponent::InfoAreaSettings: return ui->pb_MainSettings;
case CMainInfoAreaComponent::InfoAreaSimulator: return ui->pb_MainSimulator;
case CMainInfoAreaComponent::InfoAreaTextMessages: return ui->pb_MainTextMessages;
case CMainInfoAreaComponent::InfoAreaUsers: return ui->pb_MainUsers;
case CMainInfoAreaComponent::InfoAreaWeather: return ui->pb_MainWeather;
default: break;
}
return nullptr;
}
Aviation::CAircraft CMainKeypadAreaComponent::getOwnAircraft() const Aviation::CAircraft CMainKeypadAreaComponent::getOwnAircraft() const
{ {
if (!this->getIContextOwnAircraft()) { return CAircraft(); } if (!this->getIContextOwnAircraft()) { return CAircraft(); }
return this->getIContextOwnAircraft()->getOwnAircraft(); return this->getIContextOwnAircraft()->getOwnAircraft();
} }
void CMainKeypadAreaComponent::unsetInfoAreaButtons()
{
ui->pb_MainAircrafts->setChecked(false);
ui->pb_MainAtc->setChecked(false);
ui->pb_MainCockpit->setChecked(false);
ui->pb_MainFlightplan->setChecked(false);
ui->pb_MainLog->setChecked(false);
ui->pb_MainMappings->setChecked(false);
ui->pb_MainSettings->setChecked(false);
ui->pb_MainSimulator->setChecked(false);
ui->pb_MainTextMessages->setChecked(false);
ui->pb_MainUsers->setChecked(false);
ui->pb_MainWeather->setChecked(false);
}
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -17,7 +17,9 @@
#include "blackmisc/avaircraft.h" #include "blackmisc/avaircraft.h"
#include <QFrame> #include <QFrame>
#include <QPushButton>
#include <QScopedPointer> #include <QScopedPointer>
#include <QList>
namespace Ui { class CMainKeypadAreaComponent; } namespace Ui { class CMainKeypadAreaComponent; }
namespace BlackGui namespace BlackGui
@@ -57,13 +59,17 @@ namespace BlackGui
//! Ident pressed //! Ident pressed
void identPressed(); void identPressed();
public slots:
//! Main info area changed
void onMainInfoAreaChanged(int currentTabIndex, QList<int> dockedIndexes, QList<int> floatingIndexes);
protected: protected:
//! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet
virtual void runtimeHasBeenSet() override; virtual void runtimeHasBeenSet() override;
private slots: private slots:
//! Button was clicked //! Button was clicked
void ps_buttonPressed(); void ps_buttonSelected();
//! \copydoc BlackCore::IContextNetwork::connectionStatusChanged //! \copydoc BlackCore::IContextNetwork::connectionStatusChanged
void ps_connectionStatusChanged(uint from, uint to, const QString &message); void ps_connectionStatusChanged(uint from, uint to, const QString &message);
@@ -78,9 +84,15 @@ namespace BlackGui
//! If button is info area, identify it //! If button is info area, identify it
CMainInfoAreaComponent::InfoArea buttonToMainInfoArea(const QObject *button) const; CMainInfoAreaComponent::InfoArea buttonToMainInfoArea(const QObject *button) const;
//! Main info area to corresponding button
QPushButton *mainInfoAreaToButton(CMainInfoAreaComponent::InfoArea area) const;
//! Own aircraft //! Own aircraft
BlackMisc::Aviation::CAircraft getOwnAircraft() const; BlackMisc::Aviation::CAircraft getOwnAircraft() const;
//! Info area buttons
void unsetInfoAreaButtons();
QScopedPointer<Ui::CMainKeypadAreaComponent> ui; QScopedPointer<Ui::CMainKeypadAreaComponent> ui;
}; };

View File

@@ -190,6 +190,9 @@
<property name="text"> <property name="text">
<string>Aircrafts</string> <string>Aircrafts</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
@@ -209,6 +212,12 @@
<property name="text"> <property name="text">
<string>ATC</string> <string>ATC</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
@@ -222,6 +231,9 @@
<property name="text"> <property name="text">
<string>Users</string> <string>Users</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item row="1" column="3">
@@ -241,6 +253,9 @@
<property name="text"> <property name="text">
<string>Cockpit</string> <string>Cockpit</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item row="2" column="3">
@@ -273,6 +288,9 @@
<property name="text"> <property name="text">
<string>Text/Chat</string> <string>Text/Chat</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
@@ -286,6 +304,9 @@
<property name="text"> <property name="text">
<string>Simulator</string> <string>Simulator</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
@@ -305,6 +326,9 @@
<property name="text"> <property name="text">
<string>Weather</string> <string>Weather</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
@@ -324,6 +348,9 @@
<property name="text"> <property name="text">
<string>Flightplan</string> <string>Flightplan</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
@@ -343,6 +370,9 @@
<property name="text"> <property name="text">
<string>Mappings</string> <string>Mappings</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
@@ -365,6 +395,9 @@
<property name="text"> <property name="text">
<string>Settings</string> <string>Settings</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="2">
@@ -384,6 +417,9 @@
<property name="text"> <property name="text">
<string>Log</string> <string>Log</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>