X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fsettingspage.cpp;h=fd7f6e84ae489d2bc71c498453603898c4cb6397;hp=e5792b63bd0db14c3a956fa7f05b047050f55b5f;hb=HEAD;hpb=76db8cdfbeffaaba359c8e80cf2146da9e9e7f8a diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index e5792b63..fd7f6e84 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,22 +20,24 @@ #include "settingspage.h" +#include + #include #include #include #include +#include "fontselector.h" #include "uisettings.h" +#include "widgethelpers.h" -SettingsPage::SettingsPage(const QString &category, const QString &title, QWidget *parent) - : QWidget(parent), - _category(category), - _title(title), - _changed(false), - _autoWidgetsChanged(false) -{ -} - +SettingsPage::SettingsPage(QString category, QString title, QWidget* parent) + : QWidget(parent) + , _category(std::move(category)) + , _title(std::move(title)) + , _changed(false) + , _autoWidgetsChanged(false) +{} void SettingsPage::setChangedState(bool hasChanged_) { @@ -47,45 +49,49 @@ void SettingsPage::setChangedState(bool hasChanged_) } } - -void SettingsPage::load(QCheckBox *box, bool checked) +void SettingsPage::load(QCheckBox* box, bool checked) { - box->setProperty("StoredValue", checked); + box->setProperty("storedValue", checked); box->setChecked(checked); } - -bool SettingsPage::hasChanged(QCheckBox *box) +bool SettingsPage::hasChanged(QCheckBox* box) { - return box->property("StoredValue").toBool() != box->isChecked(); + return box->property("storedValue").toBool() != box->isChecked(); } - -void SettingsPage::load(QComboBox *box, int index) +void SettingsPage::load(QComboBox* box, int index) { - box->setProperty("StoredValue", index); + box->setProperty("storedValue", index); box->setCurrentIndex(index); } - -bool SettingsPage::hasChanged(QComboBox *box) +bool SettingsPage::hasChanged(QComboBox* box) { - return box->property("StoredValue").toInt() != box->currentIndex(); + return box->property("storedValue").toInt() != box->currentIndex(); } - -void SettingsPage::load(QSpinBox *box, int value) +void SettingsPage::load(QSpinBox* box, int value) { - box->setProperty("StoredValue", value); + box->setProperty("storedValue", value); box->setValue(value); } +bool SettingsPage::hasChanged(QSpinBox* box) +{ + return box->property("storedValue").toInt() != box->value(); +} -bool SettingsPage::hasChanged(QSpinBox *box) +void SettingsPage::load(FontSelector* box, QFont value) { - return box->property("StoredValue").toInt() != box->value(); + box->setProperty("storedValue", value); + box->setSelectedFont(value); } +bool SettingsPage::hasChanged(FontSelector* box) +{ + return box->property("storedValue").value() != box->selectedFont(); +} /*** Auto child widget handling ***/ @@ -97,36 +103,21 @@ void SettingsPage::initAutoWidgets() // we need to climb the QObject tree recursively findAutoWidgets(this, &_autoWidgets); - foreach(QObject *widget, _autoWidgets) { - if (widget->inherits("ColorButton")) - connect(widget, SIGNAL(colorChanged(QColor)), SLOT(autoWidgetHasChanged())); - else if (widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) - connect(widget, SIGNAL(toggled(bool)), SLOT(autoWidgetHasChanged())); - else if (widget->inherits("QLineEdit") || widget->inherits("QTextEdit")) - connect(widget, SIGNAL(textChanged(const QString &)), SLOT(autoWidgetHasChanged())); - else if (widget->inherits("QComboBox")) - connect(widget, SIGNAL(currentIndexChanged(int)), SLOT(autoWidgetHasChanged())); - else if (widget->inherits("QSpinBox")) - connect(widget, SIGNAL(valueChanged(int)), SLOT(autoWidgetHasChanged())); - else if (widget->inherits("FontSelector")) - connect(widget, SIGNAL(fontChanged(QFont)), SLOT(autoWidgetHasChanged())); - else - qWarning() << "SettingsPage::init(): Unknown autoWidget type" << widget->metaObject()->className(); + if (!connectToWidgetsChangedSignals(_autoWidgets, this, &SettingsPage::autoWidgetHasChanged)) { + qWarning() << "SettingsPage::initAutoWidgets(): Unsupported auto widget type(s)!"; } } - -void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const +void SettingsPage::findAutoWidgets(QObject* parent, QObjectList* autoList) const { - foreach(QObject *child, parent->children()) { + foreach (QObject* child, parent->children()) { if (child->property("settingsKey").isValid()) autoList->append(child); findAutoWidgets(child, autoList); } } - -QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const +QByteArray SettingsPage::autoWidgetPropertyName(QObject* widget) const { QByteArray prop; if (widget->inherits("ColorButton")) @@ -147,8 +138,7 @@ QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const return prop; } - -QString SettingsPage::autoWidgetSettingsKey(QObject *widget) const +QString SettingsPage::autoWidgetSettingsKey(QObject* widget) const { QString key = widget->property("settingsKey").toString(); if (key.isEmpty()) @@ -160,11 +150,10 @@ QString SettingsPage::autoWidgetSettingsKey(QObject *widget) const return key; } - void SettingsPage::autoWidgetHasChanged() { bool changed_ = false; - foreach(QObject *widget, _autoWidgets) { + foreach (QObject* widget, _autoWidgets) { QVariant curValue = widget->property(autoWidgetPropertyName(widget)); if (!curValue.isValid()) qWarning() << "SettingsPage::autoWidgetHasChanged(): Unknown property"; @@ -183,11 +172,10 @@ void SettingsPage::autoWidgetHasChanged() } } - void SettingsPage::load() { UiSettings s(""); - foreach(QObject *widget, _autoWidgets) { + foreach (QObject* widget, _autoWidgets) { QString key = autoWidgetSettingsKey(widget); QVariant val; if (key.isEmpty()) @@ -205,11 +193,10 @@ void SettingsPage::load() emit changed(hasChanged()); } - void SettingsPage::save() { UiSettings s(""); - foreach(QObject *widget, _autoWidgets) { + foreach (QObject* widget, _autoWidgets) { QString key = autoWidgetSettingsKey(widget); QVariant val = widget->property(autoWidgetPropertyName(widget)); widget->setProperty("storedValue", val); @@ -224,25 +211,22 @@ void SettingsPage::save() emit changed(hasChanged()); } - void SettingsPage::defaults() { - foreach(QObject *widget, _autoWidgets) { + foreach (QObject* widget, _autoWidgets) { QVariant val = widget->property("defaultValue"); widget->setProperty(autoWidgetPropertyName(widget), val); } autoWidgetHasChanged(); } - -QVariant SettingsPage::loadAutoWidgetValue(const QString &widgetName) +QVariant SettingsPage::loadAutoWidgetValue(const QString& widgetName) { qWarning() << "Could not load value for SettingsPage widget" << widgetName; return QVariant(); } - -void SettingsPage::saveAutoWidgetValue(const QString &widgetName, const QVariant &) +void SettingsPage::saveAutoWidgetValue(const QString& widgetName, const QVariant&) { qWarning() << "Could not save value for SettingsPage widget" << widgetName; }