]>
Commit | Line | Data |
---|---|---|
0fd01780 | 1 | #include "optionsdialog.h" |
92f20d53 | 2 | #include "optionsmodel.h" |
0fd01780 | 3 | #include "mainoptionspage.h" |
df577886 WL |
4 | |
5 | #include <QHBoxLayout> | |
6 | #include <QVBoxLayout> | |
7 | #include <QPushButton> | |
4d1bb15e WL |
8 | #include <QListWidget> |
9 | #include <QStackedWidget> | |
92f20d53 | 10 | #include <QDataWidgetMapper> |
c6dd35f0 | 11 | #include <QDebug> |
df577886 | 12 | |
92f20d53 WL |
13 | OptionsDialog::OptionsDialog(QWidget *parent): |
14 | QDialog(parent), contents_widget(0), pages_widget(0), | |
15 | main_options_page(0), model(0) | |
df577886 WL |
16 | { |
17 | contents_widget = new QListWidget(); | |
18 | contents_widget->setMaximumWidth(128); | |
19 | ||
20 | pages_widget = new QStackedWidget(); | |
21 | pages_widget->setMinimumWidth(300); | |
22 | ||
23 | QListWidgetItem *item_main = new QListWidgetItem(tr("Main")); | |
24 | contents_widget->addItem(item_main); | |
92f20d53 WL |
25 | main_options_page = new MainOptionsPage(this); |
26 | pages_widget->addWidget(main_options_page); | |
df577886 WL |
27 | |
28 | contents_widget->setCurrentRow(0); | |
29 | ||
30 | QHBoxLayout *main_layout = new QHBoxLayout(); | |
31 | main_layout->addWidget(contents_widget); | |
32 | main_layout->addWidget(pages_widget, 1); | |
33 | ||
34 | QVBoxLayout *layout = new QVBoxLayout(); | |
35 | layout->addLayout(main_layout); | |
36 | ||
37 | QHBoxLayout *buttons = new QHBoxLayout(); | |
38 | buttons->addStretch(1); | |
39 | QPushButton *ok_button = new QPushButton(tr("OK")); | |
40 | buttons->addWidget(ok_button); | |
41 | QPushButton *cancel_button = new QPushButton(tr("Cancel")); | |
42 | buttons->addWidget(cancel_button); | |
c6dd35f0 WL |
43 | apply_button = new QPushButton(tr("Apply")); |
44 | apply_button->setEnabled(false); | |
df577886 WL |
45 | buttons->addWidget(apply_button); |
46 | ||
47 | layout->addLayout(buttons); | |
48 | ||
df577886 WL |
49 | setLayout(layout); |
50 | setWindowTitle(tr("Options")); | |
51 | ||
c6dd35f0 | 52 | /* Widget-to-option mapper */ |
92f20d53 WL |
53 | mapper = new QDataWidgetMapper(); |
54 | mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); | |
55 | mapper->setOrientation(Qt::Vertical); | |
c6dd35f0 WL |
56 | connect(mapper->itemDelegate(), SIGNAL(commitData(QWidget*)), this, SLOT(enableApply())); |
57 | ||
58 | /* Event bindings */ | |
59 | connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked())); | |
60 | connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked())); | |
61 | connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked())); | |
92f20d53 WL |
62 | } |
63 | ||
64 | void OptionsDialog::setModel(OptionsModel *model) | |
65 | { | |
66 | this->model = model; | |
67 | ||
68 | mapper->setModel(model); | |
69 | main_options_page->setMapper(mapper); | |
df577886 | 70 | |
92f20d53 | 71 | mapper->toFirst(); |
df577886 WL |
72 | } |
73 | ||
74 | void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) | |
75 | { | |
76 | Q_UNUSED(previous); | |
77 | if(current) | |
78 | { | |
79 | pages_widget->setCurrentIndex(contents_widget->row(current)); | |
80 | } | |
81 | } | |
c6dd35f0 WL |
82 | |
83 | void OptionsDialog::okClicked() | |
84 | { | |
85 | mapper->submit(); | |
86 | accept(); | |
87 | } | |
88 | ||
89 | void OptionsDialog::cancelClicked() | |
90 | { | |
91 | reject(); | |
92 | } | |
93 | ||
94 | void OptionsDialog::applyClicked() | |
95 | { | |
96 | mapper->submit(); | |
97 | apply_button->setEnabled(false); | |
98 | } | |
99 | ||
100 | void OptionsDialog::enableApply() | |
101 | { | |
102 | apply_button->setEnabled(true); | |
103 | } |