143
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the examples of the Qt Toolkit.
|
|
7 **
|
|
8 ** $QT_BEGIN_LICENSE:LGPL$
|
|
9 ** Commercial Usage
|
|
10 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
11 ** accordance with the Qt Commercial License Agreement provided with the
|
|
12 ** Software or, alternatively, in accordance with the terms contained in
|
|
13 ** a written agreement between you and Nokia.
|
|
14 **
|
|
15 ** GNU Lesser General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
17 ** General Public License version 2.1 as published by the Free Software
|
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
19 ** packaging of this file. Please review the following information to
|
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
22 **
|
|
23 ** In addition, as a special exception, Nokia gives you certain
|
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL
|
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|
26 ** package.
|
|
27 **
|
|
28 ** GNU General Public License Usage
|
|
29 ** Alternatively, this file may be used under the terms of the GNU
|
|
30 ** General Public License version 3.0 as published by the Free Software
|
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the
|
|
32 ** packaging of this file. Please review the following information to
|
|
33 ** ensure the GNU General Public License version 3.0 requirements will be
|
|
34 ** met: http://www.gnu.org/copyleft/gpl.html.
|
|
35 **
|
|
36 ** If you are unsure which license is appropriate for your use, please
|
|
37 ** contact the sales department at qt-sales@nokia.com.
|
|
38 ** $QT_END_LICENSE$
|
|
39 **
|
|
40 ****************************************************************************/
|
|
41 module dialog;
|
|
42
|
|
43
|
|
44 import qt.gui.QDialog;
|
|
45 import qt.gui.QCheckBox;
|
|
46 import qt.gui.QLabel;
|
|
47 import qt.gui.QMessageBox;
|
|
48 import qt.gui.QGridLayout;
|
|
49 import qt.gui.QErrorMessage;
|
|
50 import qt.gui.QFileDialog;
|
|
51 import qt.gui.QLineEdit;
|
|
52 import qt.gui.QInputDialog;
|
|
53 import qt.gui.QColorDialog;
|
|
54 import qt.gui.QFontDialog;
|
|
55 import qt.gui.QFileDialog;
|
|
56 import qt.core.QFile;
|
|
57
|
|
58 import tango.text.convert.Format;
|
|
59
|
|
60
|
|
61 char[] MESSAGE = tr("<p>Message boxes have a caption, a text, "
|
|
62 "and any number of buttons, each with standard or custom texts."
|
|
63 "<p>Click a button to close the message box. Pressing the Esc button "
|
|
64 "will activate the detected escape button (if any).");
|
|
65
|
|
66
|
|
67 class Dialog : public QDialog
|
|
68 {
|
|
69 public:
|
|
70
|
|
71 this(QWidget parent = null)
|
|
72 {
|
|
73 super(parent);
|
|
74 errorMessageDialog = new QErrorMessage(this);
|
|
75
|
|
76 int frameStyle = QFrame.Sunken | QFrame.Panel;
|
|
77
|
|
78 integerLabel = new QLabel;
|
|
79 integerLabel.setFrameStyle(frameStyle);
|
|
80 QPushButton integerButton = new QPushButton(tr("QInputget&Int()"));
|
|
81
|
|
82 doubleLabel = new QLabel;
|
|
83 doubleLabel.setFrameStyle(frameStyle);
|
|
84 QPushButton doubleButton = new QPushButton(tr("QInputget&Double()"));
|
|
85
|
|
86 itemLabel = new QLabel;
|
|
87 itemLabel.setFrameStyle(frameStyle);
|
|
88 QPushButton itemButton = new QPushButton(tr("QInputgetIte&m()"));
|
|
89
|
|
90 textLabel = new QLabel;
|
|
91 textLabel.setFrameStyle(frameStyle);
|
|
92 QPushButton textButton = new QPushButton(tr("QInputget&Text()"));
|
|
93
|
|
94 colorLabel = new QLabel;
|
|
95 colorLabel.setFrameStyle(frameStyle);
|
|
96 QPushButton colorButton = new QPushButton(tr("QColorget&Color()"));
|
|
97
|
|
98 fontLabel = new QLabel;
|
|
99 fontLabel.setFrameStyle(frameStyle);
|
|
100 QPushButton fontButton = new QPushButton(tr("QFontget&Font()"));
|
|
101
|
|
102 directoryLabel = new QLabel;
|
|
103 directoryLabel.setFrameStyle(frameStyle);
|
|
104 QPushButton directoryButton = new QPushButton(tr("QFilegetE&xistingDirectory()"));
|
|
105
|
|
106 openFileNameLabel = new QLabel;
|
|
107 openFileNameLabel.setFrameStyle(frameStyle);
|
|
108 QPushButton openFileNameButton = new QPushButton(tr("QFileget&OpenFileName()"));
|
|
109
|
|
110 openFileNamesLabel = new QLabel;
|
|
111 openFileNamesLabel.setFrameStyle(frameStyle);
|
|
112 QPushButton openFileNamesButton = new QPushButton(tr("QFile&getOpenFileNames()"));
|
|
113
|
|
114 saveFileNameLabel = new QLabel;
|
|
115 saveFileNameLabel.setFrameStyle(frameStyle);
|
|
116 QPushButton saveFileNameButton = new QPushButton(tr("QFileget&SaveFileName()"));
|
|
117
|
|
118 criticalLabel = new QLabel;
|
|
119 criticalLabel.setFrameStyle(frameStyle);
|
|
120 QPushButton criticalButton = new QPushButton(tr("QMessageBox.critica&l()"));
|
|
121
|
|
122 informationLabel = new QLabel;
|
|
123 informationLabel.setFrameStyle(frameStyle);
|
|
124 QPushButton informationButton = new QPushButton(tr("QMessageBox.i&nformation()"));
|
|
125
|
|
126 questionLabel = new QLabel;
|
|
127 questionLabel.setFrameStyle(frameStyle);
|
|
128 QPushButton questionButton = new QPushButton(tr("QMessageBox.&question()"));
|
|
129
|
|
130 warningLabel = new QLabel;
|
|
131 warningLabel.setFrameStyle(frameStyle);
|
|
132 QPushButton warningButton = new QPushButton(tr("QMessageBox.&warning()"));
|
|
133
|
|
134 errorLabel = new QLabel;
|
|
135 errorLabel.setFrameStyle(frameStyle);
|
|
136 QPushButton errorButton = new QPushButton(tr("QErrorMessage.show&M&essage()"));
|
|
137
|
|
138 integerButton.clicked.connect(&this.setInteger);
|
|
139 doubleButton.clicked.connect(&this.setDouble);
|
|
140 itemButton.clicked.connect(&this.setItem);
|
|
141 textButton.clicked.connect(&this.setText);
|
|
142 colorButton.clicked.connect(&this.setColor);
|
|
143 fontButton.clicked.connect(&this.setFont);
|
|
144 directoryButton.clicked.connect(&this.setExistingDirectory);
|
|
145 openFileNameButton.clicked.connect(&this.setOpenFileName);
|
|
146 openFileNamesButton.clicked.connect(&this.setOpenFileNames);
|
|
147 saveFileNameButton.clicked.connect(&this.setSaveFileName);
|
|
148 criticalButton.clicked.connect(&this.criticalMessage);
|
|
149 informationButton.clicked.connect(&this.informationMessage);
|
|
150 questionButton.clicked.connect(&this.questionMessage);
|
|
151 warningButton.clicked.connect(&this.warningMessage);
|
|
152 errorButton.clicked.connect(&this.errorMessage);
|
|
153
|
|
154 native = new QCheckBox(this);
|
|
155 native.setText("Use native file dialog.");
|
|
156 native.setChecked(true);
|
|
157
|
|
158 version(windows) {} else
|
|
159 {
|
|
160 version(mac) {} else
|
|
161 {
|
|
162 native.hide();
|
|
163 }
|
|
164 }
|
|
165
|
|
166 QGridLayout layout = new QGridLayout;
|
|
167 layout.setColumnStretch(1, 1);
|
|
168 layout.setColumnMinimumWidth(1, 250);
|
|
169 layout.addWidget(integerButton, 0, 0);
|
|
170 layout.addWidget(integerLabel, 0, 1);
|
|
171 layout.addWidget(doubleButton, 1, 0);
|
|
172 layout.addWidget(doubleLabel, 1, 1);
|
|
173 layout.addWidget(itemButton, 2, 0);
|
|
174 layout.addWidget(itemLabel, 2, 1);
|
|
175 layout.addWidget(textButton, 3, 0);
|
|
176 layout.addWidget(textLabel, 3, 1);
|
|
177 layout.addWidget(colorButton, 4, 0);
|
|
178 layout.addWidget(colorLabel, 4, 1);
|
|
179 layout.addWidget(fontButton, 5, 0);
|
|
180 layout.addWidget(fontLabel, 5, 1);
|
|
181 layout.addWidget(directoryButton, 6, 0);
|
|
182 layout.addWidget(directoryLabel, 6, 1);
|
|
183 layout.addWidget(openFileNameButton, 7, 0);
|
|
184 layout.addWidget(openFileNameLabel, 7, 1);
|
|
185 layout.addWidget(openFileNamesButton, 8, 0);
|
|
186 layout.addWidget(openFileNamesLabel, 8, 1);
|
|
187 layout.addWidget(saveFileNameButton, 9, 0);
|
|
188 layout.addWidget(saveFileNameLabel, 9, 1);
|
|
189 layout.addWidget(criticalButton, 10, 0);
|
|
190 layout.addWidget(criticalLabel, 10, 1);
|
|
191 layout.addWidget(informationButton, 11, 0);
|
|
192 layout.addWidget(informationLabel, 11, 1);
|
|
193 layout.addWidget(questionButton, 12, 0);
|
|
194 layout.addWidget(questionLabel, 12, 1);
|
|
195 layout.addWidget(warningButton, 13, 0);
|
|
196 layout.addWidget(warningLabel, 13, 1);
|
|
197 layout.addWidget(errorButton, 14, 0);
|
|
198 layout.addWidget(errorLabel, 14, 1);
|
|
199 layout.addWidget(native, 15, 0);
|
|
200 setLayout(layout);
|
|
201
|
|
202 setWindowTitle(tr("Standard Dialogs"));
|
|
203 }
|
|
204
|
|
205 private:
|
|
206
|
|
207 void setInteger()
|
|
208 {
|
|
209 bool ok;
|
|
210 int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok);
|
|
211 if (ok)
|
|
212 integerLabel.setText(Format(tr("%"), i));
|
|
213 }
|
|
214
|
|
215 void setDouble()
|
|
216 {
|
|
217 bool ok;
|
|
218 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"),
|
|
219 tr("Amount:"), 37.56, -10000, 10000, 2, ok);
|
|
220 if (ok)
|
|
221 doubleLabel.setText(Format("${}", d));
|
|
222 }
|
|
223
|
|
224 void setItem()
|
|
225 {
|
|
226 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")];
|
|
227
|
|
228 bool ok;
|
|
229 string item = QInputDialog.getItem(this, tr("QInputgetItem()"),
|
|
230 tr("Season:"), items, 0, false, ok);
|
|
231 if (ok && item.length)
|
|
232 itemLabel.setText(item);
|
|
233 }
|
|
234
|
|
235 void setText()
|
|
236 {
|
|
237 bool ok;
|
|
238 string text = QInputDialog.getText(this, tr("QInputgetText()"),
|
|
239 tr("User name:"), QLineEdit_EchoMode.Normal,
|
|
240 QDir.home().dirName(), ok);
|
|
241 if (ok && text.length)
|
|
242 textLabel.setText(text);
|
|
243 }
|
|
244
|
|
245 void setColor()
|
|
246 {
|
|
247 QColor color = QColorDialog.getColor(QColor.Green, this);
|
|
248 if (color.isValid()) {
|
|
249 colorLabel.setText(color.name());
|
|
250 colorLabel.setPalette(new QPalette(color));
|
|
251 colorLabel.setAutoFillBackground(true);
|
|
252 }
|
|
253 }
|
|
254
|
|
255 void setFont()
|
|
256 {
|
|
257 bool ok;
|
|
258 QFont font = QFontDialog.getFont(&ok, new QFont(fontLabel.text()), this);
|
|
259 if (ok) {
|
|
260 fontLabel.setText(font.key());
|
|
261 fontLabel.setFont(font);
|
|
262 }
|
|
263 }
|
|
264
|
|
265 void setExistingDirectory()
|
|
266 {
|
|
267 int options = QFileDialog_Option.DontResolveSymlinks | QFileDialog_Option.ShowDirsOnly;
|
|
268 if (!native.isChecked())
|
|
269 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
270 string directory = QFileDialog.getExistingDirectory(this,
|
|
271 tr("QFilegetExistingDirectory()"),
|
|
272 directoryLabel.text(),
|
|
273 options);
|
|
274 if (directory.length)
|
|
275 directoryLabel.setText(directory);
|
|
276 }
|
|
277
|
|
278 void setOpenFileName()
|
|
279 {
|
|
280 int options;
|
|
281 if (!native.isChecked())
|
|
282 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
283 string selectedFilter;
|
|
284 string fileName = QFileDialog.getOpenFileName(this,
|
|
285 tr("QFilegetOpenFileName()"),
|
|
286 openFileNameLabel.text(),
|
|
287 tr("All Files (*);;Text Files (*.txt)"),
|
|
288 selectedFilter,
|
|
289 options);
|
|
290 if (fileName.length)
|
|
291 openFileNameLabel.setText(fileName);
|
|
292 }
|
|
293
|
|
294 void setOpenFileNames()
|
|
295 {
|
|
296 int options;
|
|
297 if (!native.isChecked())
|
|
298 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
299 string selectedFilter;
|
|
300 string[] files = QFileDialog.getOpenFileNames(
|
|
301 this, tr("QFilegetOpenFileNames()"),
|
|
302 openFilesPath,
|
|
303 tr("All Files (*);;Text Files (*.txt)"),
|
|
304 selectedFilter,
|
|
305 options);
|
|
306 if (files.length) {
|
|
307 openFilesPath = files[0];
|
|
308 openFileNamesLabel.setText(Format("{}", files));
|
|
309 }
|
|
310 }
|
|
311
|
|
312 void setSaveFileName()
|
|
313 {
|
|
314 int options;
|
|
315 if (!native.isChecked())
|
|
316 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
317 string selectedFilter;
|
|
318 string fileName = QFileDialog.getSaveFileName(this,
|
|
319 tr("QFilegetSaveFileName()"),
|
|
320 saveFileNameLabel.text(),
|
|
321 tr("All Files (*);;Text Files (*.txt)"),
|
|
322 selectedFilter,
|
|
323 options);
|
|
324 if (fileName.length)
|
|
325 saveFileNameLabel.setText(fileName);
|
|
326 }
|
|
327
|
|
328 void criticalMessage()
|
|
329 {
|
|
330 QMessageBox.StandardButton reply;
|
|
331 reply = QMessageBox.critical(this, tr("QMessageBox.critical()"),
|
|
332 MESSAGE,
|
|
333 QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore);
|
|
334 if (reply == QMessageBox.Abort)
|
|
335 criticalLabel.setText(tr("Abort"));
|
|
336 else if (reply == QMessageBox.Retry)
|
|
337 criticalLabel.setText(tr("Retry"));
|
|
338 else
|
|
339 criticalLabel.setText(tr("Ignore"));
|
|
340 }
|
|
341
|
|
342 void informationMessage()
|
|
343 {
|
|
344 QMessageBox.StandardButton reply;
|
|
345 reply = QMessageBox.information(this, tr("QMessageBox.information()"), MESSAGE);
|
|
346 if (reply == QMessageBox.Ok)
|
|
347 informationLabel.setText(tr("OK"));
|
|
348 else
|
|
349 informationLabel.setText(tr("Escape"));
|
|
350 }
|
|
351
|
|
352 void questionMessage()
|
|
353 {
|
|
354 QMessageBox.StandardButton reply;
|
|
355 reply = QMessageBox.question(this, tr("QMessageBox.question()"),
|
|
356 MESSAGE,
|
|
357 QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel);
|
|
358 if (reply == QMessageBox.Yes)
|
|
359 questionLabel.setText(tr("Yes"));
|
|
360 else if (reply == QMessageBox.No)
|
|
361 questionLabel.setText(tr("No"));
|
|
362 else
|
|
363 questionLabel.setText(tr("Cancel"));
|
|
364 }
|
|
365
|
|
366 void warningMessage()
|
|
367 {
|
|
368 auto msgBox = new QMessageBox(QMessageBox.Warning, tr("QMessageBox.warning()"), MESSAGE, 0, this);
|
|
369 msgBox.addButton(tr("Save &Again"), QMessageBox.AcceptRole);
|
|
370 msgBox.addButton(tr("&Continue"), QMessageBox.RejectRole);
|
|
371 if (msgBox.exec() == QMessageBox.AcceptRole)
|
|
372 warningLabel.setText(tr("Save Again"));
|
|
373 else
|
|
374 warningLabel.setText(tr("Continue"));
|
|
375 }
|
|
376
|
|
377 void errorMessage()
|
|
378 {
|
|
379 errorMessageDialog.showMessage(
|
|
380 tr("This dialog shows and remembers error messages. "
|
|
381 "If the checkbox is checked (as it is by default), "
|
|
382 "the shown message will be shown again, "
|
|
383 "but if the user unchecks the box the message "
|
|
384 "will not appear again if QErrorMessage.showMessage() "
|
|
385 "is called with the same message."));
|
|
386 errorLabel.setText(tr("If the box is unchecked, the message won't appear again."));
|
|
387 }
|
|
388
|
|
389 private:
|
|
390
|
|
391 QCheckBox native;
|
|
392 QLabel integerLabel;
|
|
393 QLabel doubleLabel;
|
|
394 QLabel itemLabel;
|
|
395 QLabel textLabel;
|
|
396 QLabel colorLabel;
|
|
397 QLabel fontLabel;
|
|
398 QLabel directoryLabel;
|
|
399 QLabel openFileNameLabel;
|
|
400 QLabel openFileNamesLabel;
|
|
401 QLabel saveFileNameLabel;
|
|
402 QLabel criticalLabel;
|
|
403 QLabel informationLabel;
|
|
404 QLabel questionLabel;
|
|
405 QLabel warningLabel;
|
|
406 QLabel errorLabel;
|
|
407 QErrorMessage errorMessageDialog;
|
|
408
|
|
409 char[] openFilesPath;
|
|
410 }
|