diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-01 09:33:48 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-01 17:15:42 +0200 |
commit | c6dd35f03dd58a5712d38a3ce535723cdf0ffb30 (patch) | |
tree | 00aaee2985dd38a4647210dedbb8a3ec06ba907f /gui | |
parent | 968d55aafa20b1da7b245f3116370e3fa6c17e5c (diff) |
Apply button
Diffstat (limited to 'gui')
-rw-r--r-- | gui/include/optionsdialog.h | 7 | ||||
-rw-r--r-- | gui/src/optionsdialog.cpp | 33 |
2 files changed, 39 insertions, 1 deletions
diff --git a/gui/include/optionsdialog.h b/gui/include/optionsdialog.h index c064b0a93c..ff8542d41a 100644 --- a/gui/include/optionsdialog.h +++ b/gui/include/optionsdialog.h @@ -8,6 +8,7 @@ class QStackedWidget; class QListWidget; class QListWidgetItem; class QDataWidgetMapper; +class QPushButton; QT_END_NAMESPACE class OptionsModel; class MainOptionsPage; @@ -24,12 +25,18 @@ signals: public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); +private slots: + void okClicked(); + void cancelClicked(); + void applyClicked(); + void enableApply(); private: QListWidget *contents_widget; QStackedWidget *pages_widget; MainOptionsPage *main_options_page; OptionsModel *model; QDataWidgetMapper *mapper; + QPushButton *apply_button; void setupMainPage(); }; diff --git a/gui/src/optionsdialog.cpp b/gui/src/optionsdialog.cpp index e1f3d67dd7..4d0493a26e 100644 --- a/gui/src/optionsdialog.cpp +++ b/gui/src/optionsdialog.cpp @@ -8,6 +8,7 @@ #include <QListWidget> #include <QStackedWidget> #include <QDataWidgetMapper> +#include <QDebug> OptionsDialog::OptionsDialog(QWidget *parent): QDialog(parent), contents_widget(0), pages_widget(0), @@ -39,7 +40,8 @@ OptionsDialog::OptionsDialog(QWidget *parent): buttons->addWidget(ok_button); QPushButton *cancel_button = new QPushButton(tr("Cancel")); buttons->addWidget(cancel_button); - QPushButton *apply_button = new QPushButton(tr("Apply")); + apply_button = new QPushButton(tr("Apply")); + apply_button->setEnabled(false); buttons->addWidget(apply_button); layout->addLayout(buttons); @@ -47,9 +49,16 @@ OptionsDialog::OptionsDialog(QWidget *parent): setLayout(layout); setWindowTitle(tr("Options")); + /* Widget-to-option mapper */ mapper = new QDataWidgetMapper(); mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mapper->setOrientation(Qt::Vertical); + connect(mapper->itemDelegate(), SIGNAL(commitData(QWidget*)), this, SLOT(enableApply())); + + /* Event bindings */ + connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked())); + connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked())); + connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked())); } void OptionsDialog::setModel(OptionsModel *model) @@ -70,3 +79,25 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo pages_widget->setCurrentIndex(contents_widget->row(current)); } } + +void OptionsDialog::okClicked() +{ + mapper->submit(); + accept(); +} + +void OptionsDialog::cancelClicked() +{ + reject(); +} + +void OptionsDialog::applyClicked() +{ + mapper->submit(); + apply_button->setEnabled(false); +} + +void OptionsDialog::enableApply() +{ + apply_button->setEnabled(true); +} |