comparison libgui/src/dialog.h @ 16512:7f2395651a1c

dialog boxes with Qt widgets * dialog.h, dialog.cc: New files. * libgui/src/module.mk: Update file lists. * main-window.h, main-window.ccmain_window::connect_uiwidget_links, main_window::handle_create_dialog, main_window::handle_create_listview, main_window::handle_create_inputlayout): New functions. (main_window::construct): Call connect_uiwidget_links. * octave-link.h, octave-link.cc (octave_link::message_dialog, octave_link::do_message_dialog, octave_link::list_dialog, octave_link::do_list_dialog, octave_link::input_dialog, octave_link::do_input_dialog): New functions. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::message_dialog, octave_qt_link::do_message_dialog, octave_qt_link::list_dialog, octave_qt_link::do_list_dialog, octave_qt_link::input_dialog, octave_qt_link::do_input_dialog, make_qstring_list): New functions. * octave-link.cc (F__octave_link_edit_file__): Call flush_octave_stdout before running the edit file action. (F__octave_link_message_dialog__, F__octave_link_list_dialog__, __octave_link_input_dialog__): New functions. * errordlg.m, helpdlg.m, inputdlg.m, listdlg.m, msgbox.m, warndlg.m: New demos adapted from dlgtest.m * dlgtest.m: Delete. * scripts/java/module.mk: Remove it from the list of files. * inputdlg.m: Try __octave_link_input_dialog__ first. Only try java method if JAVA feature is available. * listdlg.m: Likwise, for __octave_link_list_dialog__. * private/message_dialog.m: Likewise, for __octave_link_message_dialog__.
author Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
date Sat, 13 Apr 2013 15:22:34 -0400
parents
children 3cd80afc3509
comparison
equal deleted inserted replaced
16511:eee1b78d031f 16512:7f2395651a1c
1 /*
2
3 Copyright (C) 2013 John W. Eaton
4 Copyright (C) 2013 Daniel J. Sebald
5
6 This file is part of Octave.
7
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21
22 */
23
24 #if !defined (octave_guifcn_dialog_h)
25 #define octave_guifcn_dialog_h 1
26
27 #include <QMutex>
28 #include <QWaitCondition>
29 #include <QAbstractButton>
30 #include <QList>
31 #include <QItemSelectionModel>
32 #include <QDialog>
33 #include <QMessageBox>
34 #include <QLineEdit>
35
36 // Defined for purposes of sending QList<int> as part of signal.
37 typedef QList<int> QIntList;
38
39 // Defined for purposes of sending QList<float> as part of signal.
40 typedef QList<float> QFloatList;
41
42
43 class QUIWidgetCreator : public QObject
44 {
45 Q_OBJECT
46
47 public:
48
49 QUIWidgetCreator (void);
50
51 ~QUIWidgetCreator (void);
52
53 public:
54
55 void signal_dialog (const QString& message, const QString& title,
56 const QString& icon, const QStringList& button,
57 const QString& defbutton, const QStringList& role)
58 {
59
60 // Use the last button in the list as the reject result, i.e., when no
61 // button is pressed such as in the case of <esc> and close button.
62 if (!button.isEmpty ())
63 dialog_button = button.last ();
64
65 QString xicon = icon;
66 if (xicon.isEmpty ())
67 xicon = "none";
68
69 emit create_dialog (message, title, xicon, button, defbutton, role);
70 };
71
72 int get_dialog_result (void) { return dialog_result; }
73
74 const QString *get_dialog_button (void) { return &dialog_button; }
75
76 bool signal_listview (const QStringList& list, const QString& mode,
77 int wd, int ht, const QList<int>& initial,
78 const QString& name, const QString& prompt_string,
79 const QString& ok_string, const QString& cancel_string)
80 {
81 if (list.isEmpty ())
82 return false;
83
84 emit create_listview (list, mode, wd, ht, initial, name,
85 prompt_string, ok_string, cancel_string);
86
87 return true;
88 };
89
90 const QIntList *get_list_index (void) { return list_index; }
91
92 bool signal_inputlayout (const QStringList& prompt, const QString& title,
93 const QIntList& nr, const QIntList& nc,
94 const QStringList& defaults)
95 {
96 if (prompt.isEmpty ())
97 return false;
98
99 emit create_inputlayout (prompt, title, nr, nc, defaults);
100
101 return true;
102 };
103
104 const QStringList *get_string_list (void) { return string_list; }
105
106 void wait (void)
107 {
108 // Wait while the user is responding to message box.
109 waitcondition.wait (&mutex);
110 }
111
112 signals:
113
114 void create_dialog (const QString&, const QString&, const QString&,
115 const QStringList&, const QString&, const QStringList&);
116
117 void create_listview (const QStringList&, const QString&, int, int,
118 const QIntList&, const QString&, const QString&,
119 const QString&, const QString&);
120
121 void create_inputlayout (const QStringList&, const QString&,
122 const QIntList&, const QIntList&,
123 const QStringList&);
124
125 public slots:
126
127 void dialog_finished (int result);
128
129 void dialog_button_clicked (QAbstractButton *button);
130
131 void list_select_finished (const QIntList& selected,
132 const int button_pressed);
133
134 void input_finished (const QStringList& input, const int button_pressed);
135
136 private:
137
138 int dialog_result;
139 QString dialog_button;
140
141 // The list could conceivably be big. Not sure how things are
142 // stored internally, so keep off of the stack.
143 QStringList *string_list;
144 QIntList *list_index;
145
146 // GUI objects cannot be accessed in the non-GUI thread. However,
147 // signals can be sent to slots across threads with proper
148 // synchronization. Hence, the use of QWaitCondition.
149
150 QMutex mutex;
151
152 QWaitCondition waitcondition;
153 };
154
155 extern QUIWidgetCreator uiwidget_creator;
156
157 class MessageDialog : public QMessageBox
158 {
159 Q_OBJECT
160
161 public:
162
163 explicit MessageDialog (const QString& message, const QString& title,
164 const QString& icon, const QStringList& button,
165 const QString& defbutton,
166 const QStringList& role);
167 };
168
169
170 class ListDialog : public QDialog
171 {
172 Q_OBJECT
173
174 QItemSelectionModel *selector;
175
176 public:
177
178 explicit ListDialog (const QStringList& list, const QString& mode,
179 int width, int height, const QList<int>& initial,
180 const QString& name, const QString& prompt_string,
181 const QString& ok_string, const QString& cancel_string);
182
183 signals:
184
185 void finish_selection (const QIntList&, const int);
186
187 public slots:
188
189 void buttonOk_clicked (void);
190
191 void buttonCancel_clicked (void);
192
193 void reject (void);
194 };
195
196
197 class InputDialog : public QDialog
198 {
199 Q_OBJECT
200
201 QList<QLineEdit *> input_line;
202
203 public:
204
205 explicit InputDialog (const QStringList& prompt, const QString& title,
206 const QIntList& nr, const QIntList& nc,
207 const QStringList& defaults);
208
209 signals:
210
211 void finish_input (const QStringList&, const int);
212
213 public slots:
214
215 void buttonOk_clicked (void);
216
217 void buttonCancel_clicked (void);
218
219 void reject (void);
220 };
221
222 #endif