Fix overriding cockpit values if a field is input focused.

Cockpit updates are a 2 way process, from context to GUI and vice versa.
This fix checks if a widget is focused, and if so, updating is ignored.
This commit is contained in:
Klaus Basan
2014-02-08 01:11:03 +01:00
parent 3eff2f5fb1
commit f56b3b878f
5 changed files with 74 additions and 33 deletions

View File

@@ -39,6 +39,8 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) :
m_timerStatusBar(nullptr), m_timerAudioTests(nullptr),
// context menus
m_contextMenuAudio(nullptr), m_contextMenuStatusMessageList(nullptr),
// cockpit
m_inputFocusedWidget(nullptr),
// status bar
m_statusBarIcon(nullptr), m_statusBarLabel(nullptr)
{

View File

@@ -157,6 +157,7 @@ private:
// cockpit
QString m_transponderResetValue; /*!< Temp. storage of XPdr mode to reset, req. until timer allows singleShoot with Lambdas */
QWidget *m_inputFocusedWidget; /*!< currently used widget for input, mainly used with cockpit */
// status bar
QLabel *m_statusBarIcon; /*!< status bar icon */
@@ -208,10 +209,8 @@ private:
*/
bool isCockpitUpdatePending() const;
/*!
* \brief Round the COM frequency display
*/
void roundComFrequencyDisplays(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2);
//! \brief Update the COM frequency displays
void updateComFrequencyDisplays(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2);
/*!
* \brief Add new text message tab
@@ -360,14 +359,10 @@ private slots:
*/
void appendTextMessagesToGui(const BlackMisc::Network::CTextMessageList &messages, bool sending = false);
/*!
* \brief Reload settings
*/
//!\brief Reload settings
void reloadSettings();
/*!
* \brief Send cockpit updates
*/
//! \brief Send cockpit updates
void sendCockpitUpdates();
//
@@ -500,6 +495,11 @@ private slots:
//! \brief start the MIC tests (Squelch)
void startAudioTest();
//! \brief inputFocusChanged
//! \sa QApplication::focusChanged
void inputFocusChanged(QWidget *oldWidget, QWidget *newWidget);
};
#pragma pop_macro("interface")

View File

@@ -454,7 +454,7 @@ QStatusBar QLabel {
<enum>QFrame::NoFrame</enum>
</property>
<property name="currentIndex">
<number>7</number>
<number>0</number>
</property>
<widget class="QWidget" name="pg_StatusPage">
<property name="sizePolicy">
@@ -564,8 +564,8 @@ QStatusBar QLabel {
<rect>
<x>0</x>
<y>0</y>
<width>86</width>
<height>59</height>
<width>326</width>
<height>267</height>
</rect>
</property>
<attribute name="label">
@@ -607,8 +607,8 @@ QStatusBar QLabel {
<rect>
<x>0</x>
<y>0</y>
<width>90</width>
<height>55</height>
<width>326</width>
<height>267</height>
</rect>
</property>
<attribute name="label">
@@ -2842,6 +2842,7 @@ QStatusBar QLabel {
<tabstop>cb_StatusWithDBus</tabstop>
<tabstop>le_StatusNetworkContext</tabstop>
<tabstop>le_StatusVoiceContext</tabstop>
<tabstop>tv_StatusMessages</tabstop>
<tabstop>le_CommandLineInput</tabstop>
<tabstop>tw_AtcStations</tabstop>
<tabstop>tv_AtcStationsOnline</tabstop>
@@ -2852,6 +2853,7 @@ QStatusBar QLabel {
<tabstop>tv_AtcStationsBooked</tabstop>
<tabstop>pb_ReloadAtcStationsBooked</tabstop>
<tabstop>tv_AircraftsInRange</tabstop>
<tabstop>tv_AllUsers</tabstop>
<tabstop>pb_CockpitToggleCom1</tabstop>
<tabstop>ds_CockpitCom1Active</tabstop>
<tabstop>ds_CockpitCom1Standby</tabstop>
@@ -2913,6 +2915,14 @@ QStatusBar QLabel {
<tabstop>pb_MainKeypadOpacity050</tabstop>
<tabstop>pb_SoundMute</tabstop>
<tabstop>pb_SoundMaxVolume</tabstop>
<tabstop>te_StatusPageConsole</tabstop>
<tabstop>rb_SetttingsNormalLoginMode</tabstop>
<tabstop>rb_SettingsLoginStealthMode</tabstop>
<tabstop>rb_SettingsLoginObserver</tabstop>
<tabstop>pb_SettingsAudioSquelchTest</tabstop>
<tabstop>pb_SettingsAudioMicrophoneTest</tabstop>
<tabstop>pte_SettingsAudioTestActionAndResult</tabstop>
<tabstop>hs_SettingsGuiUserRefreshTime</tabstop>
</tabstops>
<resources>
<include location="../../src/blackgui/blackgui.qrc"/>

View File

@@ -81,10 +81,16 @@ void MainWindow::updateCockpitFromContext()
const CComSystem com2 = this->m_ownAircraft.getCom2System();
const CTransponder transponder = this->m_ownAircraft.getTransponder();
this->roundComFrequencyDisplays(com1, com2);
qint32 tc = transponder.getTransponderCode();
if (tc != static_cast<qint32>(this->ui->ds_CockpitTransponder->value()))
this->ui->ds_CockpitTransponder->setValue(tc);
// update the frequencies
this->updateComFrequencyDisplays(com1, com2);
if (this->m_inputFocusedWidget != this->ui->ds_CockpitTransponder)
{
// update transponder if this is not input focused
qint32 tc = transponder.getTransponderCode();
if (tc != static_cast<qint32>(this->ui->ds_CockpitTransponder->value()))
this->ui->ds_CockpitTransponder->setValue(tc);
}
QString tm = this->ui->cb_CockpitTransponderMode->currentText().trimmed().toUpper();
switch (transponder.getTransponderMode())
@@ -178,25 +184,38 @@ void MainWindow::updateCockpitFromContext()
/*
* Round the com frequency displays
*/
void MainWindow::roundComFrequencyDisplays(const CComSystem &com1, const CComSystem &com2)
void MainWindow::updateComFrequencyDisplays(const CComSystem &com1, const CComSystem &com2)
{
// do not just set! Leads to unwanted signals fired
double freq = com1.getFrequencyActive().valueRounded(3);
if (freq != this->ui->ds_CockpitCom1Active->value())
this->ui->ds_CockpitCom1Active->setValue(freq);
// only update if not focused
freq = com2.getFrequencyActive().valueRounded(3);
if (freq != this->ui->ds_CockpitCom2Active->value())
this->ui->ds_CockpitCom2Active->setValue(freq);
if (this->m_inputFocusedWidget != ui->ds_CockpitCom1Active)
{
double freq = com1.getFrequencyActive().valueRounded(3);
if (freq != this->ui->ds_CockpitCom1Active->value())
this->ui->ds_CockpitCom1Active->setValue(freq);
}
freq = com1.getFrequencyStandby().valueRounded(3);
if (freq != this->ui->ds_CockpitCom1Standby->value())
if (this->m_inputFocusedWidget != ui->ds_CockpitCom2Active)
{
double freq = com2.getFrequencyActive().valueRounded(3);
if (freq != this->ui->ds_CockpitCom2Active->value())
this->ui->ds_CockpitCom2Active->setValue(freq);
}
this->ui->ds_CockpitCom1Standby->setValue(freq);
if (this->m_inputFocusedWidget != ui->ds_CockpitCom1Standby)
{
double freq = com1.getFrequencyStandby().valueRounded(3);
if (freq != this->ui->ds_CockpitCom1Standby->value())
this->ui->ds_CockpitCom1Standby->setValue(freq);
}
freq = com2.getFrequencyStandby().valueRounded(3);
if (freq != this->ui->ds_CockpitCom2Standby->value())
this->ui->ds_CockpitCom2Standby->setValue(freq);
if (this->m_inputFocusedWidget != ui->ds_CockpitCom2Standby)
{
double freq = com2.getFrequencyStandby().valueRounded(3);
if (freq != this->ui->ds_CockpitCom2Standby->value())
this->ui->ds_CockpitCom2Standby->setValue(freq);
}
}
/*
@@ -263,7 +282,7 @@ void MainWindow::sendCockpitUpdates()
com1.setFrequencyStandbyMHz(this->ui->ds_CockpitCom1Standby->value());
com2.setFrequencyActiveMHz(this->ui->ds_CockpitCom2Active->value());
com2.setFrequencyStandbyMHz(this->ui->ds_CockpitCom2Standby->value());
this->roundComFrequencyDisplays(com1, com2);
this->updateComFrequencyDisplays(com1, com2);
//
// Send to context
@@ -358,3 +377,12 @@ QString MainWindow::getSelcalCode() const
QString selcal = this->ui->cb_CockpitSelcal1->currentText().append(this->ui->cb_CockpitSelcal2->currentText());
return selcal;
}
/*
* Current input focus
*/
void MainWindow::inputFocusChanged(QWidget *oldWidget, QWidget *newWidget)
{
Q_UNUSED(oldWidget);
this->m_inputFocusedWidget = newWidget;
}

View File

@@ -299,6 +299,7 @@ void MainWindow::initGuiSignals()
this->connect(this->ui->pb_CockpitToggleCom2, &QPushButton::clicked, this, &MainWindow::cockpitValuesChanged);
this->connect(this->ui->pb_CockpitIdent, &QPushButton::clicked, this, &MainWindow::cockpitValuesChanged);
this->connect(this->ui->pb_CockpitSelcalTest, &QPushButton::clicked, this, &MainWindow::testSelcal);
this->connect(qApp, &QApplication::focusChanged, this, &MainWindow::inputFocusChanged);
// voice
connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int)));