X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fsettingspage.cpp;h=78660f93f17514895b10dec5772ce9ee0b8fa3a1;hp=cee72a202a837d3831feec08a30b7ed29155b5a1;hb=09e81c4d2ef4ae577a0e9290a976877d9734970e;hpb=61e73ddfdd22418890102c44166483ddb28e1c93 diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index cee72a20..78660f93 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -25,15 +25,14 @@ #include #include -#include - #include "uisettings.h" SettingsPage::SettingsPage(const QString &category, const QString &title, QWidget *parent) : QWidget(parent), _category(category), _title(title), - _changed(false) + _changed(false), + _autoWidgetsChanged(false) { } @@ -52,7 +51,7 @@ void SettingsPage::load(QCheckBox *box, bool checked) { } bool SettingsPage::hasChanged(QCheckBox *box) { - return box->property("StoredValue").toBool() == box->isChecked(); + return box->property("StoredValue").toBool() != box->isChecked(); } @@ -62,7 +61,7 @@ void SettingsPage::load(QComboBox *box, int index) { } 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) { @@ -71,7 +70,7 @@ void SettingsPage::load(QSpinBox *box, int value) { } bool SettingsPage::hasChanged(QSpinBox *box) { - return box->property("StoredValue").toInt() == box->value(); + return box->property("StoredValue").toInt() != box->value(); } /*** Auto child widget handling ***/ @@ -79,15 +78,14 @@ bool SettingsPage::hasChanged(QSpinBox *box) { void SettingsPage::initAutoWidgets() { _autoWidgets.clear(); - if(settingsKey().isNull()) - return; - // 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("QAbstractButton")) + 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())); @@ -95,6 +93,8 @@ void SettingsPage::initAutoWidgets() { 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(); } @@ -102,7 +102,7 @@ void SettingsPage::initAutoWidgets() { void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const { foreach(QObject *child, parent->children()) { - if(!child->property("settingsKey").toString().isEmpty()) + if(child->property("settingsKey").isValid()) autoList->append(child); findAutoWidgets(child, autoList); } @@ -110,7 +110,9 @@ void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { QByteArray prop; - if(widget->inherits("QAbstractButton")) + if(widget->inherits("ColorButton")) + prop = "color"; + else if(widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) prop = "checked"; else if(widget->inherits("QLineEdit") || widget->inherits("QTextEdit")) prop = "text"; @@ -118,6 +120,8 @@ QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { prop = "currentIndex"; else if(widget->inherits("QSpinBox")) prop = "value"; + else if(widget->inherits("FontSelector")) + prop = "selectedFont"; else qWarning() << "SettingsPage::autoWidgetPropertyName(): Unhandled widget type for" << widget; @@ -126,6 +130,8 @@ QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { QString SettingsPage::autoWidgetSettingsKey(QObject *widget) const { QString key = widget->property("settingsKey").toString(); + if(key.isEmpty()) + return QString(""); if(key.startsWith('/')) key.remove(0, 1); else @@ -157,7 +163,14 @@ void SettingsPage::autoWidgetHasChanged() { void SettingsPage::load() { UiSettings s(""); foreach(QObject *widget, _autoWidgets) { - QVariant val = s.value(autoWidgetSettingsKey(widget), widget->property("defaultValue")); + QString key = autoWidgetSettingsKey(widget); + QVariant val; + if(key.isEmpty()) + val = loadAutoWidgetValue(widget->objectName()); + else + val = s.value(key, QVariant()); + if(!val.isValid()) + val = widget->property("defaultValue"); widget->setProperty(autoWidgetPropertyName(widget), val); widget->setProperty("storedValue", val); } @@ -170,9 +183,13 @@ void SettingsPage::load() { void SettingsPage::save() { UiSettings s(""); foreach(QObject *widget, _autoWidgets) { + QString key = autoWidgetSettingsKey(widget); QVariant val = widget->property(autoWidgetPropertyName(widget)); widget->setProperty("storedValue", val); - s.setValue(autoWidgetSettingsKey(widget), val); + if(key.isEmpty()) + saveAutoWidgetValue(widget->objectName(), val); + else + s.setValue(key, val); } bool old = hasChanged(); _autoWidgetsChanged = _changed = false; @@ -187,3 +204,13 @@ void SettingsPage::defaults() { } autoWidgetHasChanged(); } + +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 &) { + qWarning() << "Could not save value for SettingsPage widget" << widgetName; +} +