From: Manuel Nickschas Date: Mon, 27 Jul 2009 23:49:45 +0000 (+0200) Subject: Let SettingsPage handle FontSelector and ColorButton automatically X-Git-Tag: 0.5-rc1~120 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=7fd13d1b1d6ec454ad622bdb0eefa72d6488c5fa Let SettingsPage handle FontSelector and ColorButton automatically This means that SettingsPages can now handle both FontSelector and ColorButton automatically and don't have to worry about tracking/saving/loading them. This should save us several hundred lines of boilerplate code, and also some cute kittens. I must reiterate that Qt's property system is worth a ton of bacon. At least. --- diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index 0476f967..78660f93 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -83,7 +83,9 @@ void SettingsPage::initAutoWidgets() { findAutoWidgets(this, &_autoWidgets); foreach(QObject *widget, _autoWidgets) { - if(widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) + 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())); @@ -91,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(); } @@ -106,7 +110,9 @@ void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { QByteArray prop; - if(widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) + 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"; @@ -114,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;