From c19fc6bc0634eddd01f3cc4ad1eae736ec186207 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 14 Apr 2017 17:36:28 +0100 Subject: [PATCH] =?UTF-8?q?Launcher:=20add=20=E2=80=98show=20console?= =?UTF-8?q?=E2=80=99=20setting=20on=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This entailed fixing the handling of the visibility property with an override from the QWidget basic version. --- src/GUI/GeneralSettings.qml | 13 +++++++++++++ src/GUI/LauncherMainWindow.cxx | 9 +++++++++ src/GUI/SettingsSection.cxx | 2 ++ src/GUI/SettingsSection.hxx | 2 +- src/GUI/SettingsSectionQML.cxx | 13 ++++++------- src/GUI/SettingsSectionQML.hxx | 2 ++ src/GUI/SettingsWidgets.cxx | 28 ++++++++++++++++++++++++++++ src/GUI/SettingsWidgets.hxx | 13 +++++++++++++ 8 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/GUI/GeneralSettings.qml b/src/GUI/GeneralSettings.qml index d16d5b46b..686da07b6 100644 --- a/src/GUI/GeneralSettings.qml +++ b/src/GUI/GeneralSettings.qml @@ -24,9 +24,22 @@ Section { option: "auto-coordination" } + Checkbox { + id: showConsoleWin + label: "Show debugging console" + description: "Open a console window showing debug output from the application." + advanced: true + visible: _osName == "win" + keywords: ["console"] + } + onApply: { if (startPaused.checked) { _config.setArg("enable-freeze") } + + if (showConsoleWin.checked) { + _config.setArg("console") + } } } diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx index 0d07dc752..1880db2b3 100644 --- a/src/GUI/LauncherMainWindow.cxx +++ b/src/GUI/LauncherMainWindow.cxx @@ -284,6 +284,15 @@ void LauncherMainWindow::initQML() m_qmlEngine->rootContext()->setContextProperty("_launcher", this); m_qmlEngine->rootContext()->setContextProperty("_mpServers", m_serversModel); +#if defined(Q_OS_WIN) + const QString osName("win"); +#elif defined(Q_OS_MAC) + const QString osName("mac"); +#else + const QString osName("unix"); +#endif + m_qmlEngine->rootContext()->setContextProperty("_osName", osName); + flightgear::WeatherScenariosModel* weatherScenariosModel = new flightgear::WeatherScenariosModel(this); m_qmlEngine->rootContext()->setContextProperty("_weatherScenarios", weatherScenariosModel); } diff --git a/src/GUI/SettingsSection.cxx b/src/GUI/SettingsSection.cxx index 206819bff..e158a44be 100644 --- a/src/GUI/SettingsSection.cxx +++ b/src/GUI/SettingsSection.cxx @@ -105,10 +105,12 @@ void SettingsSection::internalUpdateAdvanced() void SettingsSection::saveState(QSettings &settings) const { + Q_UNUSED(settings) } void SettingsSection::restoreState(QSettings &settings) { + Q_UNUSED(settings) } void SettingsSection::updateShowAdvanced() diff --git a/src/GUI/SettingsSection.hxx b/src/GUI/SettingsSection.hxx index f09eb7c90..56cbfa9c4 100644 --- a/src/GUI/SettingsSection.hxx +++ b/src/GUI/SettingsSection.hxx @@ -21,7 +21,7 @@ public: virtual void setLaunchConfig(LaunchConfig* config); - bool showAdvanced() const + virtual bool showAdvanced() const { return m_showAdvanced; } diff --git a/src/GUI/SettingsSectionQML.cxx b/src/GUI/SettingsSectionQML.cxx index b852e0f1e..9c252790d 100644 --- a/src/GUI/SettingsSectionQML.cxx +++ b/src/GUI/SettingsSectionQML.cxx @@ -19,13 +19,7 @@ void SettingsSectionQML::internalUpdateAdvanced() { const bool showAdvanced = m_showAdvanced | m_forceShowAdvanced; Q_FOREACH (SettingsControl* w, controls()) { - if (w->advanced()) { - w->setVisible(showAdvanced); - } - - if (w->property("simple").toBool()) { - w->setVisible(!showAdvanced); - } + w->updateWidgetVisibility(showAdvanced); } } @@ -151,6 +145,11 @@ QVariant SettingsSectionQML::restoreSetting(QString key) return settings.value(key); } +bool SettingsSectionQML::showAdvanced() const +{ + return m_showAdvanced | m_forceShowAdvanced; +} + void SettingsSectionQML::setSummary(QString summary) { if (m_summary == summary) diff --git a/src/GUI/SettingsSectionQML.hxx b/src/GUI/SettingsSectionQML.hxx index 09a00d5f6..69006370e 100644 --- a/src/GUI/SettingsSectionQML.hxx +++ b/src/GUI/SettingsSectionQML.hxx @@ -33,6 +33,8 @@ public: Q_INVOKABLE void saveSetting(QString key, QVariant value); Q_INVOKABLE QVariant restoreSetting(QString key); + + bool showAdvanced() const override; public slots: void setSummary(QString summary); diff --git a/src/GUI/SettingsWidgets.cxx b/src/GUI/SettingsWidgets.cxx index 9741c6abc..c4126cbf3 100644 --- a/src/GUI/SettingsWidgets.cxx +++ b/src/GUI/SettingsWidgets.cxx @@ -17,6 +17,7 @@ #include #include "LaunchConfig.hxx" +#include "SettingsSection.hxx" const int MARGIN_HINT = 4; @@ -64,6 +65,11 @@ bool SettingsControl::setSearchTerm(QString search) return inSearch; } +bool SettingsControl::qmlVisible() const +{ + return m_localVisible; +} + void SettingsControl::setAdvanced(bool advanced) { if (m_advanced == advanced) @@ -104,6 +110,17 @@ void SettingsControl::setOption(QString option) emit optionChanged(option); } +void SettingsControl::setQmlVisible(bool visible) +{ + if (m_localVisible == visible) + return; + + m_localVisible = visible; + SettingsSection* section = qobject_cast(parent()); + updateWidgetVisibility(section->showAdvanced()); + emit qmlVisibleChanged(visible); +} + SettingsControl::SettingsControl(QWidget *pr) : QWidget(pr) { @@ -139,6 +156,17 @@ void SettingsControl::paintEvent(QPaintEvent *pe) } } +void SettingsControl::updateWidgetVisibility(bool showAdvanced) +{ + if (advanced()) { + setVisible(m_localVisible & showAdvanced); + } else if (property("simple").toBool()) { + setVisible(m_localVisible & !showAdvanced); + } else { + setVisible(m_localVisible); + } +} + ///////////////////////////////////////////////////////////////////////////////// SettingsCheckbox::SettingsCheckbox(QWidget* parent) : diff --git a/src/GUI/SettingsWidgets.hxx b/src/GUI/SettingsWidgets.hxx index 8c7e8d558..3731ae6ba 100644 --- a/src/GUI/SettingsWidgets.hxx +++ b/src/GUI/SettingsWidgets.hxx @@ -24,6 +24,9 @@ class SettingsControl : public QWidget Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) Q_PROPERTY(QStringList keywords READ keywords WRITE setKeywords NOTIFY keywordsChanged) Q_PROPERTY(QString option READ option WRITE setOption NOTIFY optionChanged) + + Q_PROPERTY(bool visible READ qmlVisible WRITE setQmlVisible NOTIFY qmlVisibleChanged) + public: bool advanced() const @@ -49,6 +52,9 @@ public: * @return - if this control matched the search term or not */ bool setSearchTerm(QString search); + bool qmlVisible() const; + + void updateWidgetVisibility(bool showAdvanced); public slots: void setAdvanced(bool advanced); @@ -61,6 +67,8 @@ public slots: void setOption(QString option); + void setQmlVisible(bool visible); + signals: void advancedChanged(bool advanced); void labelChanged(); @@ -68,6 +76,8 @@ signals: void keywordsChanged(QStringList keywords); void optionChanged(QString option); + void qmlVisibleChanged(bool visible); + protected: SettingsControl(QWidget* pr = nullptr); @@ -78,10 +88,13 @@ protected: QLabel* m_description = nullptr; void paintEvent(QPaintEvent* pe) override; + + void updateWidgetVisibility(); private: bool m_advanced = false; QStringList m_keywords; QString m_option; + bool m_localVisible = true; }; class SettingsCheckbox : public SettingsControl