comparison main/PreferencesDialog.cpp @ 163:652b22dcd4ed

* Add mouse actions to key and mouse reference dialog * Use QDialogButtonBox in all dialogs, for proper button ordering across platforms (requires Qt 4.2) * Fix #1733610 program does not exit if preferences dialog visible on close
author Chris Cannam
date Thu, 05 Jul 2007 11:07:01 +0000
parents c9930ec7a3f9
children 98ba77e0d897
comparison
equal deleted inserted replaced
162:9c9bce6440f5 163:652b22dcd4ed
22 #include <QDoubleSpinBox> 22 #include <QDoubleSpinBox>
23 #include <QLabel> 23 #include <QLabel>
24 #include <QPushButton> 24 #include <QPushButton>
25 #include <QHBoxLayout> 25 #include <QHBoxLayout>
26 #include <QString> 26 #include <QString>
27 #include <QDialogButtonBox>
28 #include <QMessageBox>
27 29
28 #include "widgets/WindowTypeSelector.h" 30 #include "widgets/WindowTypeSelector.h"
29 #include "base/Preferences.h" 31 #include "base/Preferences.h"
30 32
31 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) : 33 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
32 QDialog(parent, flags) 34 QDialog(parent, flags)
33 { 35 {
34 setWindowTitle(tr("Application Preferences")); 36 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
35 37
36 Preferences *prefs = Preferences::getInstance(); 38 Preferences *prefs = Preferences::getInstance();
37 39
38 QGridLayout *grid = new QGridLayout; 40 QGridLayout *grid = new QGridLayout;
39 setLayout(grid); 41 setLayout(grid);
40 42
41 QGroupBox *groupBox = new QGroupBox; 43 QGroupBox *groupBox = new QGroupBox;
42 groupBox->setTitle(tr("Sonic Visualiser Application Preferences")); 44 groupBox->setTitle(tr("Application Preferences"));
43 grid->addWidget(groupBox, 0, 0); 45 grid->addWidget(groupBox, 0, 0);
44 46
45 QGridLayout *subgrid = new QGridLayout; 47 QGridLayout *subgrid = new QGridLayout;
46 groupBox->setLayout(subgrid); 48 groupBox->setLayout(subgrid);
47 49
142 row, 0); 144 row, 0);
143 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2); 145 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
144 subgrid->setRowStretch(row, 10); 146 subgrid->setRowStretch(row, 10);
145 row++; 147 row++;
146 148
147 QHBoxLayout *hbox = new QHBoxLayout; 149 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
148 grid->addLayout(hbox, 1, 0); 150 grid->addWidget(bb, 1, 0);
149 151
150 QPushButton *ok = new QPushButton(tr("OK")); 152 QPushButton *ok = new QPushButton(tr("OK"));
151 QPushButton *cancel = new QPushButton(tr("Cancel")); 153 QPushButton *cancel = new QPushButton(tr("Cancel"));
152 hbox->addStretch(10); 154 bb->addButton(ok, QDialogButtonBox::AcceptRole);
153 hbox->addWidget(ok); 155 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
154 hbox->addWidget(m_applyButton); 156 bb->addButton(cancel, QDialogButtonBox::RejectRole);
155 hbox->addWidget(cancel);
156 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked())); 157 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
157 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked())); 158 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
158 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); 159 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
159 160
160 m_applyButton->setEnabled(false); 161 m_applyButton->setEnabled(false);
225 PreferencesDialog::cancelClicked() 226 PreferencesDialog::cancelClicked()
226 { 227 {
227 reject(); 228 reject();
228 } 229 }
229 230
231 void
232 PreferencesDialog::applicationClosing(bool quickly)
233 {
234 if (quickly) {
235 reject();
236 return;
237 }
238
239 if (m_applyButton->isEnabled()) {
240 int rv = QMessageBox::warning
241 (this, tr("Preferences Changed"),
242 tr("Some preferences have been changed but not applied.\n"
243 "Apply them before closing?"),
244 QMessageBox::Apply | QMessageBox::Discard,
245 QMessageBox::Discard);
246 if (rv == QMessageBox::Apply) {
247 applyClicked();
248 accept();
249 } else {
250 reject();
251 }
252 } else {
253 accept();
254 }
255 }
256