+#include "uisettings.h"
+
+SettingsPage::SettingsPage(const QString &category, const QString &title, QWidget *parent)
+ : QWidget(parent),
+ _category(category),
+ _title(title),
+ _changed(false),
+ _autoWidgetsChanged(false)
+{
+}
+
+
+void SettingsPage::setChangedState(bool hasChanged_)
+{
+ if (hasChanged_ != _changed) {
+ bool old = hasChanged();
+ _changed = hasChanged_;
+ if (hasChanged() != old)
+ emit changed(hasChanged());
+ }
+}
+
+
+void SettingsPage::load(QCheckBox *box, bool checked)
+{
+ box->setProperty("StoredValue", checked);
+ box->setChecked(checked);
+}
+
+
+bool SettingsPage::hasChanged(QCheckBox *box)
+{
+ return box->property("StoredValue").toBool() != box->isChecked();
+}
+
+
+void SettingsPage::load(QComboBox *box, int index)
+{
+ box->setProperty("StoredValue", index);
+ box->setCurrentIndex(index);
+}
+
+
+bool SettingsPage::hasChanged(QComboBox *box)
+{
+ return box->property("StoredValue").toInt() != box->currentIndex();
+}
+
+
+void SettingsPage::load(QSpinBox *box, int value)
+{
+ box->setProperty("StoredValue", value);
+ box->setValue(value);
+}
+
+
+bool SettingsPage::hasChanged(QSpinBox *box)
+{
+ return box->property("StoredValue").toInt() != box->value();
+}
+
+
+/*** Auto child widget handling ***/
+
+void SettingsPage::initAutoWidgets()
+{
+ _autoWidgets.clear();
+
+ // find all descendants that should be considered auto widgets
+ // 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();
+ }