comparison libgui/src/dialog.cc @ 31648:29d734430e5f stable

maint: Re-indent code after switch to using namespace macros. * BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h, ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h, CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h, ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h, Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc, GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h, ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc, Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc, ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc, PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h, PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h, RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc, SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h, TextEdit.cc, TextEdit.h, ToggleButtonControl.cc, ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc, ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc, annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h, qt-graphics-toolkit.cc, qt-graphics-toolkit.h, module.mk, QTerminal.h, color-picker.cc, color-picker.h, command-widget.cc, command-widget.h, community-news.cc, community-news.h, dialog.cc, dialog.h, documentation-bookmarks.cc, documentation-bookmarks.h, documentation-dock-widget.cc, documentation-dock-widget.h, documentation.cc, documentation.h, dw-main-window.cc, dw-main-window.h, external-editor-interface.cc, external-editor-interface.h, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h, find-files-model.cc, find-files-model.h, graphics-init.cc, graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc, gui-utils.h, history-dock-widget.cc, history-dock-widget.h, interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc, led-indicator.h, file-editor-interface.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc, find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h, main-window.cc, main-window.h, news-reader.cc, news-reader.h, octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc, octave-qobject.h, qt-application.cc, qt-application.h, qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h, release-notes.cc, release-notes.h, resource-manager.cc, resource-manager.h, set-path-dialog.cc, set-path-dialog.h, set-path-model.cc, set-path-model.h, settings-dialog.cc, settings-dialog.h, shortcut-manager.cc, shortcut-manager.h, tab-bar.cc, tab-bar.h, terminal-dock-widget.cc, terminal-dock-widget.h, variable-editor-model.cc, variable-editor-model.h, variable-editor.cc, variable-editor.h, welcome-wizard.cc, welcome-wizard.h, workspace-model.cc, workspace-model.h, workspace-view.cc, workspace-view.h: Re-indent code after switch to using namespace macros.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Dec 2022 14:53:00 -0500
parents c6d54dd31a7e
children deb553ac2c54 597f3ee61a48
comparison
equal deleted inserted replaced
31646:c6d54dd31a7e 31648:29d734430e5f
45 #include "octave-qobject.h" 45 #include "octave-qobject.h"
46 #include "gui-preferences-global.h" 46 #include "gui-preferences-global.h"
47 47
48 OCTAVE_BEGIN_NAMESPACE(octave) 48 OCTAVE_BEGIN_NAMESPACE(octave)
49 49
50 QUIWidgetCreator::QUIWidgetCreator (base_qobject& oct_qobj) 50 QUIWidgetCreator::QUIWidgetCreator (base_qobject& oct_qobj)
51 : QObject (), m_octave_qobj (oct_qobj), m_dialog_result (-1), 51 : QObject (), m_octave_qobj (oct_qobj), m_dialog_result (-1),
52 m_dialog_button (), m_string_list (), m_list_index (), m_path_name () 52 m_dialog_button (), m_string_list (), m_list_index (), m_path_name ()
53 { 53 {
54 connect (this, &QUIWidgetCreator::create_dialog, 54 connect (this, &QUIWidgetCreator::create_dialog,
55 this, &QUIWidgetCreator::handle_create_dialog); 55 this, &QUIWidgetCreator::handle_create_dialog);
56 56
57 connect (this, &QUIWidgetCreator::create_listview, 57 connect (this, &QUIWidgetCreator::create_listview,
58 this, &QUIWidgetCreator::handle_create_listview); 58 this, &QUIWidgetCreator::handle_create_listview);
59 59
60 connect (this, &QUIWidgetCreator::create_inputlayout, 60 connect (this, &QUIWidgetCreator::create_inputlayout,
61 this, &QUIWidgetCreator::handle_create_inputlayout); 61 this, &QUIWidgetCreator::handle_create_inputlayout);
62 62
63 connect (this, &QUIWidgetCreator::create_filedialog, 63 connect (this, &QUIWidgetCreator::create_filedialog,
64 this, &QUIWidgetCreator::handle_create_filedialog); 64 this, &QUIWidgetCreator::handle_create_filedialog);
65 } 65 }
66 66
67 QString QUIWidgetCreator::rm_amp (const QString& text) 67 QString QUIWidgetCreator::rm_amp (const QString& text)
68 { 68 {
69 QString text_wo_amp = text; 69 QString text_wo_amp = text;
70 text_wo_amp.replace (QRegExp ("&(\\w)"), "\\1"); 70 text_wo_amp.replace (QRegExp ("&(\\w)"), "\\1");
71 return text_wo_amp; 71 return text_wo_amp;
72 } 72 }
73 73
74 QString QUIWidgetCreator::message_dialog (const QString& message, 74 QString QUIWidgetCreator::message_dialog (const QString& message,
75 const QString& title,
76 const QString& icon,
77 const QStringList& buttons,
78 const QString& defbutton,
79 const QStringList& role)
80 {
81 QMutexLocker autolock (&m_mutex);
82
83 // Store button text before a window-manager adds accelerators.
84
85 m_button_list = buttons;
86
87 // Use the last button in the list as the reject result, i.e., when
88 // no button is pressed such as in the case of the upper right close
89 // tab.
90 if (! buttons.isEmpty ())
91 m_dialog_button = buttons.last ();
92
93 QString xicon = icon;
94 if (xicon.isEmpty ())
95 xicon = "none";
96
97 emit create_dialog (message, title, xicon, buttons, defbutton, role);
98
99 // Wait while the user is responding to message box.
100 wait ();
101
102 // The GUI has sent a signal and the thread has been awakened.
103 return m_dialog_button;
104 };
105
106 QPair<QIntList, int>
107 QUIWidgetCreator::list_dialog (const QStringList& list, const QString& mode,
108 int wd, int ht, const QList<int>& initial,
109 const QString& name,
110 const QStringList& prompt,
111 const QString& ok_string,
112 const QString& cancel_string)
113 {
114 if (list.isEmpty ())
115 return QPair<QIntList, int> ();
116
117 QMutexLocker autolock (&m_mutex);
118
119 emit create_listview (list, mode, wd, ht, initial, name,
120 prompt, ok_string, cancel_string);
121
122 // Wait while the user is responding to message box.
123 wait ();
124
125 // The GUI has sent a signal and the thread has been awakened.
126 return QPair<QIntList, int> (m_list_index, m_dialog_result);
127 };
128
129 // Create a message dialog with specified string, buttons and
130 // decorative text.
131
132 QStringList QUIWidgetCreator::input_dialog (const QStringList& prompt,
75 const QString& title, 133 const QString& title,
76 const QString& icon, 134 const QFloatList& nr,
77 const QStringList& buttons, 135 const QFloatList& nc,
78 const QString& defbutton, 136 const QStringList& defaults)
79 const QStringList& role) 137 {
80 { 138 if (prompt.isEmpty ())
81 QMutexLocker autolock (&m_mutex); 139 return QStringList ();
82 140
83 // Store button text before a window-manager adds accelerators. 141 QMutexLocker autolock (&m_mutex);
84 142
85 m_button_list = buttons; 143 emit create_inputlayout (prompt, title, nr, nc, defaults);
86 144
87 // Use the last button in the list as the reject result, i.e., when 145 // Wait while the user is responding to message box.
88 // no button is pressed such as in the case of the upper right close 146 wait ();
89 // tab. 147
90 if (! buttons.isEmpty ()) 148 // The GUI has sent a signal and the thread has been awakened.
91 m_dialog_button = buttons.last (); 149 return m_string_list;
92 150 };
93 QString xicon = icon; 151
94 if (xicon.isEmpty ()) 152 QStringList QUIWidgetCreator::file_dialog (const QStringList& filters,
95 xicon = "none"; 153 const QString& title,
96 154 const QString& filename,
97 emit create_dialog (message, title, xicon, buttons, defbutton, role); 155 const QString& dirname,
98 156 const QString& multimode)
99 // Wait while the user is responding to message box. 157 {
100 wait (); 158 QMutexLocker autolock (&m_mutex);
101 159
102 // The GUI has sent a signal and the thread has been awakened. 160 emit create_filedialog (filters, title, filename, dirname, multimode);
103 return m_dialog_button; 161
104 }; 162 // Wait while the user is responding to dialog.
105 163 wait ();
106 QPair<QIntList, int> 164
107 QUIWidgetCreator::list_dialog (const QStringList& list, const QString& mode, 165 // The GUI has sent a signal and the thread has been awakened.
108 int wd, int ht, const QList<int>& initial, 166 // Add all the file dialog results to a string list.
109 const QString& name, 167 QStringList retval;
110 const QStringList& prompt, 168 retval << m_string_list
111 const QString& ok_string, 169 << m_path_name
112 const QString& cancel_string) 170 << QString::number (m_dialog_result);
113 { 171
114 if (list.isEmpty ()) 172 return retval;
115 return QPair<QIntList, int> (); 173 }
116 174
117 QMutexLocker autolock (&m_mutex); 175 void QUIWidgetCreator::handle_create_dialog (const QString& message,
118
119 emit create_listview (list, mode, wd, ht, initial, name,
120 prompt, ok_string, cancel_string);
121
122 // Wait while the user is responding to message box.
123 wait ();
124
125 // The GUI has sent a signal and the thread has been awakened.
126 return QPair<QIntList, int> (m_list_index, m_dialog_result);
127 };
128
129 // Create a message dialog with specified string, buttons and
130 // decorative text.
131
132 QStringList QUIWidgetCreator::input_dialog (const QStringList& prompt,
133 const QString& title,
134 const QFloatList& nr,
135 const QFloatList& nc,
136 const QStringList& defaults)
137 {
138 if (prompt.isEmpty ())
139 return QStringList ();
140
141 QMutexLocker autolock (&m_mutex);
142
143 emit create_inputlayout (prompt, title, nr, nc, defaults);
144
145 // Wait while the user is responding to message box.
146 wait ();
147
148 // The GUI has sent a signal and the thread has been awakened.
149 return m_string_list;
150 };
151
152 QStringList QUIWidgetCreator::file_dialog (const QStringList& filters,
153 const QString& title, 176 const QString& title,
154 const QString& filename, 177 const QString& icon,
155 const QString& dirname, 178 const QStringList& button,
156 const QString& multimode) 179 const QString& defbutton,
157 { 180 const QStringList& role)
158 QMutexLocker autolock (&m_mutex); 181 {
159 182 MessageDialog *message_dialog
160 emit create_filedialog (filters, title, filename, dirname, multimode); 183 = new MessageDialog (m_octave_qobj, message, title, icon,
161 184 button, defbutton, role);
162 // Wait while the user is responding to dialog. 185
163 wait (); 186 connect (message_dialog, &MessageDialog::buttonClicked,
164 187 this, &QUIWidgetCreator::dialog_button_clicked);
165 // The GUI has sent a signal and the thread has been awakened. 188
166 // Add all the file dialog results to a string list. 189 message_dialog->setAttribute (Qt::WA_DeleteOnClose);
167 QStringList retval; 190 message_dialog->show ();
168 retval << m_string_list 191 }
169 << m_path_name 192
170 << QString::number (m_dialog_result); 193 void QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button)
171 194 {
172 return retval; 195 // button is NULL when dialog is closed.
173 } 196 if (button)
174 197 {
175 void QUIWidgetCreator::handle_create_dialog (const QString& message, 198 // Check for a matching button text while ignoring accelerators
176 const QString& title, 199 // because the window manager may have added one in the passed
177 const QString& icon, 200 // button.
178 const QStringList& button, 201
179 const QString& defbutton, 202 QString text_clean = rm_amp (button->text ());
180 const QStringList& role) 203
181 { 204 for (int i = 0; i < m_button_list.count (); i++)
182 MessageDialog *message_dialog 205 {
183 = new MessageDialog (m_octave_qobj, message, title, icon, 206 if (rm_amp (m_button_list.at (i)) == text_clean)
184 button, defbutton, role); 207 {
185 208 // Text w/o extra accelerator.
186 connect (message_dialog, &MessageDialog::buttonClicked, 209 m_dialog_button = m_button_list.at (i);
187 this, &QUIWidgetCreator::dialog_button_clicked); 210 break;
188 211 }
189 message_dialog->setAttribute (Qt::WA_DeleteOnClose); 212 }
190 message_dialog->show (); 213 }
191 } 214
192 215 // The value should always be 1 for the Octave functions.
193 void QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button) 216 m_dialog_result = 1;
194 { 217
195 // button is NULL when dialog is closed. 218 // Wake up Octave process so that it continues.
196 if (button) 219 wake_all ();
197 { 220 }
198 // Check for a matching button text while ignoring accelerators 221
199 // because the window manager may have added one in the passed 222 // Create a list dialog with specified list, initially selected, mode,
200 // button. 223 // view size and decorative text.
201 224
202 QString text_clean = rm_amp (button->text ()); 225 void QUIWidgetCreator::handle_create_listview (const QStringList& list,
203 226 const QString& mode,
204 for (int i = 0; i < m_button_list.count (); i++) 227 int wd, int ht,
205 { 228 const QIntList& initial,
206 if (rm_amp (m_button_list.at (i)) == text_clean) 229 const QString& name,
207 { 230 const QStringList& prompt,
208 // Text w/o extra accelerator. 231 const QString& ok_string,
209 m_dialog_button = m_button_list.at (i); 232 const QString& cancel_string)
210 break; 233 {
211 } 234 ListDialog *list_dialog
212 } 235 = new ListDialog (m_octave_qobj, list, mode, wd, ht, initial,
213 } 236 name, prompt, ok_string, cancel_string);
214 237
215 // The value should always be 1 for the Octave functions. 238 connect (list_dialog, &ListDialog::finish_selection,
216 m_dialog_result = 1; 239 this, &QUIWidgetCreator::list_select_finished);
217 240
218 // Wake up Octave process so that it continues. 241 list_dialog->setAttribute (Qt::WA_DeleteOnClose);
219 wake_all (); 242 list_dialog->show ();
220 } 243 }
221 244
222 // Create a list dialog with specified list, initially selected, mode, 245 void QUIWidgetCreator::list_select_finished (const QIntList& selected,
223 // view size and decorative text. 246 int button_pressed)
224 247 {
225 void QUIWidgetCreator::handle_create_listview (const QStringList& list, 248 // Store the value so that builtin functions can retrieve.
226 const QString& mode, 249
227 int wd, int ht, 250 m_list_index = selected;
228 const QIntList& initial, 251 m_dialog_result = button_pressed;
229 const QString& name, 252
230 const QStringList& prompt, 253 // Wake up Octave process so that it continues.
231 const QString& ok_string, 254 wake_all ();
232 const QString& cancel_string) 255 }
233 { 256
234 ListDialog *list_dialog 257 // Create an input dialog with specified prompts and defaults, title
235 = new ListDialog (m_octave_qobj, list, mode, wd, ht, initial, 258 // and row/column size specifications.
236 name, prompt, ok_string, cancel_string); 259
237 260 void QUIWidgetCreator::handle_create_inputlayout (const QStringList& prompt,
238 connect (list_dialog, &ListDialog::finish_selection, 261 const QString& title,
239 this, &QUIWidgetCreator::list_select_finished); 262 const QFloatList& nr,
240 263 const QFloatList& nc,
241 list_dialog->setAttribute (Qt::WA_DeleteOnClose); 264 const QStringList& defaults)
242 list_dialog->show (); 265 {
243 } 266 InputDialog *input_dialog
244 267 = new InputDialog (m_octave_qobj, prompt, title, nr, nc, defaults);
245 void QUIWidgetCreator::list_select_finished (const QIntList& selected, 268
246 int button_pressed) 269 connect (input_dialog, &InputDialog::finish_input,
247 { 270 this, &QUIWidgetCreator::input_finished);
248 // Store the value so that builtin functions can retrieve. 271
249 272 input_dialog->setAttribute (Qt::WA_DeleteOnClose);
250 m_list_index = selected; 273 input_dialog->show ();
251 m_dialog_result = button_pressed; 274 }
252 275
253 // Wake up Octave process so that it continues. 276 void QUIWidgetCreator::input_finished (const QStringList& input,
254 wake_all (); 277 int button_pressed)
255 } 278 {
256 279 // Store the value so that builtin functions can retrieve.
257 // Create an input dialog with specified prompts and defaults, title 280
258 // and row/column size specifications. 281 m_string_list = input;
259 282 m_dialog_result = button_pressed;
260 void QUIWidgetCreator::handle_create_inputlayout (const QStringList& prompt, 283
261 const QString& title, 284 // Wake up Octave process so that it continues.
262 const QFloatList& nr, 285 wake_all ();
263 const QFloatList& nc, 286 }
264 const QStringList& defaults) 287
265 { 288 void QUIWidgetCreator::handle_create_filedialog (const QStringList& filters,
266 InputDialog *input_dialog 289 const QString& title,
267 = new InputDialog (m_octave_qobj, prompt, title, nr, nc, defaults); 290 const QString& filename,
268 291 const QString& dirname,
269 connect (input_dialog, &InputDialog::finish_input, 292 const QString& multimode)
270 this, &QUIWidgetCreator::input_finished); 293 {
271 294 FileDialog *file_dialog
272 input_dialog->setAttribute (Qt::WA_DeleteOnClose); 295 = new FileDialog (m_octave_qobj, filters, title, filename,
273 input_dialog->show (); 296 dirname, multimode);
274 } 297
275 298 connect (file_dialog, &FileDialog::finish_input,
276 void QUIWidgetCreator::input_finished (const QStringList& input, 299 this, &QUIWidgetCreator::filedialog_finished);
277 int button_pressed) 300
278 { 301 file_dialog->setAttribute (Qt::WA_DeleteOnClose);
279 // Store the value so that builtin functions can retrieve. 302 file_dialog->show ();
280 303 }
281 m_string_list = input; 304
282 m_dialog_result = button_pressed; 305 void QUIWidgetCreator::filedialog_finished (const QStringList& files,
283 306 const QString& path,
284 // Wake up Octave process so that it continues. 307 int filterindex)
285 wake_all (); 308 {
286 } 309 // Store the value so that builtin functions can retrieve.
287 310
288 void QUIWidgetCreator::handle_create_filedialog (const QStringList& filters, 311 m_string_list = files;
289 const QString& title, 312 m_dialog_result = filterindex;
290 const QString& filename, 313 m_path_name = path;
291 const QString& dirname, 314
292 const QString& multimode) 315 // Wake up Octave process so that it continues.
293 { 316 wake_all ();
294 FileDialog *file_dialog 317 }
295 = new FileDialog (m_octave_qobj, filters, title, filename, 318
296 dirname, multimode); 319 MessageDialog::MessageDialog (base_qobject&, const QString& message,
297 320 const QString& title, const QString& qsicon,
298 connect (file_dialog, &FileDialog::finish_input, 321 const QStringList& qsbutton,
299 this, &QUIWidgetCreator::filedialog_finished); 322 const QString& defbutton,
300 323 const QStringList& role)
301 file_dialog->setAttribute (Qt::WA_DeleteOnClose); 324 : QMessageBox (QMessageBox::NoIcon, title.isEmpty () ? " " : title,
302 file_dialog->show (); 325 message)
303 } 326 {
304 327 // Create a NonModal message.
305 void QUIWidgetCreator::filedialog_finished (const QStringList& files, 328 setWindowModality (Qt::NonModal);
306 const QString& path, 329
307 int filterindex) 330 // Interpret the icon string, because enumeration QMessageBox::Icon can't
308 { 331 // easily be made to pass through a signal.
309 // Store the value so that builtin functions can retrieve. 332
310 333 QMessageBox::Icon eicon = QMessageBox::NoIcon;
311 m_string_list = files; 334
312 m_dialog_result = filterindex; 335 if (qsicon == "error")
313 m_path_name = path; 336 eicon = QMessageBox::Critical;
314 337 else if (qsicon == "warn")
315 // Wake up Octave process so that it continues. 338 eicon = QMessageBox::Warning;
316 wake_all (); 339 else if (qsicon == "help")
317 } 340 eicon = QMessageBox::Information;
318 341 else if (qsicon == "quest")
319 MessageDialog::MessageDialog (base_qobject&, const QString& message, 342 eicon = QMessageBox::Question;
320 const QString& title, const QString& qsicon, 343
321 const QStringList& qsbutton, 344 setIcon (eicon);
322 const QString& defbutton, 345
323 const QStringList& role) 346 int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ());
324 : QMessageBox (QMessageBox::NoIcon, title.isEmpty () ? " " : title, 347
325 message) 348 if (N == 0)
326 { 349 addButton (QMessageBox::Ok);
327 // Create a NonModal message. 350 else
328 setWindowModality (Qt::NonModal); 351 {
329 352 for (int i = 0; i < N; i++)
330 // Interpret the icon string, because enumeration QMessageBox::Icon can't 353 {
331 // easily be made to pass through a signal. 354 // Interpret the button role string, because enumeration
332 355 // QMessageBox::ButtonRole can't be made to pass through a
333 QMessageBox::Icon eicon = QMessageBox::NoIcon; 356 // signal.
334 357
335 if (qsicon == "error") 358 QString srole = role.at (i);
336 eicon = QMessageBox::Critical; 359 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
337 else if (qsicon == "warn") 360 if (srole == "ResetRole")
338 eicon = QMessageBox::Warning; 361 erole = QMessageBox::ResetRole;
339 else if (qsicon == "help") 362 else if (srole == "YesRole")
340 eicon = QMessageBox::Information; 363 erole = QMessageBox::YesRole;
341 else if (qsicon == "quest") 364 else if (srole == "NoRole")
342 eicon = QMessageBox::Question; 365 erole = QMessageBox::NoRole;
343 366 else if (srole == "RejectRole")
344 setIcon (eicon); 367 erole = QMessageBox::RejectRole;
345 368 else if (srole == "AcceptRole")
346 int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ()); 369 erole = QMessageBox::AcceptRole;
347 370
348 if (N == 0) 371 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
349 addButton (QMessageBox::Ok); 372 if (qsbutton.at (i) == defbutton)
350 else 373 setDefaultButton (pbutton);
351 { 374
352 for (int i = 0; i < N; i++) 375 // Make the last button the button pressed when <esc> key activated.
353 { 376 if (i == N-1)
354 // Interpret the button role string, because enumeration 377 {
355 // QMessageBox::ButtonRole can't be made to pass through a 378 // FIXME: Why define and then immediately test value?
356 // signal.
357
358 QString srole = role.at (i);
359 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
360 if (srole == "ResetRole")
361 erole = QMessageBox::ResetRole;
362 else if (srole == "YesRole")
363 erole = QMessageBox::YesRole;
364 else if (srole == "NoRole")
365 erole = QMessageBox::NoRole;
366 else if (srole == "RejectRole")
367 erole = QMessageBox::RejectRole;
368 else if (srole == "AcceptRole")
369 erole = QMessageBox::AcceptRole;
370
371 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
372 if (qsbutton.at (i) == defbutton)
373 setDefaultButton (pbutton);
374
375 // Make the last button the button pressed when <esc> key activated.
376 if (i == N-1)
377 {
378 // FIXME: Why define and then immediately test value?
379 #define ACTIVE_ESCAPE 1 379 #define ACTIVE_ESCAPE 1
380 #if ACTIVE_ESCAPE 380 #if ACTIVE_ESCAPE
381 setEscapeButton (pbutton); 381 setEscapeButton (pbutton);
382 #else 382 #else
383 setEscapeButton (0); 383 setEscapeButton (0);
384 #endif 384 #endif
385 #undef ACTIVE_ESCAPE 385 #undef ACTIVE_ESCAPE
386 } 386 }
387 } 387 }
388 } 388 }
389 } 389 }
390 390
391 ListDialog::ListDialog (base_qobject&, const QStringList& list, 391 ListDialog::ListDialog (base_qobject&, const QStringList& list,
392 const QString& mode, int wd, int ht, 392 const QString& mode, int wd, int ht,
393 const QList<int>& initial, const QString& title, 393 const QList<int>& initial, const QString& title,
394 const QStringList& prompt, 394 const QStringList& prompt,
395 const QString& ok_string, 395 const QString& ok_string,
396 const QString& cancel_string) 396 const QString& cancel_string)
397 : QDialog (), m_model (new QStringListModel (list, this)) 397 : QDialog (), m_model (new QStringListModel (list, this))
398 { 398 {
399 QListView *view = new QListView; 399 QListView *view = new QListView;
400 view->setModel (m_model); 400 view->setModel (m_model);
401 401
402 if (mode == "single") 402 if (mode == "single")
403 view->setSelectionMode (QAbstractItemView::SingleSelection); 403 view->setSelectionMode (QAbstractItemView::SingleSelection);
404 else if (mode == "multiple") 404 else if (mode == "multiple")
405 view->setSelectionMode (QAbstractItemView::ExtendedSelection); 405 view->setSelectionMode (QAbstractItemView::ExtendedSelection);
406 else 406 else
407 view->setSelectionMode (QAbstractItemView::NoSelection); 407 view->setSelectionMode (QAbstractItemView::NoSelection);
408 408
409 selector = view->selectionModel (); 409 selector = view->selectionModel ();
410 int i = 0; 410 int i = 0;
411 for (auto it = initial.begin (); it != initial.end (); it++) 411 for (auto it = initial.begin (); it != initial.end (); it++)
412 { 412 {
413 QModelIndex idx = m_model->index (initial.value (i++) - 1, 0, 413 QModelIndex idx = m_model->index (initial.value (i++) - 1, 0,
414 QModelIndex ()); 414 QModelIndex ());
415 selector->select (idx, QItemSelectionModel::Select); 415 selector->select (idx, QItemSelectionModel::Select);
416 } 416 }
417 417
418 bool fixed_layout = false; 418 bool fixed_layout = false;
419 if (wd > 0 && ht > 0) 419 if (wd > 0 && ht > 0)
420 { 420 {
421 view->setFixedSize (wd, ht); 421 view->setFixedSize (wd, ht);
422 fixed_layout = true; 422 fixed_layout = true;
423 } 423 }
424 424
425 view->setEditTriggers (QAbstractItemView::NoEditTriggers); 425 view->setEditTriggers (QAbstractItemView::NoEditTriggers);
426 426
427 QVBoxLayout *listLayout = new QVBoxLayout; 427 QVBoxLayout *listLayout = new QVBoxLayout;
428 if (! prompt.isEmpty ()) 428 if (! prompt.isEmpty ())
429 { 429 {
430 // For now, assume html-like Rich Text. May be incompatible 430 // For now, assume html-like Rich Text. May be incompatible
431 // with something down the road, but just testing capability. 431 // with something down the road, but just testing capability.
432 QString prompt_string; 432 QString prompt_string;
433 for (int j = 0; j < prompt.length (); j++) 433 for (int j = 0; j < prompt.length (); j++)
434 { 434 {
435 if (j > 0) 435 if (j > 0)
436 // FIXME: Why define and then immediately test value? 436 // FIXME: Why define and then immediately test value?
437 #define RICH_TEXT 1 437 #define RICH_TEXT 1
438 #if RICH_TEXT 438 #if RICH_TEXT
439 prompt_string.append ("<br>"); 439 prompt_string.append ("<br>");
440 #else 440 #else
441 prompt_string.append ("\n"); 441 prompt_string.append ("\n");
442 #endif 442 #endif
443 prompt_string.append (prompt.at (j)); 443 prompt_string.append (prompt.at (j));
444 } 444 }
445 QLabel *plabel = new QLabel (prompt_string); 445 QLabel *plabel = new QLabel (prompt_string);
446 #if RICH_TEXT 446 #if RICH_TEXT
447 plabel->setTextFormat (Qt::RichText); 447 plabel->setTextFormat (Qt::RichText);
448 #endif 448 #endif
449 #undef RICH_TEXT 449 #undef RICH_TEXT
450 listLayout->addWidget (plabel); 450 listLayout->addWidget (plabel);
451 } 451 }
452 listLayout->addWidget (view); 452 listLayout->addWidget (view);
453 QPushButton *select_all = new QPushButton (tr ("Select All")); 453 QPushButton *select_all = new QPushButton (tr ("Select All"));
454 select_all->setVisible (mode == "multiple"); 454 select_all->setVisible (mode == "multiple");
455 listLayout->addWidget (select_all); 455 listLayout->addWidget (select_all);
456 456
457 QPushButton *buttonOk = new QPushButton (ok_string); 457 QPushButton *buttonOk = new QPushButton (ok_string);
458 QPushButton *buttonCancel = new QPushButton (cancel_string); 458 QPushButton *buttonCancel = new QPushButton (cancel_string);
459 QHBoxLayout *buttonsLayout = new QHBoxLayout; 459 QHBoxLayout *buttonsLayout = new QHBoxLayout;
460 buttonsLayout->addStretch (1); 460 buttonsLayout->addStretch (1);
461 buttonsLayout->addWidget (buttonOk); 461 buttonsLayout->addWidget (buttonOk);
462 buttonsLayout->addWidget (buttonCancel); 462 buttonsLayout->addWidget (buttonCancel);
463 buttonOk->setDefault (true); 463 buttonOk->setDefault (true);
464 464
465 QVBoxLayout *mainLayout = new QVBoxLayout; 465 QVBoxLayout *mainLayout = new QVBoxLayout;
466 mainLayout->addLayout (listLayout); 466 mainLayout->addLayout (listLayout);
467 mainLayout->addSpacing (12); 467 mainLayout->addSpacing (12);
468 mainLayout->addLayout (buttonsLayout); 468 mainLayout->addLayout (buttonsLayout);
469 setLayout (mainLayout); 469 setLayout (mainLayout);
470 if (fixed_layout) 470 if (fixed_layout)
471 layout ()->setSizeConstraint (QLayout::SetFixedSize); 471 layout ()->setSizeConstraint (QLayout::SetFixedSize);
472 472
473 // If empty, make blank rather than use default OS behavior. 473 // If empty, make blank rather than use default OS behavior.
474 setWindowTitle (title.isEmpty () ? " " : title); 474 setWindowTitle (title.isEmpty () ? " " : title);
475 475
476 connect (select_all, &QPushButton::clicked, 476 connect (select_all, &QPushButton::clicked,
477 view, &QListView::selectAll); 477 view, &QListView::selectAll);
478 478
479 connect (buttonOk, &QPushButton::clicked, 479 connect (buttonOk, &QPushButton::clicked,
480 this, &ListDialog::buttonOk_clicked); 480 this, &ListDialog::buttonOk_clicked);
481 481
482 connect (buttonCancel, &QPushButton::clicked, 482 connect (buttonCancel, &QPushButton::clicked,
483 this, &ListDialog::buttonCancel_clicked); 483 this, &ListDialog::buttonCancel_clicked);
484 484
485 connect (view, &QListView::doubleClicked, 485 connect (view, &QListView::doubleClicked,
486 this, &ListDialog::item_double_clicked); 486 this, &ListDialog::item_double_clicked);
487 } 487 }
488 488
489 void ListDialog::buttonOk_clicked (void) 489 void ListDialog::buttonOk_clicked (void)
490 { 490 {
491 // Store information about what button was pressed so that builtin 491 // Store information about what button was pressed so that builtin
492 // functions can retrieve. 492 // functions can retrieve.
493 493
494 QModelIndexList selected_index = selector->selectedIndexes (); 494 QModelIndexList selected_index = selector->selectedIndexes ();
495 QIntList selected_int; 495 QIntList selected_int;
496 496
497 for (int i = 0; i < selected_index.size (); i++) 497 for (int i = 0; i < selected_index.size (); i++)
498 selected_int << selected_index.at (i).row () + 1; 498 selected_int << selected_index.at (i).row () + 1;
499 499
500 emit finish_selection (selected_int, 1); 500 emit finish_selection (selected_int, 1);
501 501
502 done (QDialog::Accepted); 502 done (QDialog::Accepted);
503 } 503 }
504 504
505 void ListDialog::buttonCancel_clicked (void) 505 void ListDialog::buttonCancel_clicked (void)
506 { 506 {
507 // Store information about what button was pressed so that builtin 507 // Store information about what button was pressed so that builtin
508 // functions can retrieve. 508 // functions can retrieve.
509 509
510 QIntList empty; 510 QIntList empty;
511 511
512 emit finish_selection (empty, 0); 512 emit finish_selection (empty, 0);
513 513
514 done (QDialog::Rejected); 514 done (QDialog::Rejected);
515 } 515 }
516 516
517 void ListDialog::reject (void) 517 void ListDialog::reject (void)
518 { 518 {
519 buttonCancel_clicked (); 519 buttonCancel_clicked ();
520 } 520 }
521 521
522 void ListDialog::item_double_clicked (const QModelIndex&) 522 void ListDialog::item_double_clicked (const QModelIndex&)
523 { 523 {
524 buttonOk_clicked (); 524 buttonOk_clicked ();
525 } 525 }
526 526
527 InputDialog::InputDialog (base_qobject&, const QStringList& prompt, 527 InputDialog::InputDialog (base_qobject&, const QStringList& prompt,
528 const QString& title, const QFloatList& nr, 528 const QString& title, const QFloatList& nr,
529 const QFloatList& nc, const QStringList& defaults) 529 const QFloatList& nc, const QStringList& defaults)
530 : QDialog () 530 : QDialog ()
531 { 531 {
532 532
533 #define LINE_EDIT_FOLLOWS_PROMPT 0 533 #define LINE_EDIT_FOLLOWS_PROMPT 0
534 534
535 #if LINE_EDIT_FOLLOWS_PROMPT 535 #if LINE_EDIT_FOLLOWS_PROMPT
536 // Prompt on left followed by input on right. 536 // Prompt on left followed by input on right.
537 QGridLayout *promptInputLayout = new QGridLayout; 537 QGridLayout *promptInputLayout = new QGridLayout;
538 #else 538 #else
539 // Prompt aligned above input. 539 // Prompt aligned above input.
540 QVBoxLayout *promptInputLayout = new QVBoxLayout; 540 QVBoxLayout *promptInputLayout = new QVBoxLayout;
541 #endif 541 #endif
542 int N_gridrows = prompt.size (); 542 int N_gridrows = prompt.size ();
543 for (int i = 0; i < N_gridrows; i++) 543 for (int i = 0; i < N_gridrows; i++)
544 { 544 {
545 QLabel *label = new QLabel (prompt.at (i)); 545 QLabel *label = new QLabel (prompt.at (i));
546 QLineEdit *line_edit = new QLineEdit (); 546 QLineEdit *line_edit = new QLineEdit ();
547 if (i < defaults.size ()) 547 if (i < defaults.size ())
548 line_edit->setText (defaults.at (i)); 548 line_edit->setText (defaults.at (i));
549 if (i < nr.size () && nr.at (i) > 0) 549 if (i < nr.size () && nr.at (i) > 0)
550 { 550 {
551 QSize qsize = line_edit->sizeHint (); 551 QSize qsize = line_edit->sizeHint ();
552 int intval = qsize.height () * nr.at (i); 552 int intval = qsize.height () * nr.at (i);
553 line_edit->setFixedHeight (intval); 553 line_edit->setFixedHeight (intval);
554 if (i < nc.size () && nc.at (i) > 0) 554 if (i < nc.size () && nc.at (i) > 0)
555 { 555 {
556 intval = qsize.height () * nc.at (i) / 2; 556 intval = qsize.height () * nc.at (i) / 2;
557 line_edit->setFixedWidth (intval); 557 line_edit->setFixedWidth (intval);
558 } 558 }
559 } 559 }
560 input_line << line_edit; 560 input_line << line_edit;
561 #if LINE_EDIT_FOLLOWS_PROMPT 561 #if LINE_EDIT_FOLLOWS_PROMPT
562 promptInputLayout->addWidget (label, i + 1, 0); 562 promptInputLayout->addWidget (label, i + 1, 0);
563 promptInputLayout->addWidget (line_edit, i + 1, 1); 563 promptInputLayout->addWidget (line_edit, i + 1, 1);
564 #else 564 #else
565 promptInputLayout->addWidget (label); 565 promptInputLayout->addWidget (label);
566 promptInputLayout->addWidget (line_edit); 566 promptInputLayout->addWidget (line_edit);
567 #endif 567 #endif
568 } 568 }
569 #undef LINE_EDIT_FOLLOWS_PROMPT 569 #undef LINE_EDIT_FOLLOWS_PROMPT
570 570
571 QPushButton *buttonOk = new QPushButton ("OK"); 571 QPushButton *buttonOk = new QPushButton ("OK");
572 QPushButton *buttonCancel = new QPushButton ("Cancel"); 572 QPushButton *buttonCancel = new QPushButton ("Cancel");
573 QHBoxLayout *buttonsLayout = new QHBoxLayout; 573 QHBoxLayout *buttonsLayout = new QHBoxLayout;
574 buttonsLayout->addStretch (1); 574 buttonsLayout->addStretch (1);
575 buttonsLayout->addWidget (buttonOk); 575 buttonsLayout->addWidget (buttonOk);
576 buttonsLayout->addWidget (buttonCancel); 576 buttonsLayout->addWidget (buttonCancel);
577 577
578 QVBoxLayout *mainLayout = new QVBoxLayout; 578 QVBoxLayout *mainLayout = new QVBoxLayout;
579 mainLayout->addLayout (promptInputLayout); 579 mainLayout->addLayout (promptInputLayout);
580 mainLayout->addSpacing (12); 580 mainLayout->addSpacing (12);
581 mainLayout->addLayout (buttonsLayout); 581 mainLayout->addLayout (buttonsLayout);
582 setLayout (mainLayout); 582 setLayout (mainLayout);
583 583
584 // If empty, make blank rather than use default OS behavior. 584 // If empty, make blank rather than use default OS behavior.
585 setWindowTitle (title.isEmpty () ? " " : title); 585 setWindowTitle (title.isEmpty () ? " " : title);
586 586
587 connect (buttonOk, &QPushButton::clicked, 587 connect (buttonOk, &QPushButton::clicked,
588 this, &InputDialog::buttonOk_clicked); 588 this, &InputDialog::buttonOk_clicked);
589 589
590 connect (buttonCancel, &QPushButton::clicked, 590 connect (buttonCancel, &QPushButton::clicked,
591 this, &InputDialog::buttonCancel_clicked); 591 this, &InputDialog::buttonCancel_clicked);
592 } 592 }
593 593
594 void InputDialog::buttonOk_clicked (void) 594 void InputDialog::buttonOk_clicked (void)
595 { 595 {
596 // Store information about what button was pressed so that builtin 596 // Store information about what button was pressed so that builtin
597 // functions can retrieve. 597 // functions can retrieve.
598 598
599 QStringList string_result; 599 QStringList string_result;
600 for (int i = 0; i < input_line.size (); i++) 600 for (int i = 0; i < input_line.size (); i++)
601 string_result << input_line.at (i)->text (); 601 string_result << input_line.at (i)->text ();
602 emit finish_input (string_result, 1); 602 emit finish_input (string_result, 1);
603 done (QDialog::Accepted); 603 done (QDialog::Accepted);
604 } 604 }
605 605
606 void InputDialog::buttonCancel_clicked (void) 606 void InputDialog::buttonCancel_clicked (void)
607 { 607 {
608 // Store information about what button was pressed so that builtin 608 // Store information about what button was pressed so that builtin
609 // functions can retrieve. 609 // functions can retrieve.
610 610
611 QStringList empty; 611 QStringList empty;
612 emit finish_input (empty, 0); 612 emit finish_input (empty, 0);
613 done (QDialog::Rejected); 613 done (QDialog::Rejected);
614 } 614 }
615 615
616 void InputDialog::reject (void) 616 void InputDialog::reject (void)
617 { 617 {
618 buttonCancel_clicked (); 618 buttonCancel_clicked ();
619 } 619 }
620 620
621 FileDialog::FileDialog (base_qobject& oct_qobj, 621 FileDialog::FileDialog (base_qobject& oct_qobj,
622 const QStringList& name_filters, 622 const QStringList& name_filters,
623 const QString& title, const QString& filename, 623 const QString& title, const QString& filename,
624 const QString& dirname, const QString& multimode) 624 const QString& dirname, const QString& multimode)
625 : QFileDialog () 625 : QFileDialog ()
626 { 626 {
627 // Create a NonModal message. 627 // Create a NonModal message.
628 setWindowModality (Qt::NonModal); 628 setWindowModality (Qt::NonModal);
629 629
630 setWindowTitle (title.isEmpty () ? " " : title); 630 setWindowTitle (title.isEmpty () ? " " : title);
631 setDirectory (dirname); 631 setDirectory (dirname);
632 632
633 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. 633 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved.
634 resource_manager& rmgr = oct_qobj.get_resource_manager (); 634 resource_manager& rmgr = oct_qobj.get_resource_manager ();
635 gui_settings *settings = rmgr.get_settings (); 635 gui_settings *settings = rmgr.get_settings ();
636 if (! settings->value (global_use_native_dialogs).toBool ()) 636 if (! settings->value (global_use_native_dialogs).toBool ())
637 setOption(QFileDialog::DontUseNativeDialog); 637 setOption(QFileDialog::DontUseNativeDialog);
638 638
639 if (multimode == "on") // uigetfile multiselect=on 639 if (multimode == "on") // uigetfile multiselect=on
640 { 640 {
641 setFileMode (QFileDialog::ExistingFiles); 641 setFileMode (QFileDialog::ExistingFiles);
642 setAcceptMode (QFileDialog::AcceptOpen); 642 setAcceptMode (QFileDialog::AcceptOpen);
643 } 643 }
644 else if (multimode == "create") // uiputfile 644 else if (multimode == "create") // uiputfile
645 { 645 {
646 setFileMode (QFileDialog::AnyFile); 646 setFileMode (QFileDialog::AnyFile);
647 setAcceptMode (QFileDialog::AcceptSave); 647 setAcceptMode (QFileDialog::AcceptSave);
648 setOption (QFileDialog::DontConfirmOverwrite, false); 648 setOption (QFileDialog::DontConfirmOverwrite, false);
649 } 649 }
650 else if (multimode == "dir") // uigetdir 650 else if (multimode == "dir") // uigetdir
651 { 651 {
652 setFileMode (QFileDialog::Directory); 652 setFileMode (QFileDialog::Directory);
653 setOption (QFileDialog::ShowDirsOnly, true); 653 setOption (QFileDialog::ShowDirsOnly, true);
654 setOption (QFileDialog::HideNameFilterDetails, true); 654 setOption (QFileDialog::HideNameFilterDetails, true);
655 setAcceptMode (QFileDialog::AcceptOpen); 655 setAcceptMode (QFileDialog::AcceptOpen);
656 } 656 }
657 else // uigetfile multiselect=off 657 else // uigetfile multiselect=off
658 { 658 {
659 setFileMode (QFileDialog::ExistingFile); 659 setFileMode (QFileDialog::ExistingFile);
660 setAcceptMode (QFileDialog::AcceptOpen); 660 setAcceptMode (QFileDialog::AcceptOpen);
661 } 661 }
662 662
663 setNameFilters (name_filters); 663 setNameFilters (name_filters);
664 664
665 selectFile (filename); 665 selectFile (filename);
666 666
667 connect (this, &FileDialog::accepted, this, &FileDialog::acceptSelection); 667 connect (this, &FileDialog::accepted, this, &FileDialog::acceptSelection);
668 668
669 connect (this, &FileDialog::rejected, this, &FileDialog::rejectSelection); 669 connect (this, &FileDialog::rejected, this, &FileDialog::rejectSelection);
670 } 670 }
671 671
672 void FileDialog::rejectSelection (void) 672 void FileDialog::rejectSelection (void)
673 { 673 {
674 QStringList empty; 674 QStringList empty;
675 emit finish_input (empty, "", 0); 675 emit finish_input (empty, "", 0);
676 } 676 }
677 677
678 void FileDialog::acceptSelection (void) 678 void FileDialog::acceptSelection (void)
679 { 679 {
680 QStringList string_result; 680 QStringList string_result;
681 QString path; 681 QString path;
682 int idx = 1; 682 int idx = 1;
683 683
684 string_result = selectedFiles (); 684 string_result = selectedFiles ();
685 685
686 if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0) 686 if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0)
687 path = string_result[0]; 687 path = string_result[0];
688 else 688 else
689 path = directory ().absolutePath (); 689 path = directory ().absolutePath ();
690 690
691 // Matlab expects just the filename, whereas the file dialog gave us 691 // Matlab expects just the filename, whereas the file dialog gave us
692 // full path names, so fix it. 692 // full path names, so fix it.
693 693
694 for (int i = 0; i < string_result.size (); i++) 694 for (int i = 0; i < string_result.size (); i++)
695 string_result[i] = QFileInfo (string_result[i]).fileName (); 695 string_result[i] = QFileInfo (string_result[i]).fileName ();
696 696
697 // If not showing only dirs, add end slash for the path component. 697 // If not showing only dirs, add end slash for the path component.
698 if (testOption (QFileDialog::ShowDirsOnly) == false) 698 if (testOption (QFileDialog::ShowDirsOnly) == false)
699 path += '/'; 699 path += '/';
700 700
701 // Convert to native slashes. 701 // Convert to native slashes.
702 path = QDir::toNativeSeparators (path); 702 path = QDir::toNativeSeparators (path);
703 703
704 QStringList name_filters = nameFilters (); 704 QStringList name_filters = nameFilters ();
705 idx = name_filters.indexOf (selectedNameFilter ()) + 1; 705 idx = name_filters.indexOf (selectedNameFilter ()) + 1;
706 706
707 // Send the selected info. 707 // Send the selected info.
708 emit finish_input (string_result, path, idx); 708 emit finish_input (string_result, path, idx);
709 } 709 }
710 710
711 OCTAVE_END_NAMESPACE(octave) 711 OCTAVE_END_NAMESPACE(octave)