18 #include <QHBoxLayout>
19 #include <QHeaderView>
20 #include <QMessageBox>
21 #include <QPushButton>
22 #include <QScrollArea>
24 #include <QVBoxLayout>
38 mSectionMap[sectionName].append(widget);
57 for (
auto it = mSectionMap.begin(); it != mSectionMap.end(); ++it)
59 auto jt = it->begin();
60 while (jt != it->end())
77 for (
auto it = mSectionMap.constBegin(); it != mSectionMap.constEnd(); ++it)
78 if (it.value().isEmpty())
91 mSearchbarContainer =
new QFrame(
this);
93 mSearchbar =
new Searchbar(mSearchbarContainer);
101 mLayout->
addWidget(mExpandingListWidget);
107 mVerticalLayout->
addWidget(mSearchbarContainer);
110 mSearchbarContainer->
setLayout(mSearchbarLayout);
134 mSettingsContainer->
setLayout(mContainerLayout);
136 mContentLayout->
addWidget(mSettingsContainer);
143 mVerticalLayout->
addWidget(mDescriptionText);
145 mVerticalLayout->
addLayout(mButtonLayout);
147 mRestoreDefaults->
setText(
"Restore default values for all settings");
148 mRestoreDefaults->
setToolTip(
"Clear user preferences for this page");
171 void MainSettingsWidget::initWidgets()
175 QSet<QString> registeredCategories = QtCompat::listToSet<QString>(mSectionNames.values());
182 if (catg.
isEmpty()) catg =
"Other";
183 if (!registeredCategories.
contains(catg))
186 registeredCategories.
insert(catg);
189 SettingsWidget* widget = si->editWidget();
193 registeredItems.
insert(si);
198 for (ExpandingListButton* btn : mSectionNames.keys())
202 for (
auto it = mSectionNames.begin(); it!= mSectionNames.end(); ++it)
203 if (it.value() == sectionName)
208 void MainSettingsWidget::makeSection(
const QString& label)
210 int colon = label.
indexOf(
':');
218 topLabel = label.
left(colon);
219 subLabel = label.
mid(colon+1);
220 if (!mExpandingListWidget->
hasGroup(topLabel))
222 ExpandingListButton* topBtn =
new ExpandingListButton(0);
223 topBtn->setObjectName(topLabel);
224 topBtn->setText(topLabel);
225 topBtn->setDefaultIcon(topLabel);
227 mSectionNames.insert(topBtn,topLabel);
231 ExpandingListButton* btn =
new ExpandingListButton(level);
232 btn->setObjectName(subLabel);
233 btn->setText(subLabel);
234 btn->setDefaultIcon(subLabel);
236 mExpandingListWidget->
appendItem(btn,topLabel);
237 mSectionNames.insert(btn, label);
263 return saveSettings();
274 widget->handleSetDefaultValue(
true);
301 widget->loadCurrentValue();
307 if (!activeSettingsItem)
309 mDescriptionText->
clear();
312 QString html =
QString(
"<html><body><h3>%1</h3><p>%2</p></body></html>")
314 mDescriptionText->
setHtml(html);
319 mResetToFirstElement =
false;
320 mResetToFirstElement =
true;
327 QString sectionName = mSectionNames.value(button);
328 mActiveSection = sectionName;
338 void MainSettingsWidget::hideAllSettings()
347 but->setSelected(
false);
354 mSearchOptions = searchOpts;
355 mActiveSection.
clear();
356 if (mExpandingListWidget)
359 but->setSelected(
false);
364 mActiveSection = widget->settingsItem()->label();
371 bool MainSettingsWidget::saveSettings()
373 bool changed =
false;
379 widget->acceptValue();
403 return regEx.match(stringToCheck).hasMatch();
static AssignedKeybindMap * instance()
QList< SettingsWidget * > section(const QString &s) const
void registerWidget(const QString §ionName, SettingsWidget *widget)
QList< const SettingsItem * > getItems() const
QStringList emptySections() const
void unregisterWidget(SettingsWidget *widget)
void handleCancelClicked()
MainSettingsWidget(QWidget *parent=nullptr)
bool handleAboutToClose()
void searchSettings(const QString &needle, SearchOptions searchOpts)
void handleButtonSelected(ExpandingListButton *button)
void handleDescriptionUpdate(SettingsItem *activeSettingsItem)
bool isMatching(QString searchString, QString stringToCheck)
void handleWidgetRemove(SettingsWidget *widget)
void handleRestoreDefaultsClicked()
bool isExactMatch() const
bool isCaseSensitive() const
bool isRegularExpression() const
A QFrame with a QLineEdit that can be used to input a substring to search for.
void triggerNewSearch(const QString &text, int searchOptions)
The interface for the logical part of a setting.
virtual QString label() const
virtual QString description() const
void persistUserSettings()
static SettingsManager * instance()
void setText(const QString &text)
void addLayout(QLayout *layout, int stretch)
void setSpacing(int spacing)
void setFrameStyle(int style)
bool setAlignment(QWidget *w, Qt::Alignment alignment)
void setContentsMargins(int left, int top, int right, int bottom)
void append(const T &value)
int removeAll(const T &value)
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setObjectName(const QString &name)
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
int compare(const QString &other, Qt::CaseSensitivity cs) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(int n) const const
QString mid(int position, int n) const const
void setHtml(const QString &text)