diff libgui/src/dialog.cc @ 16551:6ae555fc8c43

Add questdlg dialog function and fix variety of dialog bugs. * octave-qt-link.cc (octave_qt_link::do_message_dialog): Change initializer from QString to QString::fromStdString(dlg). (octave_qt_link::do_question_dialog): New function. Make all buttons AcceptRole. Signal dialog creation. Go to wait state. Get dialog button result when awakened. (octave_qt_link::do_list_dialog): Change std string 'prompt_string' to std list of std string 'prompt'. Use make_qstring_list(prompt). (octave_qt_link::do_input_dialog): Change 'nr' and 'nc' to std list of float. Use QFloatList::fromStdList(nc). * octave-qt-link.h (octave_qt_link : QObject, public octave_link): Add member do_question_dialog. (octave_qt_link::do_list_dialog): Use std list of std string for prompt. (octave_qt_link::do_input_dialog): Change 'nr' and 'nc' to std list of float. * octave-link.cc (__octave_link_question_dialog__): New builtin. Translate args to inputs of octave_link::question_dialog function. (__octave_link_list_dialog__): Retain prompt string cell list as a std list of std string. (__octave_link_input_dialog__): Make 'nr' and 'nc' std list of float. * octave-link.h (octave_link::question_dialog, octave_link::do_question_dialog): Add. (octave_link::list_dialog, octave_link::do_list_dialog): Change prompt to std list of std string. (octave_link::input_dialog, octave_link::do_input_dialog): Change 'nr' and 'nc' to std list of float. * errordlg.m (errordlg): Make retval return variable. Add "error" icon as message_dialog input. * helpdlg.m (helpdlg): Make retval return variable. Add "help" icon as message_dialog input. * warndlg.m (warndlg): Add "warn" icon as message_dialog input. * message_dialog.m (message_dialog): Define default icon "none". Use dlg variable with icon variable as input to __octave_link_message_dialog__. Use __octave_link_enabled__ rather than return value. * inputdlg.m (inputdlg): Round up rowscols to integer. Replace iscell(cstr) with __octave_link_enabled__. * listdlg.m (listdlg): Correct indentation. Change default selmode from "multiple" to "Multiple". Make default prompt {}. Check valid selmode entry. Use __octave_link_enabled__ rather than ok return value. Remove FIXME note. Use Rich Text in prompt of demo. Add demo using ListSize. * questdlg.m (questdlg): Add case 0 to switch. Add error message for default button not matching options. In all cases, check that default button matches an button option. Add __octave_link_question_dialog__ call conditioned under __octave_link_enabled__. Add three demos. * dialog.cc (QUIWidgetCreator::dialog_finished): Remove. (QUIWidgetCreator::dialog_button_clicked): Test that button pointer is nonzero. Move dialog_result assignment and waitcondition.wakeAll here. (MessageDialog::MessageDialog): If title "", change to " ". Reverse order that buttons are installed. Remove signal 'finished' connection. (ListDialog::ListDialog): Change prompt from QString to QStringList. Make list items noneditable. Add Rich Text support to prompt, place RT <br> between prompt list lines. Use label for prompt. Disable select_all button if not "Multiple". Remove horizontal group box. If title "", change to " ". (InputDialog::InputDialog): Change 'nr' and 'nc' to QFloatList. Define pre-processor variables, then undefine. If title "", change to " ". * dialog.h (QUIWidgetCreator::signal_listviewQUI, WidgetCreator::create_listview): Change QString 'prompt_string' to QStringList 'prompt'. (QUIWidgetCreator::signal_inputlayout, QUIWidgetCreator::create_inputlayout): Use QFloatList for 'nr' and 'nc'. (QUIWidgetCreator::dialog_finished): Remove. (MessageDialog::closeEvent): New override, emitting buttonClicked(0). (ListDialog::ListDialog): Change QString 'prompt_string' to QStringList 'prompt'. (InputDialog::InputDialog): Use QFloatList for 'nr' and 'nc'. * main_window.cc, main_window.h: Make function call changes that match dialog.h changes. (main_window::find_files_finished): Remove unused 'button' variable.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Mon, 22 Apr 2013 15:07:13 -0400
parents 94067a5d28ee
children e4b94abfeb96
line wrap: on
line diff
--- a/libgui/src/dialog.cc	Mon Apr 22 11:50:40 2013 -0400
+++ b/libgui/src/dialog.cc	Mon Apr 22 15:07:13 2013 -0400
@@ -42,6 +42,7 @@
 
 QUIWidgetCreator uiwidget_creator;
 
+
 QUIWidgetCreator::QUIWidgetCreator (void)
   : QObject (), dialog_result (-1), dialog_button (),
     string_list (new QStringList ()), list_index (new QIntList ())
@@ -56,13 +57,13 @@
 
 
 void
-QUIWidgetCreator::dialog_finished (int)
+QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button)
 {
   // Store the value so that builtin functions can retrieve.
-  // The value should always be 1 for the Octave functions.
+  if (button)
+    dialog_button = button->text ();
 
-  // Value returned by message box is not quite always 1.  If the
-  // window upper-right close button is pressed, 'result' is 0.
+  // The value should always be 1 for the Octave functions.
   dialog_result = 1;
 
   // Wake up Octave process so that it continues.
@@ -71,15 +72,6 @@
 
 
 void
-QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button)
-{
-  // Store information about what button was pressed so that builtin
-  // functions can retrieve.
-  dialog_button = button->text ();
-}
-
-
-void
 QUIWidgetCreator::list_select_finished (const QIntList& selected, const int button_pressed)
 {
   // Store the value so that builtin functions can retrieve.
@@ -103,12 +95,14 @@
 }
 
 
-MessageDialog::MessageDialog (const QString& message, const QString& title,
+MessageDialog::MessageDialog (const QString& message,
+                              const QString& title,
                               const QString& qsicon,
                               const QStringList& qsbutton,
                               const QString& defbutton,
                               const QStringList& role)
-  : QMessageBox (QMessageBox::NoIcon, title, message, 0, 0)
+  : QMessageBox (QMessageBox::NoIcon, title.isEmpty () ? " " : title,
+                 message, 0, 0)
 {
   // Create a NonModal message.
   setWindowModality (Qt::NonModal);
@@ -131,7 +125,7 @@
     addButton (QMessageBox::Ok);
   else
     {
-      for (int i = 0; i < N; i++)
+      for (int i = N-1; i >= 0; i--)
         {
           // Interpret the button role string, because enumeration
           // QMessageBox::ButtonRole can't be made to pass through a signal.
@@ -151,21 +145,26 @@
             setDefaultButton (pbutton);
           // Make the last button the button pressed when <esc> key activated.
           if (i == N-1)
-            setEscapeButton (pbutton);
+            {
+#define ACTIVE_ESCAPE true
+#if ACTIVE_ESCAPE
+              setEscapeButton (pbutton);
+#else
+              setEscapeButton (0);
+#endif
+#undef ACTIVE_ESCAPE
+            }
         }
     }
 
   connect (this, SIGNAL (buttonClicked (QAbstractButton *)),
            &uiwidget_creator, SLOT (dialog_button_clicked (QAbstractButton *)));
-
-  connect (this, SIGNAL (finished (int)),
-           &uiwidget_creator, SLOT (dialog_finished (int)));
 }
 
 
 ListDialog::ListDialog (const QStringList& list, const QString& mode,
                         int wd, int ht, const QList<int>& initial,
-                        const QString& name, const QString& prompt_string,
+                        const QString& title, const QStringList& prompt,
                         const QString& ok_string, const QString& cancel_string)
   : QDialog ()
 {
@@ -194,7 +193,6 @@
     {
       QModelIndex idx = model->index (initial.value (i++) - 1, 0,
                                       QModelIndex ());
-
       selector->select (idx, QItemSelectionModel::Select);
     }
 
@@ -205,17 +203,36 @@
       fixed_layout = true;
     }
 
-  QPushButton *select_all = new QPushButton (tr ("Select All"));
+  view->setEditTriggers (QAbstractItemView::NoEditTriggers);
+
   QVBoxLayout *listLayout = new QVBoxLayout;
+  if (! prompt.isEmpty ())
+    {
+      // For now, assume html-like Rich Text.  May be incompatible
+      // with something down the road, but just testing capability.
+      QString prompt_string;
+      for (int j = 0; j < prompt.length (); j++)
+        {
+          if (j > 0)
+#define RICH_TEXT true
+#if RICH_TEXT
+            prompt_string.append ("<br>");
+#else
+            prompt_string.append ("\n");
+#endif
+          prompt_string.append (prompt.at (j));
+        }
+      QLabel *plabel = new QLabel (prompt_string);
+#if RICH_TEXT
+      plabel->setTextFormat (Qt::RichText);
+#endif
+#undef RICH_TEXT
+      listLayout->addWidget (plabel);
+    }
   listLayout->addWidget (view);
+  QPushButton *select_all = new QPushButton (tr ("Select All"));
+  select_all->setEnabled (mode == "Multiple");
   listLayout->addWidget (select_all);
-  QGroupBox *listGroupBox = new QGroupBox (prompt_string);
-  listGroupBox->setLayout (listLayout);
-
-  //    QIcon *question_mark = new QIcon;
-  QHBoxLayout *horizontalLayout = new QHBoxLayout;
-  //    horizontalLayout->addWidget (question_mark);
-  horizontalLayout->addWidget (listGroupBox);
 
   QPushButton *buttonOk = new QPushButton (ok_string);
   QPushButton *buttonCancel = new QPushButton (cancel_string);
@@ -225,14 +242,15 @@
   buttonsLayout->addWidget (buttonCancel);
 
   QVBoxLayout *mainLayout = new QVBoxLayout;
-  mainLayout->addLayout (horizontalLayout);
+  mainLayout->addLayout (listLayout);
   mainLayout->addSpacing (12);
   mainLayout->addLayout (buttonsLayout);
   setLayout (mainLayout);
   if (fixed_layout)
     layout()->setSizeConstraint (QLayout::SetFixedSize);
 
-  setWindowTitle (name);
+  // If empty, make blank rather than use default OS behavior.
+  setWindowTitle (title.isEmpty () ? " " : title);
 
   connect (select_all, SIGNAL (clicked ()),
            view, SLOT (selectAll ()));
@@ -287,14 +305,14 @@
 
 
 InputDialog::InputDialog (const QStringList& prompt, const QString& title,
-                          const QIntList& nr, const QIntList& nc,
+                          const QFloatList& nr, const QFloatList& nc,
                           const QStringList& defaults)
   : QDialog ()
 {
 
-//#define LINE_EDIT_FOLLOWS_PROMPT
+#define LINE_EDIT_FOLLOWS_PROMPT false
 
-#ifdef LINE_EDIT_FOLLOWS_PROMPT
+#if LINE_EDIT_FOLLOWS_PROMPT
     // Prompt on left followed by input on right.
     QGridLayout *promptInputLayout = new QGridLayout;
 #else
@@ -318,7 +336,7 @@
               }
           }
         input_line << line_edit;
-#ifdef LINE_EDIT_FOLLOWS_PROMPT
+#if LINE_EDIT_FOLLOWS_PROMPT
         promptInputLayout->addWidget (label, i + 1, 0);
         promptInputLayout->addWidget (line_edit, i + 1, 1);
 #else
@@ -326,6 +344,7 @@
         promptInputLayout->addWidget (line_edit);
 #endif
       }
+#undef LINE_EDIT_FOLLOWS_PROMPT
 
     QPushButton *buttonOk = new QPushButton("OK");
     QPushButton *buttonCancel = new QPushButton("Cancel");
@@ -340,7 +359,8 @@
     mainLayout->addLayout (buttonsLayout);
     setLayout (mainLayout);
 
-    setWindowTitle (title);
+    // If empty, make blank rather than use default OS behavior.
+    setWindowTitle (title.isEmpty () ? " " : title);
 
     connect (buttonOk, SIGNAL (clicked ()),
              this, SLOT (buttonOk_clicked ()));