changeset 21020:7ebc9f38b312

use standard message box for discarding/restoring breakpoints while saving a file * file-editor-tab.cc (save_file): use QMessageBox with additional checkbox instead of QDialog
author Torsten <ttl@justmail.de>
date Thu, 31 Dec 2015 12:01:01 +0100
parents 8a65589d1a42
children a5b99b09f8fd
files libgui/src/m-editor/file-editor-tab.cc
diffstat 1 files changed, 15 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Wed Dec 30 13:16:43 2015 -0800
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu Dec 31 12:01:01 2015 +0100
@@ -1642,46 +1642,27 @@
         restore_breakpoints = false;
       else
         {
-          QDialog* dlgBox = new QDialog ();
+          // ask user
+          QMessageBox *dlgBox = new QMessageBox (QMessageBox::Question,
+                                  tr ("Octave Editor"),
+                                  tr ("Would you like to restore adjusted breakpoints?"),
+                                  QMessageBox::Yes | QMessageBox::No, this);
 
-          QStyle *mbstyle = dlgBox->style ();
-          QIcon tmpIcon = mbstyle->standardIcon (QStyle::SP_MessageBoxQuestion,
-                                                 0, dlgBox);
-          int iconSize = mbstyle->pixelMetric(QStyle::PM_MessageBoxIconSize,
-                                              0, dlgBox);
-          QLabel *questImage = new QLabel ();
-          questImage->setPixmap (tmpIcon.pixmap (iconSize, iconSize));
-          QLabel *questText = new QLabel ("Would you like to restore adjusted breakpoints?");
-          QHBoxLayout *horizontalLayout = new QHBoxLayout;
-          horizontalLayout->addWidget (questImage);
-          horizontalLayout->addWidget (questText);
-
+          // add checkbox whether to store the result in the settings
           QCheckBox *checkBox = new QCheckBox ("Don't ask again.");
           checkBox->setCheckState (Qt::Unchecked);
-
-          QDialogButtonBox *buttonBox = new QDialogButtonBox ();
-          QPushButton *noButton = buttonBox->addButton (QDialogButtonBox::No);
-          noButton->setAutoDefault (false);
-          buttonBox->addButton (QDialogButtonBox::Yes);
-          QHBoxLayout *buttonsLayout = new QHBoxLayout;
-          buttonsLayout->addStretch (1);
-          buttonsLayout->addWidget (buttonBox);
+          QVBoxLayout *extra = new QVBoxLayout (dlgBox);
+          extra->addWidget (checkBox);
+          QGridLayout *dialog_layout = dynamic_cast<QGridLayout*> (dlgBox->layout ());
+          dialog_layout->addLayout (extra,dialog_layout->rowCount (),0,
+                                    1,dialog_layout->columnCount ());
 
-          QVBoxLayout *mainLayout = new QVBoxLayout;
-          mainLayout->addLayout (horizontalLayout);
-          mainLayout->addSpacing(12);
-          mainLayout->addWidget (checkBox);
-          mainLayout->addSpacing(12);
-          mainLayout->addLayout (buttonsLayout);
-
-          dlgBox->setLayout (mainLayout);
-
-          connect(buttonBox, SIGNAL(accepted()), dlgBox, SLOT(accept()));
-          connect(buttonBox, SIGNAL(rejected()), dlgBox, SLOT(reject()));
-          dlgBox->setWindowModality (Qt::NonModal);
+          // shoe the dialog
           dlgBox->exec ();
 
-          restore_breakpoints = (dlgBox->result () == QDialog::Accepted);
+          // evaluate result
+          QMessageBox::StandardButton clicked = dlgBox->standardButton (dlgBox->clickedButton ());
+          restore_breakpoints = (clicked == QMessageBox::Yes);
 
           if (checkBox->checkState () == Qt::Checked)
             {