Ref T430, added FG simulator selector support

* FG can be disabled (normal scenarios)
* added combobox mode as well, as too many radio buttons are too wide, will gradually change to combobox in some UI scenarios
This commit is contained in:
Klaus Basan
2018-11-10 17:13:51 +01:00
parent 53a77813a5
commit 4f74a36596
3 changed files with 164 additions and 27 deletions

View File

@@ -10,8 +10,9 @@
#include "blackgui/components/simulatorselector.h" #include "blackgui/components/simulatorselector.h"
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h" #include "blackgui/guiutility.h"
#include "blackmisc/compare.h"
#include "blackcore/context/contextsimulator.h" #include "blackcore/context/contextsimulator.h"
#include "blackmisc/compare.h"
#include "blackconfig/buildconfig.h"
#include "ui_simulatorselector.h" #include "ui_simulatorselector.h"
#include <QCheckBox> #include <QCheckBox>
@@ -20,6 +21,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QPointer> #include <QPointer>
using namespace BlackConfig;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
using namespace BlackCore::Context; using namespace BlackCore::Context;
@@ -32,17 +34,24 @@ namespace BlackGui
ui(new Ui::CSimulatorSelector) ui(new Ui::CSimulatorSelector)
{ {
ui->setupUi(this); ui->setupUi(this);
this->enableFG(false && CBuildConfig::isLocalDeveloperDebugBuild());
this->setMode(CheckBoxes); this->setMode(CheckBoxes);
connect(ui->rb_FS9, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged); connect(ui->rb_FS9, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged);
connect(ui->rb_FSX, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged); connect(ui->rb_FSX, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged);
connect(ui->rb_P3D, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged); connect(ui->rb_P3D, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged);
connect(ui->rb_FG, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged);
connect(ui->rb_XPlane, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged); connect(ui->rb_XPlane, &QRadioButton::toggled, this, &CSimulatorSelector::radioButtonChanged);
connect(ui->cb_FS9, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged); connect(ui->cb_FS9, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged);
connect(ui->cb_FSX, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged); connect(ui->cb_FSX, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged);
connect(ui->cb_P3D, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged); connect(ui->cb_P3D, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged);
connect(ui->cb_FG, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged);
connect(ui->cb_XPlane, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged); connect(ui->cb_XPlane, &QRadioButton::toggled, this, &CSimulatorSelector::checkBoxChanged);
connect(ui->cb_Simulators, &QComboBox::currentTextChanged, this, &CSimulatorSelector::comboBoxChanged);
this->addComboxBoxValues();
} }
CSimulatorSelector::~CSimulatorSelector() CSimulatorSelector::~CSimulatorSelector()
@@ -51,37 +60,37 @@ namespace BlackGui
void CSimulatorSelector::setMode(CSimulatorSelector::Mode mode) void CSimulatorSelector::setMode(CSimulatorSelector::Mode mode)
{ {
m_mode = mode; m_mode = mode;
ui->wi_CheckBoxes->setVisible(false);
ui->wi_RadioButtons->setVisible(false);
ui->wi_ComboBox->setVisible(false);
switch (mode) switch (mode)
{ {
default: default:
case CheckBoxes: case CheckBoxes:
ui->wi_CheckBoxes->setVisible(true); ui->wi_CheckBoxes->setVisible(true);
ui->wi_RadioButtons->setVisible(false);
break; break;
case RadioButtons: case RadioButtons:
ui->wi_CheckBoxes->setVisible(false);
ui->wi_RadioButtons->setVisible(true); ui->wi_RadioButtons->setVisible(true);
break; break;
case ComboBox:
ui->wi_ComboBox->setVisible(true);
break;
} }
this->setToLastSelection(); this->setToLastSelection();
} }
CSimulatorInfo CSimulatorSelector::getValue() const CSimulatorInfo CSimulatorSelector::getValue() const
{ {
if (m_noSelectionMeansAll && this->isUnselected()) if (m_noSelectionMeansAll && this->isUnselected()) { return CSimulatorInfo::allSimulators(); }
{
return CSimulatorInfo::allSimulators();
}
switch (m_mode) switch (m_mode)
{ {
default: default:
case CheckBoxes: case CheckBoxes: return CSimulatorInfo(ui->cb_FSX->isChecked(), ui->cb_FS9->isChecked(), ui->cb_XPlane->isChecked(), ui->cb_P3D->isChecked(), m_withFG && ui->cb_FG->isChecked());
return CSimulatorInfo(ui->cb_FSX->isChecked(), ui->cb_FS9->isChecked(), case RadioButtons: return CSimulatorInfo(ui->rb_FSX->isChecked(), ui->rb_FS9->isChecked(), ui->rb_XPlane->isChecked(), ui->rb_P3D->isChecked(), m_withFG && ui->rb_FG->isChecked());
ui->cb_XPlane->isChecked(), ui->cb_P3D->isChecked()); case ComboBox: return CSimulatorInfo(ui->cb_Simulators->currentText());
case RadioButtons:
return CSimulatorInfo(ui->rb_FSX->isChecked(), ui->rb_FS9->isChecked(),
ui->rb_XPlane->isChecked(), ui->rb_P3D->isChecked());
} }
} }
@@ -95,12 +104,16 @@ namespace BlackGui
ui->cb_FS9->setChecked(simulator.isFS9()); ui->cb_FS9->setChecked(simulator.isFS9());
ui->cb_XPlane->setChecked(simulator.isXPlane()); ui->cb_XPlane->setChecked(simulator.isXPlane());
ui->cb_P3D->setChecked(simulator.isP3D()); ui->cb_P3D->setChecked(simulator.isP3D());
ui->cb_FG->setChecked(simulator.isFG());
// radio buttons // radio buttons
if (simulator.isFSX()) { ui->rb_FSX->setChecked(simulator.isFSX()); return; } if (simulator.isFSX()) { ui->rb_FSX->setChecked(simulator.isFSX()); return; }
if (simulator.isFS9()) { ui->rb_FS9->setChecked(simulator.isFS9()); return; } if (simulator.isFS9()) { ui->rb_FS9->setChecked(simulator.isFS9()); return; }
if (simulator.isXPlane()) { ui->rb_XPlane->setChecked(simulator.isXPlane()); return; } if (simulator.isXPlane()) { ui->rb_XPlane->setChecked(simulator.isXPlane()); return; }
if (simulator.isP3D()) { ui->rb_P3D->setChecked(simulator.isP3D()); return; } if (simulator.isP3D()) { ui->rb_P3D->setChecked(simulator.isP3D()); return; }
if (simulator.isFG()) { ui->rb_FG->setChecked(simulator.isFG()); return; }
ui->cb_Simulators->setCurrentText(simulator.toQString(true));
} }
void CSimulatorSelector::setToLastSelection() void CSimulatorSelector::setToLastSelection()
@@ -146,6 +159,7 @@ namespace BlackGui
return; return;
} }
if (!sGui || sGui->isShuttingDown()) { return; }
QPointer<CSimulatorSelector> myself(this); QPointer<CSimulatorSelector> myself(this);
QTimer::singleShot(deferredMs, this, [ = ] QTimer::singleShot(deferredMs, this, [ = ]
{ {
@@ -158,8 +172,19 @@ namespace BlackGui
{ {
ui->cb_FS9->setVisible(false); ui->cb_FS9->setVisible(false);
ui->cb_XPlane->setVisible(false); ui->cb_XPlane->setVisible(false);
ui->cb_FG->setVisible(false);
ui->rb_FS9->setVisible(false); ui->rb_FS9->setVisible(false);
ui->rb_XPlane->setVisible(false); ui->rb_XPlane->setVisible(false);
ui->rb_FG->setVisible(false);
}
void CSimulatorSelector::enableFG(bool enabled)
{
m_withFG = enabled;
ui->cb_FG->setVisible(enabled);
ui->rb_FG->setVisible(enabled);
ui->cb_FG->setChecked(false);
ui->rb_FG->setChecked(false);
} }
void CSimulatorSelector::checkAll() void CSimulatorSelector::checkAll()
@@ -169,9 +194,10 @@ namespace BlackGui
ui->cb_FS9->setChecked(true); ui->cb_FS9->setChecked(true);
ui->cb_XPlane->setChecked(true); ui->cb_XPlane->setChecked(true);
ui->cb_P3D->setChecked(true); ui->cb_P3D->setChecked(true);
ui->cb_FG->setChecked(true);
// radio // radio
ui->rb_FSX->setChecked(true); ui->rb_P3D->setChecked(true);
} }
void CSimulatorSelector::uncheckAll() void CSimulatorSelector::uncheckAll()
@@ -181,6 +207,7 @@ namespace BlackGui
ui->cb_FS9->setChecked(false); ui->cb_FS9->setChecked(false);
ui->cb_XPlane->setChecked(false); ui->cb_XPlane->setChecked(false);
ui->cb_P3D->setChecked(false); ui->cb_P3D->setChecked(false);
ui->cb_FG->setChecked(false);
} }
bool CSimulatorSelector::isUnselected() const bool CSimulatorSelector::isUnselected() const
@@ -190,12 +217,14 @@ namespace BlackGui
{ {
default: default:
case CheckBoxes: case CheckBoxes:
c = ui->cb_FSX->isChecked() || ui->cb_FS9->isChecked() || c = ui->cb_FSX->isChecked() || ui->cb_FS9->isChecked() || ui->cb_XPlane->isChecked() || ui->cb_P3D->isChecked() || (m_withFG && ui->rb_FG->isChecked());
ui->cb_XPlane->isChecked() || ui->cb_P3D->isChecked();
break; break;
case RadioButtons: case RadioButtons:
c = ui->rb_FSX->isChecked() || ui->rb_FS9->isChecked() || c = ui->rb_FSX->isChecked() || ui->rb_FS9->isChecked() || ui->rb_XPlane->isChecked() || ui->cb_P3D->isChecked() || (m_withFG && ui->cb_FG->isChecked());
ui->rb_XPlane->isChecked() || ui->cb_P3D->isChecked(); break;
case ComboBox:
const int i = ui->cb_Simulators->currentIndex();
c = i < 0;
break; break;
} }
return !c; return !c;
@@ -208,13 +237,16 @@ namespace BlackGui
{ {
default: default:
case CheckBoxes: case CheckBoxes:
c = ui->cb_FSX->isChecked() && ui->cb_FS9->isChecked() && c = ui->cb_FSX->isChecked() && ui->cb_FS9->isChecked() && ui->cb_XPlane->isChecked() && ui->cb_P3D->isChecked() && (!m_withFG || ui->cb_FG->isChecked());
ui->cb_XPlane->isChecked() && ui->cb_P3D->isChecked();
break; break;
case RadioButtons: case RadioButtons:
// actually this should never be true // actually this should never be true
c = false; c = false;
break; break;
case ComboBox:
// actually this should never be true
c = false;
break;
} }
return c; return c;
} }
@@ -244,6 +276,11 @@ namespace BlackGui
} }
} }
bool CSimulatorSelector::isSingleSelection() const
{
return m_mode == RadioButtons || m_mode == ComboBox;
}
void CSimulatorSelector::setReadOnly(bool readOnly) void CSimulatorSelector::setReadOnly(bool readOnly)
{ {
CGuiUtility::checkBoxesReadOnly(this, readOnly); CGuiUtility::checkBoxesReadOnly(this, readOnly);
@@ -251,6 +288,10 @@ namespace BlackGui
ui->rb_FS9->setEnabled(!readOnly); ui->rb_FS9->setEnabled(!readOnly);
ui->rb_XPlane->setEnabled(!readOnly); ui->rb_XPlane->setEnabled(!readOnly);
ui->rb_P3D->setEnabled(!readOnly); ui->rb_P3D->setEnabled(!readOnly);
ui->rb_FG->setEnabled(!readOnly);
ui->cb_Simulators->setEnabled(!readOnly);
this->setEnabled(!readOnly); this->setEnabled(!readOnly);
} }
@@ -268,15 +309,24 @@ namespace BlackGui
m_digestButtonsChanged.inputSignal(); m_digestButtonsChanged.inputSignal();
} }
void CSimulatorSelector::comboBoxChanged(const QString &value)
{
if (m_mode != ComboBox) { return; }
Q_UNUSED(value);
m_digestButtonsChanged.inputSignal();
}
void CSimulatorSelector::rememberSelection() void CSimulatorSelector::rememberSelection()
{ {
if (!m_rememberSelection) { return; } if (!m_rememberSelection) { return; }
if (m_mode == RadioButtons) if (this->isSingleSelection())
{ {
// single
m_currentSimulator.set(this->getValue()); m_currentSimulator.set(this->getValue());
} }
else else
{ {
// multiple
m_currentSimulators.set(this->getValue()); m_currentSimulators.set(this->getValue());
} }
} }
@@ -317,5 +367,10 @@ namespace BlackGui
this->rememberSelection(); this->rememberSelection();
emit this->changed(simulator); emit this->changed(simulator);
} }
void CSimulatorSelector::addComboxBoxValues()
{
ui->cb_Simulators->addItems(CSimulatorInfo::allSimulatorStrings());
}
} // ns } // ns
} // ns } // ns

View File

@@ -39,8 +39,9 @@ namespace BlackGui
//! How to display //! How to display
enum Mode enum Mode
{ {
CheckBoxes, CheckBoxes, //!< multiple selections
RadioButtons RadioButtons, //!< single
ComboBox //!< single
}; };
//! Constructor //! Constructor
@@ -73,6 +74,9 @@ namespace BlackGui
//! Only show FSX/P3D //! Only show FSX/P3D
void setFsxP3DOnly(); void setFsxP3DOnly();
//! Enable FG
void enableFG(bool enabled);
//! Set all, only making sense with checkboxes //! Set all, only making sense with checkboxes
void checkAll(); void checkAll();
@@ -100,6 +104,9 @@ namespace BlackGui
//! Clear values //! Clear values
void clear(); void clear();
//! Single selection mode (radio buttons)
bool isSingleSelection() const;
//! Set read only //! Set read only
void setReadOnly(bool readOnly); void setReadOnly(bool readOnly);
@@ -114,6 +121,9 @@ namespace BlackGui
//! Checkbox changed //! Checkbox changed
void checkBoxChanged(bool checked); void checkBoxChanged(bool checked);
//! ComboBox has been changed
void comboBoxChanged(const QString &value);
//! Remember last selection //! Remember last selection
void rememberSelection(); void rememberSelection();
@@ -132,10 +142,14 @@ namespace BlackGui
//! Emit the CSimulatorSelector::changed signal //! Emit the CSimulatorSelector::changed signal
void emitChangedSignal(); void emitChangedSignal();
//! Add all combobox values
void addComboxBoxValues();
QScopedPointer<Ui::CSimulatorSelector> ui; QScopedPointer<Ui::CSimulatorSelector> ui;
Mode m_mode = CheckBoxes; Mode m_mode = CheckBoxes;
bool m_withFG = false; //! with FG
bool m_noSelectionMeansAll = false; //!< for filters, no selection means all bool m_noSelectionMeansAll = false; //!< for filters, no selection means all
bool m_rememberSelection = false; //!< remember last selection bool m_rememberSelection = false; //!< remember last selection
BlackMisc::CDigestSignal m_digestButtonsChanged { this, &CSimulatorSelector::emitChangedSignal, 250, 3 }; BlackMisc::CDigestSignal m_digestButtonsChanged { this, &CSimulatorSelector::emitChangedSignal, 250, 3 };
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this, &CSimulatorSelector::changedLastSelectionRb }; //!< current simulator (used with radio buttons) BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this, &CSimulatorSelector::changedLastSelectionRb }; //!< current simulator (used with radio buttons)
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelections> m_currentSimulators { this, &CSimulatorSelector::changedLastSelectionCb }; //!< current simulators (used with multiple checkboxes) BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelections> m_currentSimulators { this, &CSimulatorSelector::changedLastSelectionCb }; //!< current simulators (used with multiple checkboxes)

View File

@@ -2,13 +2,18 @@
<ui version="4.0"> <ui version="4.0">
<class>CSimulatorSelector</class> <class>CSimulatorSelector</class>
<widget class="QFrame" name="CSimulatorSelector"> <widget class="QFrame" name="CSimulatorSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>188</width>
<height>66</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Simulator selector</string> <string>Simulator selector</string>
</property> </property>
<layout class="QVBoxLayout" name="vl_SimulatorSelector"> <layout class="QVBoxLayout" name="vl_SimulatorSelector">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@@ -70,6 +75,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="cb_FG">
<property name="toolTip">
<string>FlightGear</string>
</property>
<property name="whatsThis">
<string>FlightGear</string>
</property>
<property name="text">
<string>FG</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@@ -128,11 +146,61 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="rb_FG">
<property name="toolTip">
<string>FlightGear</string>
</property>
<property name="whatsThis">
<string>FlightGear</string>
</property>
<property name="text">
<string>FG</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="wi_ComboBox" native="true">
<layout class="QVBoxLayout" name="vl_ComboBox">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cb_Simulators"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>cb_P3D</tabstop>
<tabstop>cb_FSX</tabstop>
<tabstop>cb_FS9</tabstop>
<tabstop>cb_XPlane</tabstop>
<tabstop>cb_FG</tabstop>
<tabstop>rb_P3D</tabstop>
<tabstop>rb_FSX</tabstop>
<tabstop>rb_FS9</tabstop>
<tabstop>rb_XPlane</tabstop>
<tabstop>rb_FG</tabstop>
<tabstop>cb_Simulators</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>