diff --git a/src/blackgui/settingscomponent.ui b/src/blackgui/settingscomponent.ui index 05d636c72..159f3cfb1 100644 --- a/src/blackgui/settingscomponent.ui +++ b/src/blackgui/settingscomponent.ui @@ -527,7 +527,7 @@ - + QFrame::StyledPanel @@ -743,9 +743,9 @@
blackgui/serverview.h
- BlackGui::CSettingsFsxComponent + BlackGui::CSettingsSimulatorComponent QFrame -
blackgui/settingsfsxcomponent.h
+
blackgui/settingssimulatorcomponent.h
1
diff --git a/src/blackgui/settingsfsxcomponent.ui b/src/blackgui/settingsfsxcomponent.ui index 2a2bee7e8..f3f83714b 100644 --- a/src/blackgui/settingsfsxcomponent.ui +++ b/src/blackgui/settingsfsxcomponent.ui @@ -7,7 +7,7 @@ 0 0 400 - 300 + 150 @@ -40,35 +40,35 @@ QFormLayout::AllNonFixedFieldsGrow - + FSX address - + 127.0.0.1 - + FSX port - + 500 - + @@ -100,14 +100,14 @@ - + "simconnect.cfg" exists? - + @@ -142,6 +142,13 @@ + + + + <html><head/><body><p><span style=" font-size:10pt; font-weight:600;">FSX simconnect config files</span></p></body></html> + + +
diff --git a/src/blackgui/settingssimulatorcomponent.cpp b/src/blackgui/settingssimulatorcomponent.cpp new file mode 100644 index 000000000..03914c13c --- /dev/null +++ b/src/blackgui/settingssimulatorcomponent.cpp @@ -0,0 +1,74 @@ +#include "settingssimulatorcomponent.h" +#include "ui_settingssimulatorcomponent.h" + +#include "blackcore/context_settings.h" +#include "blacksim/simulatorinfolist.h" +#include "blacksim/setsimulator.h" +#include "blackmisc/settingutilities.h" + +#include + +using namespace BlackMisc; +using namespace BlackMisc::Settings; +using namespace BlackSim; +using namespace BlackSim::Settings; +using namespace BlackCore; + +namespace BlackGui +{ + CSettingsSimulatorComponent::CSettingsSimulatorComponent(QWidget *parent) : + QFrame(parent), CRuntimeBasedComponent(nullptr, false), + ui(new Ui::CSettingsSimulatorComponent) + { + ui->setupUi(this); + bool connected = this->connect(this->ui->cb_SimulatorDriver, SIGNAL(currentIndexChanged(int)), this, SLOT(driverHasChanged(int))); + Q_ASSERT(connected); + Q_UNUSED(connected); + } + + CSettingsSimulatorComponent::~CSettingsSimulatorComponent() + { + delete ui; + } + + void CSettingsSimulatorComponent::runtimeHasBeenSet() + { + Q_ASSERT(this->getIContextSimulator()); + if (this->getIContextSimulator()) + { + QStringList drivers = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true); + this->ui->cb_SimulatorDriver->addItems(drivers); + + bool fsxDriver = + this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX()); + this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver); + } + } + + void CSettingsSimulatorComponent::driverHasChanged(int index) + { + Q_ASSERT(this->getIContextSimulator()); + Q_ASSERT(this->getIContextSettings()); + if (!this->getIContextSimulator() || !this->getIContextSettings()) return; + + CSimulatorInfoList simDrivers = this->getIContextSimulator()->getAvailableSimulatorPlugins(); + if (simDrivers.isEmpty()) + { + this->sendStatusMessage(CStatusMessage::getErrorMessage("No drivers available", CStatusMessage::TypeSimulator)); + return; + } + if (simDrivers.size() <= index) + { + this->sendStatusMessage(CStatusMessage::getErrorMessage("Wrong driver index", CStatusMessage::TypeSimulator)); + return; + } + + // update + CSimulatorInfo currentDriver = simDrivers[index]; + const QString path = CSettingUtilities::appendPaths(IContextSettings::PathSimulatorSettings(), CSettingsSimulator::ValueSelectedDriver()); + this->sendStatusMessages( + this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), currentDriver.toCVariant()) + ); + } + +} // namespace diff --git a/src/blackgui/settingssimulatorcomponent.h b/src/blackgui/settingssimulatorcomponent.h new file mode 100644 index 000000000..25ebe34b5 --- /dev/null +++ b/src/blackgui/settingssimulatorcomponent.h @@ -0,0 +1,38 @@ +#ifndef BLACKGUI_SETTINGSSIMULATORCOMPONENT_H +#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H + +#include "runtimebasedcomponent.h" +#include + +namespace Ui { class CSettingsSimulatorComponent; } + +namespace BlackGui +{ + /*! + * All simulator settings component (GUI) + */ + class CSettingsSimulatorComponent : public QFrame, public CRuntimeBasedComponent + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsSimulatorComponent(QWidget *parent = nullptr); + + //! Destructor + ~CSettingsSimulatorComponent(); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet() + virtual void runtimeHasBeenSet() override; + + private slots: + //! Driver changed + void driverHasChanged(int index); + + private: + Ui::CSettingsSimulatorComponent *ui; //!< UI + }; + +} // namespace +#endif // guard diff --git a/src/blackgui/settingssimulatorcomponent.ui b/src/blackgui/settingssimulatorcomponent.ui new file mode 100644 index 000000000..3e14671a3 --- /dev/null +++ b/src/blackgui/settingssimulatorcomponent.ui @@ -0,0 +1,89 @@ + + + CSettingsSimulatorComponent + + + + 0 + 0 + 424 + 318 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + Driver + + + + + + + + + + <html><head/><body><p><span style=" font-size:10pt; font-weight:600;">All simulators</span></p></body></html> + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + BlackGui::CSettingsFsxComponent + QFrame +
blackgui/settingsfsxcomponent.h
+ 1 +
+
+ + +