1
0
Fork 0

Settings searching support.

Also tightened up the layouts.
This commit is contained in:
James Turner 2017-04-08 11:21:51 +09:00
parent 3732930269
commit 427f662dca
11 changed files with 157 additions and 63 deletions

View file

@ -10,7 +10,7 @@ Section {
description: "FlightGear can automatically download scenery as needed, and check for updates to " 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 " + "the scenery. If you disable this option, you will need to download & install scenery "
+ "using an alternative method." + "using an alternative method."
keywords: ["terrasync", "download"] keywords: ["terrasync", "download", "scenery"]
option: "terrasync" option: "terrasync"
} }
@ -27,6 +27,8 @@ Section {
defaultPath: _config.defaultDownloadDir defaultPath: _config.defaultDownloadDir
option: "download-dir" option: "download-dir"
dialogPrompt: "Choose a location to store download files." dialogPrompt: "Choose a location to store download files."
keywords: ["download", "storage", "disk"]
} }
onApply: { onApply: {

View file

@ -311,8 +311,8 @@ void LauncherMainWindow::buildSettingsSections()
settingsVBox->addWidget(m_extraSettings); settingsVBox->addWidget(m_extraSettings);
settingsVBox->addStretch(1); settingsVBox->addStretch(1);
// disable search for the moment, not implemented connect(m_ui->settingsSearchEdit, &QLineEdit::textChanged,
m_ui->settingsSearchEdit->hide(); this, &LauncherMainWindow::onSettingsSearchChanged);
} }
void LauncherMainWindow::buildEnvironmentSections() void LauncherMainWindow::buildEnvironmentSections()
@ -1089,3 +1089,10 @@ void LauncherMainWindow::onChangeDataDir()
flightgear::restartTheApp(); flightgear::restartTheApp();
} }
void LauncherMainWindow::onSettingsSearchChanged()
{
Q_FOREACH(SettingsSectionQML* ss, findChildren<SettingsSectionQML*>()) {
ss->setSearchTerm(m_ui->settingsSearchEdit->text());
}
}

View file

@ -108,6 +108,8 @@ private slots:
void onAircraftPathsChanged(); void onAircraftPathsChanged();
void onChangeDataDir(); void onChangeDataDir();
void onSettingsSearchChanged();
private: private:
/** /**

View file

@ -12,7 +12,7 @@ Section {
description: "Flightgear supporters maintain a network of server to enable global multi-user " 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 " + "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." + "will be visible to other users online, and you will see their aircraft."
keywords: ["network", "mp"] keywords: ["network", "mp", "multiplay","online"]
} }
LineEdit { LineEdit {
@ -23,6 +23,7 @@ Section {
"how ATC services and other pilots will refer to you. " + "how ATC services and other pilots will refer to you. " +
"(Maximum of ten charatcers permitted)" "(Maximum of ten charatcers permitted)"
placeholder: "D-FGFS" placeholder: "D-FGFS"
keywords: ["callsign", "handle", "name"]
} }
Combo { Combo {
@ -33,6 +34,8 @@ Section {
model: _mpServers model: _mpServers
readonly property bool currentIsCustom: (model.serverForIndex(selectedIndex) == "__custom__") readonly property bool currentIsCustom: (model.serverForIndex(selectedIndex) == "__custom__")
keywords: ["server", "hostname"]
} }
Connections Connections

View file

@ -23,6 +23,8 @@ Section {
"effects and more. However, not all aircraft appear correctly and performance will " + "effects and more. However, not all aircraft appear correctly and performance will " +
"depend greatly on your system hardware." "depend greatly on your system hardware."
] ]
keywords: ["als", "rembrandt", "render", "shadow"]
} }
Combo { Combo {
@ -31,7 +33,7 @@ Section {
description: "Anti-aliasing improves the appearance of high-contrast edges and lines." + description: "Anti-aliasing improves the appearance of high-contrast edges and lines." +
"This is especially noticeable on sloping or diagonal egdes. " + "This is especially noticeable on sloping or diagonal egdes. " +
"Higher settings can reduce performance." "Higher settings can reduce performance."
keywords: ["msaa"] keywords: ["msaa", "anti", "aliasing", "multi", "sample"]
choices: ["Off", "2x", "4x"] choices: ["Off", "2x", "4x"]
enabled: !rembrandt enabled: !rembrandt
property var data: [0, 2, 4]; property var data: [0, 2, 4];

View file

@ -17,13 +17,14 @@ SettingsSectionQML::SettingsSectionQML()
void SettingsSectionQML::internalUpdateAdvanced() void SettingsSectionQML::internalUpdateAdvanced()
{ {
const bool showAdvanced = m_showAdvanced | m_forceShowAdvanced;
Q_FOREACH (SettingsControl* w, controls()) { Q_FOREACH (SettingsControl* w, controls()) {
if (w->advanced()) { if (w->advanced()) {
w->setVisible(m_showAdvanced); w->setVisible(showAdvanced);
} }
if (w->property("simple").toBool()) { 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 qmlSummaryChanged(summary);
emit summaryChanged(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();
}

View file

@ -36,6 +36,7 @@ public:
public slots: public slots:
void setSummary(QString summary); void setSummary(QString summary);
void setSearchTerm(QString search);
signals: signals:
void controlsChanged(); void controlsChanged();
@ -63,6 +64,7 @@ private:
void updateShowAdvanced() override; void updateShowAdvanced() override;
QString m_summary; QString m_summary;
QObjectList m_controls; QObjectList m_controls;
bool m_forceShowAdvanced; ///< overrides show-advanced when searching
}; };
#endif // SETTINGSSECTIONQML_HXX #endif // SETTINGSSECTIONQML_HXX

View file

@ -14,64 +14,13 @@
#include <QQmlEngine> #include <QQmlEngine>
#include <QQmlContext> #include <QQmlContext>
#include <QDateTimeEdit> #include <QDateTimeEdit>
#include <QPainter>
#include "LaunchConfig.hxx" #include "LaunchConfig.hxx"
SettingsCheckbox::SettingsCheckbox(QWidget* parent) : const int MARGIN_HINT = 4;
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);
}
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 QString SettingsControl::label() const
{ {
@ -97,6 +46,24 @@ QString SettingsControl::option() const
return m_option; 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) void SettingsControl::setAdvanced(bool advanced)
{ {
if (m_advanced == advanced) if (m_advanced == advanced)
@ -158,13 +125,91 @@ QString SettingsControl::qmlName() const
return s; 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) : SettingsComboBox::SettingsComboBox(QWidget *pr) :
SettingsControl(pr) SettingsControl(pr)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
setLayout(vbox); setLayout(vbox);
vbox->setMargin(MARGIN_HINT);
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(MARGIN_HINT);
vbox->addLayout(hbox); vbox->addLayout(hbox);
m_combo = new QComboBox(this); m_combo = new QComboBox(this);
@ -274,9 +319,12 @@ SettingsIntSpinbox::SettingsIntSpinbox(QWidget *pr) :
SettingsControl(pr) SettingsControl(pr)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->setMargin(MARGIN_HINT);
setLayout(vbox); setLayout(vbox);
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(MARGIN_HINT);
vbox->addLayout(hbox); vbox->addLayout(hbox);
m_spin = new QSpinBox(this); m_spin = new QSpinBox(this);
@ -362,9 +410,11 @@ SettingsText::SettingsText(QWidget *pr) :
SettingsControl(pr) SettingsControl(pr)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->setMargin(MARGIN_HINT);
setLayout(vbox); setLayout(vbox);
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(MARGIN_HINT);
vbox->addLayout(hbox); vbox->addLayout(hbox);
m_edit = new QLineEdit(this); m_edit = new QLineEdit(this);
@ -442,9 +492,11 @@ SettingsPath::SettingsPath(QWidget *pr) :
SettingsControl(pr) SettingsControl(pr)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->setMargin(MARGIN_HINT);
setLayout(vbox); setLayout(vbox);
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(MARGIN_HINT);
vbox->addLayout(hbox); vbox->addLayout(hbox);
m_changeButton = new QPushButton(tr("Change"), this); m_changeButton = new QPushButton(tr("Change"), this);
@ -581,9 +633,11 @@ SettingsDateTime::SettingsDateTime(QWidget *pr) :
SettingsControl(pr) SettingsControl(pr)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->setMargin(MARGIN_HINT);
setLayout(vbox); setLayout(vbox);
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(MARGIN_HINT);
vbox->addLayout(hbox); vbox->addLayout(hbox);
m_edit = new QDateTimeEdit; m_edit = new QDateTimeEdit;

View file

@ -42,7 +42,13 @@ public:
virtual void restoreState(QSettings& settings) = 0; 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: public slots:
void setAdvanced(bool advanced); void setAdvanced(bool advanced);
@ -70,6 +76,8 @@ protected:
QString qmlName() const; QString qmlName() const;
QLabel* m_description = nullptr; QLabel* m_description = nullptr;
void paintEvent(QPaintEvent* pe) override;
private: private:
bool m_advanced = false; bool m_advanced = false;
QStringList m_keywords; QStringList m_keywords;

View file

@ -8,7 +8,7 @@ Section {
id: fullscreen id: fullscreen
label: "Start full-screen" label: "Start full-screen"
description: "Start the simulator in full-screen mode" description: "Start the simulator in full-screen mode"
keywords: ["window", "full", "screen"] keywords: ["window", "full", "screen", "maximize"]
option: "fullscreen" option: "fullscreen"
} }
@ -21,6 +21,8 @@ Section {
choices: ["640x480", "800x600", "1024x768", "1920x1080", "2560x1600" ] choices: ["640x480", "800x600", "1024x768", "1920x1080", "2560x1600" ]
defaultIndex: 2 defaultIndex: 2
readonly property bool isDefault: selectedIndex == defaultIndex readonly property bool isDefault: selectedIndex == defaultIndex
keywords: ["window", "geometry", "size", "resolution"]
} }
onApply: { onApply: {

View file

@ -28,6 +28,7 @@ SettingsSection::SettingsSection(QWidget* pr) :
if (!layout()) { if (!layout()) {
QVBoxLayout* vbox = new QVBoxLayout(this); QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->setMargin(4);
setLayout(vbox); setLayout(vbox);
} }
} }