From 427f662dca213c6793d8964dc81ee15217ee693e Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 8 Apr 2017 11:21:51 +0900 Subject: [PATCH] Settings searching support. Also tightened up the layouts. --- src/GUI/DownloadSettings.qml | 4 +- src/GUI/LauncherMainWindow.cxx | 11 ++- src/GUI/LauncherMainWindow.hxx | 2 + src/GUI/MPSettings.qml | 5 +- src/GUI/RenderSettings.qml | 4 +- src/GUI/SettingsSectionQML.cxx | 15 ++- src/GUI/SettingsSectionQML.hxx | 2 + src/GUI/SettingsWidgets.cxx | 162 ++++++++++++++++++++++----------- src/GUI/SettingsWidgets.hxx | 10 +- src/GUI/ViewSettings.qml | 4 +- src/GUI/settingssection.cpp | 1 + 11 files changed, 157 insertions(+), 63 deletions(-) diff --git a/src/GUI/DownloadSettings.qml b/src/GUI/DownloadSettings.qml index 979dfc386..8cf191db5 100644 --- a/src/GUI/DownloadSettings.qml +++ b/src/GUI/DownloadSettings.qml @@ -10,7 +10,7 @@ Section { description: "FlightGear can automatically download scenery as needed, and check for updates to " + "the scenery. If you disable this option, you will need to download & install scenery " + "using an alternative method." - keywords: ["terrasync", "download"] + keywords: ["terrasync", "download", "scenery"] option: "terrasync" } @@ -27,6 +27,8 @@ Section { defaultPath: _config.defaultDownloadDir option: "download-dir" dialogPrompt: "Choose a location to store download files." + + keywords: ["download", "storage", "disk"] } onApply: { diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx index 64687b804..ec30f6ce1 100644 --- a/src/GUI/LauncherMainWindow.cxx +++ b/src/GUI/LauncherMainWindow.cxx @@ -311,8 +311,8 @@ void LauncherMainWindow::buildSettingsSections() settingsVBox->addWidget(m_extraSettings); settingsVBox->addStretch(1); - // disable search for the moment, not implemented - m_ui->settingsSearchEdit->hide(); + connect(m_ui->settingsSearchEdit, &QLineEdit::textChanged, + this, &LauncherMainWindow::onSettingsSearchChanged); } void LauncherMainWindow::buildEnvironmentSections() @@ -1089,3 +1089,10 @@ void LauncherMainWindow::onChangeDataDir() flightgear::restartTheApp(); } +void LauncherMainWindow::onSettingsSearchChanged() +{ + Q_FOREACH(SettingsSectionQML* ss, findChildren()) { + ss->setSearchTerm(m_ui->settingsSearchEdit->text()); + } +} + diff --git a/src/GUI/LauncherMainWindow.hxx b/src/GUI/LauncherMainWindow.hxx index 9870dac54..eff15cb16 100644 --- a/src/GUI/LauncherMainWindow.hxx +++ b/src/GUI/LauncherMainWindow.hxx @@ -108,6 +108,8 @@ private slots: void onAircraftPathsChanged(); void onChangeDataDir(); + + void onSettingsSearchChanged(); private: /** diff --git a/src/GUI/MPSettings.qml b/src/GUI/MPSettings.qml index 225147cc2..6cd9b858a 100644 --- a/src/GUI/MPSettings.qml +++ b/src/GUI/MPSettings.qml @@ -12,7 +12,7 @@ Section { description: "Flightgear supporters maintain a network of server to enable global multi-user " + "flight. This requires a moderately fast Inernet connection to be usable. Your aircraft " + "will be visible to other users online, and you will see their aircraft." - keywords: ["network", "mp"] + keywords: ["network", "mp", "multiplay","online"] } LineEdit { @@ -23,6 +23,7 @@ Section { "how ATC services and other pilots will refer to you. " + "(Maximum of ten charatcers permitted)" placeholder: "D-FGFS" + keywords: ["callsign", "handle", "name"] } Combo { @@ -33,6 +34,8 @@ Section { model: _mpServers readonly property bool currentIsCustom: (model.serverForIndex(selectedIndex) == "__custom__") + + keywords: ["server", "hostname"] } Connections diff --git a/src/GUI/RenderSettings.qml b/src/GUI/RenderSettings.qml index 861d9096f..c619375e9 100644 --- a/src/GUI/RenderSettings.qml +++ b/src/GUI/RenderSettings.qml @@ -23,6 +23,8 @@ Section { "effects and more. However, not all aircraft appear correctly and performance will " + "depend greatly on your system hardware." ] + + keywords: ["als", "rembrandt", "render", "shadow"] } Combo { @@ -31,7 +33,7 @@ Section { description: "Anti-aliasing improves the appearance of high-contrast edges and lines." + "This is especially noticeable on sloping or diagonal egdes. " + "Higher settings can reduce performance." - keywords: ["msaa"] + keywords: ["msaa", "anti", "aliasing", "multi", "sample"] choices: ["Off", "2x", "4x"] enabled: !rembrandt property var data: [0, 2, 4]; diff --git a/src/GUI/SettingsSectionQML.cxx b/src/GUI/SettingsSectionQML.cxx index 429e01ef4..b852e0f1e 100644 --- a/src/GUI/SettingsSectionQML.cxx +++ b/src/GUI/SettingsSectionQML.cxx @@ -17,13 +17,14 @@ SettingsSectionQML::SettingsSectionQML() void SettingsSectionQML::internalUpdateAdvanced() { + const bool showAdvanced = m_showAdvanced | m_forceShowAdvanced; Q_FOREACH (SettingsControl* w, controls()) { if (w->advanced()) { - w->setVisible(m_showAdvanced); + w->setVisible(showAdvanced); } if (w->property("simple").toBool()) { - w->setVisible(!m_showAdvanced); + w->setVisible(!showAdvanced); } } } @@ -159,3 +160,13 @@ void SettingsSectionQML::setSummary(QString summary) emit qmlSummaryChanged(summary); emit summaryChanged(summary); } + +void SettingsSectionQML::setSearchTerm(QString search) +{ + m_forceShowAdvanced = false; + Q_FOREACH(SettingsControl* control, controls()) { + const bool matches = control->setSearchTerm(search); + m_forceShowAdvanced |= (matches && control->advanced()); + } + internalUpdateAdvanced(); +} diff --git a/src/GUI/SettingsSectionQML.hxx b/src/GUI/SettingsSectionQML.hxx index cd9c58767..900e220f6 100644 --- a/src/GUI/SettingsSectionQML.hxx +++ b/src/GUI/SettingsSectionQML.hxx @@ -36,6 +36,7 @@ public: public slots: void setSummary(QString summary); + void setSearchTerm(QString search); signals: void controlsChanged(); @@ -63,6 +64,7 @@ private: void updateShowAdvanced() override; QString m_summary; QObjectList m_controls; + bool m_forceShowAdvanced; ///< overrides show-advanced when searching }; #endif // SETTINGSSECTIONQML_HXX diff --git a/src/GUI/SettingsWidgets.cxx b/src/GUI/SettingsWidgets.cxx index 47ce6bc7c..9741c6abc 100644 --- a/src/GUI/SettingsWidgets.cxx +++ b/src/GUI/SettingsWidgets.cxx @@ -14,64 +14,13 @@ #include #include #include +#include #include "LaunchConfig.hxx" -SettingsCheckbox::SettingsCheckbox(QWidget* parent) : - SettingsControl(parent) -{ - QVBoxLayout* vbox = new QVBoxLayout(this); - setLayout(vbox); - m_check = new QCheckBox(this); - vbox->addWidget(m_check); - createDescription(); - vbox->addWidget(m_description); - connect(m_check, &QCheckBox::toggled, this, &SettingsCheckbox::checkedChanged); -} +const int MARGIN_HINT = 4; -QString SettingsCheckbox::label() const -{ - return m_check->text(); -} - -bool SettingsCheckbox::isChecked() const -{ - return m_check->isChecked(); -} - -void SettingsCheckbox::setChecked(bool checked) -{ - if (checked == isChecked()) { - return; - } - - m_check->setChecked(checked); - emit checkedChanged(checked); -} - -void SettingsCheckbox::setLabel(QString label) -{ - m_check->setText(label); -} - -void SettingsCheckbox::apply(LaunchConfig* lconfig) const -{ - if (option().isEmpty()) { - return; - } - - lconfig->setEnableDisableOption(option(), isChecked()); -} - -void SettingsCheckbox::saveState(QSettings &settings) const -{ - settings.setValue(qmlName(), isChecked()); -} - -void SettingsCheckbox::restoreState(QSettings &settings) -{ - setChecked(settings.value(qmlName(), isChecked()).toBool()); -} +///////////////////////////////////////////////////////////////////////////////// QString SettingsControl::label() const { @@ -97,6 +46,24 @@ QString SettingsControl::option() const return m_option; } +bool SettingsControl::setSearchTerm(QString search) +{ + bool inSearch = false; + // only show matches when search string is at least three characters, + // to avoid many hits when the user starts typing + if (search.length() > 2) { + Q_FOREACH(QString k, m_keywords) { + if (k.indexOf(search, 0, Qt::CaseInsensitive) >= 0) { + inSearch = true; + } + } + } + + setProperty("search-result", inSearch); + update(); + return inSearch; +} + void SettingsControl::setAdvanced(bool advanced) { if (m_advanced == advanced) @@ -158,13 +125,91 @@ QString SettingsControl::qmlName() const return s; } +void SettingsControl::paintEvent(QPaintEvent *pe) +{ + QWidget::paintEvent(pe); + + if (property("search-result").toBool()) { + QPainter painter(this); + painter.setRenderHints(QPainter::Antialiasing); + QPen pen(QColor("#7f7f7fff"), 1); + painter.setPen(pen); + painter.setBrush(QColor("#2f7f7fff")); + painter.drawRoundedRect(rect(), 8, 8); + } +} + +///////////////////////////////////////////////////////////////////////////////// + +SettingsCheckbox::SettingsCheckbox(QWidget* parent) : + SettingsControl(parent) +{ + QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(MARGIN_HINT); + setLayout(vbox); + m_check = new QCheckBox(this); + vbox->addWidget(m_check); + createDescription(); + vbox->addWidget(m_description); + connect(m_check, &QCheckBox::toggled, this, &SettingsCheckbox::checkedChanged); +} + +QString SettingsCheckbox::label() const +{ + return m_check->text(); +} + +bool SettingsCheckbox::isChecked() const +{ + return m_check->isChecked(); +} + +void SettingsCheckbox::setChecked(bool checked) +{ + if (checked == isChecked()) { + return; + } + + m_check->setChecked(checked); + emit checkedChanged(checked); +} + +void SettingsCheckbox::setLabel(QString label) +{ + m_check->setText(label); +} + +void SettingsCheckbox::apply(LaunchConfig* lconfig) const +{ + if (option().isEmpty()) { + return; + } + + lconfig->setEnableDisableOption(option(), isChecked()); +} + +void SettingsCheckbox::saveState(QSettings &settings) const +{ + settings.setValue(qmlName(), isChecked()); +} + +void SettingsCheckbox::restoreState(QSettings &settings) +{ + setChecked(settings.value(qmlName(), isChecked()).toBool()); +} + +///////////////////////////////////////////////////////////////////////////////// + SettingsComboBox::SettingsComboBox(QWidget *pr) : SettingsControl(pr) { QVBoxLayout* vbox = new QVBoxLayout(this); setLayout(vbox); + vbox->setMargin(MARGIN_HINT); QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin(MARGIN_HINT); + vbox->addLayout(hbox); m_combo = new QComboBox(this); @@ -274,9 +319,12 @@ SettingsIntSpinbox::SettingsIntSpinbox(QWidget *pr) : SettingsControl(pr) { QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(MARGIN_HINT); setLayout(vbox); QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin(MARGIN_HINT); + vbox->addLayout(hbox); m_spin = new QSpinBox(this); @@ -362,9 +410,11 @@ SettingsText::SettingsText(QWidget *pr) : SettingsControl(pr) { QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(MARGIN_HINT); setLayout(vbox); QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin(MARGIN_HINT); vbox->addLayout(hbox); m_edit = new QLineEdit(this); @@ -442,9 +492,11 @@ SettingsPath::SettingsPath(QWidget *pr) : SettingsControl(pr) { QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(MARGIN_HINT); setLayout(vbox); QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin(MARGIN_HINT); vbox->addLayout(hbox); m_changeButton = new QPushButton(tr("Change"), this); @@ -581,9 +633,11 @@ SettingsDateTime::SettingsDateTime(QWidget *pr) : SettingsControl(pr) { QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(MARGIN_HINT); setLayout(vbox); QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin(MARGIN_HINT); vbox->addLayout(hbox); m_edit = new QDateTimeEdit; diff --git a/src/GUI/SettingsWidgets.hxx b/src/GUI/SettingsWidgets.hxx index dd7876b86..8c7e8d558 100644 --- a/src/GUI/SettingsWidgets.hxx +++ b/src/GUI/SettingsWidgets.hxx @@ -42,7 +42,13 @@ public: virtual void restoreState(QSettings& settings) = 0; - + /** + * @brief setSearchTerm - update the search term and decide if this control + * should e highlighted or not. + * @param search - the text being searched + * @return - if this control matched the search term or not + */ + bool setSearchTerm(QString search); public slots: void setAdvanced(bool advanced); @@ -70,6 +76,8 @@ protected: QString qmlName() const; QLabel* m_description = nullptr; + + void paintEvent(QPaintEvent* pe) override; private: bool m_advanced = false; QStringList m_keywords; diff --git a/src/GUI/ViewSettings.qml b/src/GUI/ViewSettings.qml index 0945c3a80..21430edb1 100644 --- a/src/GUI/ViewSettings.qml +++ b/src/GUI/ViewSettings.qml @@ -8,7 +8,7 @@ Section { id: fullscreen label: "Start full-screen" description: "Start the simulator in full-screen mode" - keywords: ["window", "full", "screen"] + keywords: ["window", "full", "screen", "maximize"] option: "fullscreen" } @@ -21,6 +21,8 @@ Section { choices: ["640x480", "800x600", "1024x768", "1920x1080", "2560x1600" ] defaultIndex: 2 readonly property bool isDefault: selectedIndex == defaultIndex + keywords: ["window", "geometry", "size", "resolution"] + } onApply: { diff --git a/src/GUI/settingssection.cpp b/src/GUI/settingssection.cpp index bb3ee3454..f51728178 100644 --- a/src/GUI/settingssection.cpp +++ b/src/GUI/settingssection.cpp @@ -28,6 +28,7 @@ SettingsSection::SettingsSection(QWidget* pr) : if (!layout()) { QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(4); setLayout(vbox); } }