mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
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:
@@ -10,8 +10,9 @@
|
||||
#include "blackgui/components/simulatorselector.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackcore/context/contextsimulator.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "ui_simulatorselector.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPointer>
|
||||
|
||||
using namespace BlackConfig;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackCore::Context;
|
||||
|
||||
@@ -32,17 +34,24 @@ namespace BlackGui
|
||||
ui(new Ui::CSimulatorSelector)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->enableFG(false && CBuildConfig::isLocalDeveloperDebugBuild());
|
||||
this->setMode(CheckBoxes);
|
||||
|
||||
connect(ui->rb_FS9, &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_FG, &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_FSX, &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_Simulators, &QComboBox::currentTextChanged, this, &CSimulatorSelector::comboBoxChanged);
|
||||
|
||||
this->addComboxBoxValues();
|
||||
}
|
||||
|
||||
CSimulatorSelector::~CSimulatorSelector()
|
||||
@@ -51,37 +60,37 @@ namespace BlackGui
|
||||
void CSimulatorSelector::setMode(CSimulatorSelector::Mode mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
|
||||
ui->wi_CheckBoxes->setVisible(false);
|
||||
ui->wi_RadioButtons->setVisible(false);
|
||||
ui->wi_ComboBox->setVisible(false);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
case CheckBoxes:
|
||||
ui->wi_CheckBoxes->setVisible(true);
|
||||
ui->wi_RadioButtons->setVisible(false);
|
||||
break;
|
||||
case RadioButtons:
|
||||
ui->wi_CheckBoxes->setVisible(false);
|
||||
ui->wi_RadioButtons->setVisible(true);
|
||||
break;
|
||||
case ComboBox:
|
||||
ui->wi_ComboBox->setVisible(true);
|
||||
break;
|
||||
}
|
||||
this->setToLastSelection();
|
||||
}
|
||||
|
||||
CSimulatorInfo CSimulatorSelector::getValue() const
|
||||
{
|
||||
if (m_noSelectionMeansAll && this->isUnselected())
|
||||
{
|
||||
return CSimulatorInfo::allSimulators();
|
||||
}
|
||||
if (m_noSelectionMeansAll && this->isUnselected()) { return CSimulatorInfo::allSimulators(); }
|
||||
|
||||
switch (m_mode)
|
||||
{
|
||||
default:
|
||||
case CheckBoxes:
|
||||
return CSimulatorInfo(ui->cb_FSX->isChecked(), ui->cb_FS9->isChecked(),
|
||||
ui->cb_XPlane->isChecked(), ui->cb_P3D->isChecked());
|
||||
case RadioButtons:
|
||||
return CSimulatorInfo(ui->rb_FSX->isChecked(), ui->rb_FS9->isChecked(),
|
||||
ui->rb_XPlane->isChecked(), ui->rb_P3D->isChecked());
|
||||
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());
|
||||
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());
|
||||
case ComboBox: return CSimulatorInfo(ui->cb_Simulators->currentText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,12 +104,16 @@ namespace BlackGui
|
||||
ui->cb_FS9->setChecked(simulator.isFS9());
|
||||
ui->cb_XPlane->setChecked(simulator.isXPlane());
|
||||
ui->cb_P3D->setChecked(simulator.isP3D());
|
||||
ui->cb_FG->setChecked(simulator.isFG());
|
||||
|
||||
// radio buttons
|
||||
if (simulator.isFSX()) { ui->rb_FSX->setChecked(simulator.isFSX()); return; }
|
||||
if (simulator.isFS9()) { ui->rb_FS9->setChecked(simulator.isFS9()); return; }
|
||||
if (simulator.isXPlane()) { ui->rb_XPlane->setChecked(simulator.isXPlane()); 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()
|
||||
@@ -146,6 +159,7 @@ namespace BlackGui
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
QPointer<CSimulatorSelector> myself(this);
|
||||
QTimer::singleShot(deferredMs, this, [ = ]
|
||||
{
|
||||
@@ -158,8 +172,19 @@ namespace BlackGui
|
||||
{
|
||||
ui->cb_FS9->setVisible(false);
|
||||
ui->cb_XPlane->setVisible(false);
|
||||
ui->cb_FG->setVisible(false);
|
||||
ui->rb_FS9->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()
|
||||
@@ -169,9 +194,10 @@ namespace BlackGui
|
||||
ui->cb_FS9->setChecked(true);
|
||||
ui->cb_XPlane->setChecked(true);
|
||||
ui->cb_P3D->setChecked(true);
|
||||
ui->cb_FG->setChecked(true);
|
||||
|
||||
// radio
|
||||
ui->rb_FSX->setChecked(true);
|
||||
ui->rb_P3D->setChecked(true);
|
||||
}
|
||||
|
||||
void CSimulatorSelector::uncheckAll()
|
||||
@@ -181,6 +207,7 @@ namespace BlackGui
|
||||
ui->cb_FS9->setChecked(false);
|
||||
ui->cb_XPlane->setChecked(false);
|
||||
ui->cb_P3D->setChecked(false);
|
||||
ui->cb_FG->setChecked(false);
|
||||
}
|
||||
|
||||
bool CSimulatorSelector::isUnselected() const
|
||||
@@ -190,12 +217,14 @@ namespace BlackGui
|
||||
{
|
||||
default:
|
||||
case CheckBoxes:
|
||||
c = ui->cb_FSX->isChecked() || ui->cb_FS9->isChecked() ||
|
||||
ui->cb_XPlane->isChecked() || ui->cb_P3D->isChecked();
|
||||
c = ui->cb_FSX->isChecked() || ui->cb_FS9->isChecked() || ui->cb_XPlane->isChecked() || ui->cb_P3D->isChecked() || (m_withFG && ui->rb_FG->isChecked());
|
||||
break;
|
||||
case RadioButtons:
|
||||
c = ui->rb_FSX->isChecked() || ui->rb_FS9->isChecked() ||
|
||||
ui->rb_XPlane->isChecked() || ui->cb_P3D->isChecked();
|
||||
c = ui->rb_FSX->isChecked() || ui->rb_FS9->isChecked() || ui->rb_XPlane->isChecked() || ui->cb_P3D->isChecked() || (m_withFG && ui->cb_FG->isChecked());
|
||||
break;
|
||||
case ComboBox:
|
||||
const int i = ui->cb_Simulators->currentIndex();
|
||||
c = i < 0;
|
||||
break;
|
||||
}
|
||||
return !c;
|
||||
@@ -208,13 +237,16 @@ namespace BlackGui
|
||||
{
|
||||
default:
|
||||
case CheckBoxes:
|
||||
c = ui->cb_FSX->isChecked() && ui->cb_FS9->isChecked() &&
|
||||
ui->cb_XPlane->isChecked() && ui->cb_P3D->isChecked();
|
||||
c = ui->cb_FSX->isChecked() && ui->cb_FS9->isChecked() && ui->cb_XPlane->isChecked() && ui->cb_P3D->isChecked() && (!m_withFG || ui->cb_FG->isChecked());
|
||||
break;
|
||||
case RadioButtons:
|
||||
// actually this should never be true
|
||||
c = false;
|
||||
break;
|
||||
case ComboBox:
|
||||
// actually this should never be true
|
||||
c = false;
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@@ -244,6 +276,11 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorSelector::isSingleSelection() const
|
||||
{
|
||||
return m_mode == RadioButtons || m_mode == ComboBox;
|
||||
}
|
||||
|
||||
void CSimulatorSelector::setReadOnly(bool readOnly)
|
||||
{
|
||||
CGuiUtility::checkBoxesReadOnly(this, readOnly);
|
||||
@@ -251,6 +288,10 @@ namespace BlackGui
|
||||
ui->rb_FS9->setEnabled(!readOnly);
|
||||
ui->rb_XPlane->setEnabled(!readOnly);
|
||||
ui->rb_P3D->setEnabled(!readOnly);
|
||||
ui->rb_FG->setEnabled(!readOnly);
|
||||
|
||||
ui->cb_Simulators->setEnabled(!readOnly);
|
||||
|
||||
this->setEnabled(!readOnly);
|
||||
}
|
||||
|
||||
@@ -268,15 +309,24 @@ namespace BlackGui
|
||||
m_digestButtonsChanged.inputSignal();
|
||||
}
|
||||
|
||||
void CSimulatorSelector::comboBoxChanged(const QString &value)
|
||||
{
|
||||
if (m_mode != ComboBox) { return; }
|
||||
Q_UNUSED(value);
|
||||
m_digestButtonsChanged.inputSignal();
|
||||
}
|
||||
|
||||
void CSimulatorSelector::rememberSelection()
|
||||
{
|
||||
if (!m_rememberSelection) { return; }
|
||||
if (m_mode == RadioButtons)
|
||||
if (this->isSingleSelection())
|
||||
{
|
||||
// single
|
||||
m_currentSimulator.set(this->getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
// multiple
|
||||
m_currentSimulators.set(this->getValue());
|
||||
}
|
||||
}
|
||||
@@ -317,5 +367,10 @@ namespace BlackGui
|
||||
this->rememberSelection();
|
||||
emit this->changed(simulator);
|
||||
}
|
||||
|
||||
void CSimulatorSelector::addComboxBoxValues()
|
||||
{
|
||||
ui->cb_Simulators->addItems(CSimulatorInfo::allSimulatorStrings());
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -39,8 +39,9 @@ namespace BlackGui
|
||||
//! How to display
|
||||
enum Mode
|
||||
{
|
||||
CheckBoxes,
|
||||
RadioButtons
|
||||
CheckBoxes, //!< multiple selections
|
||||
RadioButtons, //!< single
|
||||
ComboBox //!< single
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
@@ -73,6 +74,9 @@ namespace BlackGui
|
||||
//! Only show FSX/P3D
|
||||
void setFsxP3DOnly();
|
||||
|
||||
//! Enable FG
|
||||
void enableFG(bool enabled);
|
||||
|
||||
//! Set all, only making sense with checkboxes
|
||||
void checkAll();
|
||||
|
||||
@@ -100,6 +104,9 @@ namespace BlackGui
|
||||
//! Clear values
|
||||
void clear();
|
||||
|
||||
//! Single selection mode (radio buttons)
|
||||
bool isSingleSelection() const;
|
||||
|
||||
//! Set read only
|
||||
void setReadOnly(bool readOnly);
|
||||
|
||||
@@ -114,6 +121,9 @@ namespace BlackGui
|
||||
//! Checkbox changed
|
||||
void checkBoxChanged(bool checked);
|
||||
|
||||
//! ComboBox has been changed
|
||||
void comboBoxChanged(const QString &value);
|
||||
|
||||
//! Remember last selection
|
||||
void rememberSelection();
|
||||
|
||||
@@ -132,10 +142,14 @@ namespace BlackGui
|
||||
//! Emit the CSimulatorSelector::changed signal
|
||||
void emitChangedSignal();
|
||||
|
||||
//! Add all combobox values
|
||||
void addComboxBoxValues();
|
||||
|
||||
QScopedPointer<Ui::CSimulatorSelector> ui;
|
||||
Mode m_mode = CheckBoxes;
|
||||
bool m_withFG = false; //! with FG
|
||||
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::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)
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
<ui version="4.0">
|
||||
<class>CSimulatorSelector</class>
|
||||
<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">
|
||||
<string>Simulator selector</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_SimulatorSelector">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -70,6 +75,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -128,11 +146,61 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</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/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user