diff 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
line wrap: on
line diff
--- a/main/PreferencesDialog.cpp	Wed Jul 04 17:22:12 2007 +0000
+++ b/main/PreferencesDialog.cpp	Thu Jul 05 11:07:01 2007 +0000
@@ -24,6 +24,8 @@
 #include <QPushButton>
 #include <QHBoxLayout>
 #include <QString>
+#include <QDialogButtonBox>
+#include <QMessageBox>
 
 #include "widgets/WindowTypeSelector.h"
 #include "base/Preferences.h"
@@ -31,7 +33,7 @@
 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
     QDialog(parent, flags)
 {
-    setWindowTitle(tr("Application Preferences"));
+    setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
 
     Preferences *prefs = Preferences::getInstance();
 
@@ -39,7 +41,7 @@
     setLayout(grid);
     
     QGroupBox *groupBox = new QGroupBox;
-    groupBox->setTitle(tr("Sonic Visualiser Application Preferences"));
+    groupBox->setTitle(tr("Application Preferences"));
     grid->addWidget(groupBox, 0, 0);
     
     QGridLayout *subgrid = new QGridLayout;
@@ -144,15 +146,14 @@
     subgrid->setRowStretch(row, 10);
     row++;
     
-    QHBoxLayout *hbox = new QHBoxLayout;
-    grid->addLayout(hbox, 1, 0);
+    QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
+    grid->addWidget(bb, 1, 0);
     
     QPushButton *ok = new QPushButton(tr("OK"));
     QPushButton *cancel = new QPushButton(tr("Cancel"));
-    hbox->addStretch(10);
-    hbox->addWidget(ok);
-    hbox->addWidget(m_applyButton);
-    hbox->addWidget(cancel);
+    bb->addButton(ok, QDialogButtonBox::AcceptRole);
+    bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
+    bb->addButton(cancel, QDialogButtonBox::RejectRole);
     connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
     connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
     connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
@@ -227,3 +228,29 @@
     reject();
 }
 
+void
+PreferencesDialog::applicationClosing(bool quickly)
+{
+    if (quickly) {
+        reject();
+        return;
+    }
+
+    if (m_applyButton->isEnabled()) {
+        int rv = QMessageBox::warning
+            (this, tr("Preferences Changed"),
+             tr("Some preferences have been changed but not applied.\n"
+                "Apply them before closing?"),
+             QMessageBox::Apply | QMessageBox::Discard,
+             QMessageBox::Discard);
+        if (rv == QMessageBox::Apply) {
+            applyClicked();
+            accept();
+        } else {
+            reject();
+        }
+    } else {
+        accept();
+    }
+}
+