diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-03 05:58:50 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-06-03 06:02:05 +0900 |
commit | 77c4b8ef87fcbf0fd6be7cdd7581035bb96f0b58 (patch) | |
tree | 4afb1d460070341c68c68f5eeb239f4abf5627ec | |
parent | de8395e09e0e6c6ada06dbd3d5e6a053fd821a71 (diff) | |
download | subsurface-77c4b8ef87fcbf0fd6be7cdd7581035bb96f0b58.tar.gz |
Implement Apply / Close without Saving for preferences
This hooks up the buttons correctly
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/preferences.cpp | 42 | ||||
-rw-r--r-- | qt-ui/preferences.h | 8 |
2 files changed, 42 insertions, 8 deletions
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index 551d7965a..7e2f5c999 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -13,12 +13,22 @@ PreferencesDialog* PreferencesDialog::instance() #define D(V, P) s.value(#V, default_prefs.P).toDouble() #define I(V, P) s.value(#V, default_prefs.P).toInt() -PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) -, ui(new Ui::PreferencesDialog()) +PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f), + ui(new Ui::PreferencesDialog()) { ui->setupUi(this); - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(syncSettings())); - connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(resetSettings())); + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + reloadPrefs(); +} + +void PreferencesDialog::showEvent(QShowEvent *event) +{ + reloadPrefs(); + QDialog::showEvent(event); +} + +void PreferencesDialog::reloadPrefs() +{ oldPrefs = prefs; @@ -140,8 +150,30 @@ void PreferencesDialog::syncSettings() s.endGroup(); s.sync(); - oldPrefs = prefs; emit settingsChanged(); } +void PreferencesDialog::buttonClicked(QAbstractButton* button) +{ + switch(ui->buttonBox->standardButton(button)){ + case QDialogButtonBox::Discard: + prefs = oldPrefs; + close(); + break; + case QDialogButtonBox::Apply: + syncSettings(); + emit settingsChanged(); + break; + case QDialogButtonBox::FirstButton: + syncSettings(); + oldPrefs = prefs; + emit settingsChanged(); + close(); + break; + default: + break; // ignore warnings. + } +} + + #undef SB diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h index 34fc26b07..f50c05c1b 100644 --- a/qt-ui/preferences.h +++ b/qt-ui/preferences.h @@ -6,23 +6,25 @@ #include "../pref.h" namespace Ui{ - class PreferencesDialog; +class PreferencesDialog; } +class QAbstractButton; class PreferencesDialog :public QDialog{ Q_OBJECT public: static PreferencesDialog* instance(); - + void showEvent(QShowEvent* ); signals: void settingsChanged(); - public slots: + void buttonClicked(QAbstractButton* button); void syncSettings(); void resetSettings(); private: explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); + void reloadPrefs(); Ui::PreferencesDialog* ui; struct preferences oldPrefs; }; |