diff --git a/src/blackgui/components/configsimulatorcomponent.cpp b/src/blackgui/components/configsimulatorcomponent.cpp new file mode 100644 index 000000000..e2452affb --- /dev/null +++ b/src/blackgui/components/configsimulatorcomponent.cpp @@ -0,0 +1,98 @@ +/* Copyright (C) 2017 + * swift project community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "configsimulatorcomponent.h" +#include "blackconfig/buildconfig.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/simulation/fscommon/fscommonutil.h" +#include "ui_configsimulatorcomponent.h" + +using namespace BlackMisc; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Simulation::FsCommon; +using namespace BlackConfig; + +namespace BlackGui +{ + namespace Components + { + CConfigSimulatorComponent::CConfigSimulatorComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CConfigSimulatorComponent) + { + ui->setupUi(this); + this->preselectSimulators(); + } + + CConfigSimulatorComponent::~CConfigSimulatorComponent() + { } + + void CConfigSimulatorComponent::save() + { + ui->comp_SettingsSimulator->save(); + const QStringList sims = this->selectedSimsToPluginIds(); + const CStatusMessage msg = m_enabledSimulators.setAndSave(sims); + CLogMessage::preformatted(msg); + } + + void CConfigSimulatorComponent::preselectSimulators() + { + CSimulatorInfo sims; + if (m_enabledSimulators.isSaved()) + { + sims = CSimulatorInfo(m_enabledSimulators.get()); + } + else + { + // by model set + sims = m_modelSets.simulatorsWithInitializedCache(); + } + + const bool p3d = (sims.p3d() || !CFsCommonUtil::p3dDir().isEmpty()) && CBuildConfig::isCompiledWithP3DSupport(); + const bool fsx = (sims.fsx() || !CFsCommonUtil::fsxDir().isEmpty()) && CBuildConfig::isCompiledWithFsxSupport(); + const bool fs9 = (sims.fs9() || !CFsCommonUtil::fs9Dir().isEmpty()) && CBuildConfig::isCompiledWithFs9Support(); + const bool xp = sims.xplane() && CBuildConfig::isCompiledWithXPlaneSupport(); + + ui->cb_P3D->setChecked(p3d); + ui->cb_FSX->setChecked(fsx); + ui->cb_FS9->setChecked(fs9); + ui->cb_XP->setChecked(xp); // \fixme some default for XP? + + ui->cb_P3D->setEnabled(CBuildConfig::isCompiledWithP3DSupport()); + ui->cb_FSX->setEnabled(CBuildConfig::isCompiledWithFsxSupport()); + ui->cb_FS9->setEnabled(CBuildConfig::isCompiledWithFs9Support()); + ui->cb_XP->setEnabled(CBuildConfig::isCompiledWithXPlaneSupport()); + + if (p3d) { ui->comp_SettingsSimulator->setSimulator(CSimulatorInfo(CSimulatorInfo::P3D)); } + else if (fsx) { ui->comp_SettingsSimulator->setSimulator(CSimulatorInfo(CSimulatorInfo::FSX)); } + else if (fs9) { ui->comp_SettingsSimulator->setSimulator(CSimulatorInfo(CSimulatorInfo::FS9)); } + else if (xp) { ui->comp_SettingsSimulator->setSimulator(CSimulatorInfo(CSimulatorInfo::XPLANE)); } + } + + QStringList CConfigSimulatorComponent::selectedSimsToPluginIds() + { + QStringList ids; + + // have to match ids from swift-plugin-simulators.xml + if (ui->cb_FS9->isChecked()) { ids << "fs2004"; } + if (ui->cb_FSX->isChecked()) { ids << "fsx"; } + if (ui->cb_P3D->isChecked()) { ids << "p3d"; } + if (ui->cb_XP->isChecked()) { ids << "xplane"; } + + return ids; + } + + bool CConfigSimulatorWizardPage::validatePage() + { + Q_ASSERT_X(m_config, Q_FUNC_INFO, "Missing config"); + m_config->save(); + return true; + } + } // ns +} // ns diff --git a/src/blackgui/components/configsimulatorcomponent.h b/src/blackgui/components/configsimulatorcomponent.h new file mode 100644 index 000000000..443ccbc9f --- /dev/null +++ b/src/blackgui/components/configsimulatorcomponent.h @@ -0,0 +1,75 @@ +/* Copyright (C) 2017 + * swift project community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_CONFIGSIMULATORCOMPONENT_H +#define BLACKGUI_COMPONENTS_CONFIGSIMULATORCOMPONENT_H + +#include "blackmisc/simulation/data/modelcaches.h" +#include "blackcore/application/applicationsettings.h" +#include +#include +#include + +namespace Ui { class CConfigSimulatorComponent; } +namespace BlackGui +{ + namespace Components + { + /** + * Simulator configuration + */ + class CConfigSimulatorComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CConfigSimulatorComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CConfigSimulatorComponent(); + + //! Save data + void save(); + + private: + //! Preselect simulators + void preselectSimulators(); + + //! Get the plugin ids + QStringList selectedSimsToPluginIds(); + + BlackMisc::CSetting m_enabledSimulators { this }; + BlackMisc::Simulation::Data::CModelSetCaches m_modelSets { true, this }; + QScopedPointer ui; + }; + + /** + * Wizard page for CConfigSimulatorComponent + */ + class CConfigSimulatorWizardPage : public QWizardPage + { + public: + //! Constructors + using QWizardPage::QWizardPage; + + //! Set config + void setConfigComponent(CConfigSimulatorComponent *config) { m_config = config; } + + //! \copydoc QWizardPage::validatePage + virtual bool validatePage() override; + + private: + CConfigSimulatorComponent *m_config = nullptr; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/configsimulatorcomponent.ui b/src/blackgui/components/configsimulatorcomponent.ui new file mode 100644 index 000000000..7b22e099b --- /dev/null +++ b/src/blackgui/components/configsimulatorcomponent.ui @@ -0,0 +1,190 @@ + + + CConfigSimulatorComponent + + + + 0 + 0 + 640 + 480 + + + + Frame + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + Select your simulator(s) + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + background: "lightgrey" + + + <img width="100" src=":/simulators/icons/simulators/FSX.png"/> + + + + + + + background: "lightgrey" + + + <img width="100" src=":/simulators/icons/simulators/FS9.png"/> + + + + + + + background: "lightgrey" + + + <img width="100" src=":/simulators/icons/simulators/XPlane.png"/> + + + + + + + FSX + + + + + + + XPlane + + + + + + + FS9 + + + + 64 + 64 + + + + + + + + P3D + + + + + + + background: "lightgrey" + + + <img width="130" src=":/simulators/icons/simulators/Prepar3D.png"/> + + + + + + + + + + Setup of each individual simulator + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + <html><head/><body><p>Simulator directories: <span style=" font-weight:600;">Normally</span> there is <span style=" font-weight:600;">no need</span> to override the defaults. But if the simulator directories / excludes are incorrect you can set individual values here.</p></body></html> + + + true + + + + + + + + 0 + 100 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + BlackGui::Components::CSettingsSimulatorBasicsComponent + QFrame +
blackgui/components/settingssimulatorbasicscomponent.h
+ 1 +
+
+ + +
diff --git a/src/blackgui/components/settingssimulatorbasicscomponent.cpp b/src/blackgui/components/settingssimulatorbasicscomponent.cpp index 94a398c00..5b9b934a4 100644 --- a/src/blackgui/components/settingssimulatorbasicscomponent.cpp +++ b/src/blackgui/components/settingssimulatorbasicscomponent.cpp @@ -32,7 +32,7 @@ namespace BlackGui connect(ui->pb_ExcludeFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_excludeFileDialog); connect(ui->pb_ModelFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_modelFileDialog); connect(ui->pb_SimulatorFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_simulatorFileDialog); - connect(ui->pb_Save, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_save); + connect(ui->pb_Save, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::save); connect(ui->pb_Reset, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_reset); connect(ui->pb_CopyDefaults, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::ps_copyDefaults); connect(ui->le_SimulatorDirectory, &QLineEdit::returnPressed, this, &CSettingsSimulatorBasicsComponent::ps_simulatorDirectoryEntered); @@ -55,11 +55,6 @@ namespace BlackGui ui->comp_SimulatorSelector->setValue(simulator); } - void CSettingsSimulatorBasicsComponent::save() - { - this->ps_save(); - } - void CSettingsSimulatorBasicsComponent::setSmallLayout(bool small) { ui->lbl_ExcludeDirectories->setWordWrap(small); @@ -104,7 +99,7 @@ namespace BlackGui this->displayDefaultValuesAsPlaceholder(simulator); } - void CSettingsSimulatorBasicsComponent::ps_save() + void CSettingsSimulatorBasicsComponent::save() { const CSimulatorInfo simulator(ui->comp_SimulatorSelector->getValue()); CSimulatorSettings s = this->getSettings(simulator); diff --git a/src/blackgui/components/settingssimulatorbasicscomponent.h b/src/blackgui/components/settingssimulatorbasicscomponent.h index 81df92dda..473c26813 100644 --- a/src/blackgui/components/settingssimulatorbasicscomponent.h +++ b/src/blackgui/components/settingssimulatorbasicscomponent.h @@ -50,7 +50,6 @@ namespace BlackGui void ps_excludeFileDialog(); void ps_simulatorFileDialog(); void ps_simulatorDirectoryEntered(); - void ps_save(); void ps_copyDefaults(); void ps_reset(); void ps_simulatorChanged(); diff --git a/src/blackgui/components/settingssimulatorbasicscomponent.ui b/src/blackgui/components/settingssimulatorbasicscomponent.ui index b4b3f711e..ac46912be 100644 --- a/src/blackgui/components/settingssimulatorbasicscomponent.ui +++ b/src/blackgui/components/settingssimulatorbasicscomponent.ui @@ -44,16 +44,6 @@ - - - - Excluded from model loading - - - Exclude directory patterns: - - - @@ -129,6 +119,16 @@ + + + + Excluded from model loading + + + Exclude directory patterns: + + +