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
|
211
|
58 version(Tango)
|
|
59 import tango.text.convert.Format;
|
|
60 else
|
|
61 import std.string;
|
143
|
62
|
|
63
|
211
|
64 string MESSAGE = tr("<p>Message boxes have a caption, a text, "
|
143
|
65 "and any number of buttons, each with standard or custom texts."
|
|
66 "<p>Click a button to close the message box. Pressing the Esc button "
|
|
67 "will activate the detected escape button (if any).");
|
|
68
|
|
69
|
|
70 class Dialog : public QDialog
|
|
71 {
|
|
72 public:
|
|
73
|
|
74 this(QWidget parent = null)
|
|
75 {
|
|
76 super(parent);
|
|
77 errorMessageDialog = new QErrorMessage(this);
|
|
78
|
|
79 int frameStyle = QFrame.Sunken | QFrame.Panel;
|
|
80
|
|
81 integerLabel = new QLabel;
|
|
82 integerLabel.setFrameStyle(frameStyle);
|
|
83 QPushButton integerButton = new QPushButton(tr("QInputget&Int()"));
|
|
84
|
|
85 doubleLabel = new QLabel;
|
|
86 doubleLabel.setFrameStyle(frameStyle);
|
|
87 QPushButton doubleButton = new QPushButton(tr("QInputget&Double()"));
|
|
88
|
|
89 itemLabel = new QLabel;
|
|
90 itemLabel.setFrameStyle(frameStyle);
|
|
91 QPushButton itemButton = new QPushButton(tr("QInputgetIte&m()"));
|
|
92
|
|
93 textLabel = new QLabel;
|
|
94 textLabel.setFrameStyle(frameStyle);
|
|
95 QPushButton textButton = new QPushButton(tr("QInputget&Text()"));
|
|
96
|
|
97 colorLabel = new QLabel;
|
|
98 colorLabel.setFrameStyle(frameStyle);
|
|
99 QPushButton colorButton = new QPushButton(tr("QColorget&Color()"));
|
|
100
|
|
101 fontLabel = new QLabel;
|
|
102 fontLabel.setFrameStyle(frameStyle);
|
|
103 QPushButton fontButton = new QPushButton(tr("QFontget&Font()"));
|
|
104
|
|
105 directoryLabel = new QLabel;
|
|
106 directoryLabel.setFrameStyle(frameStyle);
|
|
107 QPushButton directoryButton = new QPushButton(tr("QFilegetE&xistingDirectory()"));
|
|
108
|
|
109 openFileNameLabel = new QLabel;
|
|
110 openFileNameLabel.setFrameStyle(frameStyle);
|
|
111 QPushButton openFileNameButton = new QPushButton(tr("QFileget&OpenFileName()"));
|
|
112
|
|
113 openFileNamesLabel = new QLabel;
|
|
114 openFileNamesLabel.setFrameStyle(frameStyle);
|
|
115 QPushButton openFileNamesButton = new QPushButton(tr("QFile&getOpenFileNames()"));
|
|
116
|
|
117 saveFileNameLabel = new QLabel;
|
|
118 saveFileNameLabel.setFrameStyle(frameStyle);
|
|
119 QPushButton saveFileNameButton = new QPushButton(tr("QFileget&SaveFileName()"));
|
|
120
|
|
121 criticalLabel = new QLabel;
|
|
122 criticalLabel.setFrameStyle(frameStyle);
|
|
123 QPushButton criticalButton = new QPushButton(tr("QMessageBox.critica&l()"));
|
|
124
|
|
125 informationLabel = new QLabel;
|
|
126 informationLabel.setFrameStyle(frameStyle);
|
|
127 QPushButton informationButton = new QPushButton(tr("QMessageBox.i&nformation()"));
|
|
128
|
|
129 questionLabel = new QLabel;
|
|
130 questionLabel.setFrameStyle(frameStyle);
|
|
131 QPushButton questionButton = new QPushButton(tr("QMessageBox.&question()"));
|
|
132
|
|
133 warningLabel = new QLabel;
|
|
134 warningLabel.setFrameStyle(frameStyle);
|
|
135 QPushButton warningButton = new QPushButton(tr("QMessageBox.&warning()"));
|
|
136
|
|
137 errorLabel = new QLabel;
|
|
138 errorLabel.setFrameStyle(frameStyle);
|
|
139 QPushButton errorButton = new QPushButton(tr("QErrorMessage.show&M&essage()"));
|
|
140
|
|
141 integerButton.clicked.connect(&this.setInteger);
|
|
142 doubleButton.clicked.connect(&this.setDouble);
|
|
143 itemButton.clicked.connect(&this.setItem);
|
|
144 textButton.clicked.connect(&this.setText);
|
|
145 colorButton.clicked.connect(&this.setColor);
|
|
146 fontButton.clicked.connect(&this.setFont);
|
|
147 directoryButton.clicked.connect(&this.setExistingDirectory);
|
|
148 openFileNameButton.clicked.connect(&this.setOpenFileName);
|
|
149 openFileNamesButton.clicked.connect(&this.setOpenFileNames);
|
|
150 saveFileNameButton.clicked.connect(&this.setSaveFileName);
|
|
151 criticalButton.clicked.connect(&this.criticalMessage);
|
|
152 informationButton.clicked.connect(&this.informationMessage);
|
|
153 questionButton.clicked.connect(&this.questionMessage);
|
|
154 warningButton.clicked.connect(&this.warningMessage);
|
|
155 errorButton.clicked.connect(&this.errorMessage);
|
|
156
|
|
157 native = new QCheckBox(this);
|
|
158 native.setText("Use native file dialog.");
|
|
159 native.setChecked(true);
|
|
160
|
|
161 version(windows) {} else
|
|
162 {
|
|
163 version(mac) {} else
|
|
164 {
|
|
165 native.hide();
|
|
166 }
|
|
167 }
|
|
168
|
|
169 QGridLayout layout = new QGridLayout;
|
|
170 layout.setColumnStretch(1, 1);
|
|
171 layout.setColumnMinimumWidth(1, 250);
|
|
172 layout.addWidget(integerButton, 0, 0);
|
|
173 layout.addWidget(integerLabel, 0, 1);
|
|
174 layout.addWidget(doubleButton, 1, 0);
|
|
175 layout.addWidget(doubleLabel, 1, 1);
|
|
176 layout.addWidget(itemButton, 2, 0);
|
|
177 layout.addWidget(itemLabel, 2, 1);
|
|
178 layout.addWidget(textButton, 3, 0);
|
|
179 layout.addWidget(textLabel, 3, 1);
|
|
180 layout.addWidget(colorButton, 4, 0);
|
|
181 layout.addWidget(colorLabel, 4, 1);
|
|
182 layout.addWidget(fontButton, 5, 0);
|
|
183 layout.addWidget(fontLabel, 5, 1);
|
|
184 layout.addWidget(directoryButton, 6, 0);
|
|
185 layout.addWidget(directoryLabel, 6, 1);
|
|
186 layout.addWidget(openFileNameButton, 7, 0);
|
|
187 layout.addWidget(openFileNameLabel, 7, 1);
|
|
188 layout.addWidget(openFileNamesButton, 8, 0);
|
|
189 layout.addWidget(openFileNamesLabel, 8, 1);
|
|
190 layout.addWidget(saveFileNameButton, 9, 0);
|
|
191 layout.addWidget(saveFileNameLabel, 9, 1);
|
|
192 layout.addWidget(criticalButton, 10, 0);
|
|
193 layout.addWidget(criticalLabel, 10, 1);
|
|
194 layout.addWidget(informationButton, 11, 0);
|
|
195 layout.addWidget(informationLabel, 11, 1);
|
|
196 layout.addWidget(questionButton, 12, 0);
|
|
197 layout.addWidget(questionLabel, 12, 1);
|
|
198 layout.addWidget(warningButton, 13, 0);
|
|
199 layout.addWidget(warningLabel, 13, 1);
|
|
200 layout.addWidget(errorButton, 14, 0);
|
|
201 layout.addWidget(errorLabel, 14, 1);
|
|
202 layout.addWidget(native, 15, 0);
|
|
203 setLayout(layout);
|
|
204
|
|
205 setWindowTitle(tr("Standard Dialogs"));
|
|
206 }
|
|
207
|
|
208 private:
|
|
209
|
|
210 void setInteger()
|
|
211 {
|
|
212 bool ok;
|
|
213 int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok);
|
|
214 if (ok)
|
211
|
215 version(Tango)
|
|
216 integerLabel.setText(Format("{}", i));
|
|
217 else
|
|
218 integerLabel.setText(format("%d", i));
|
143
|
219 }
|
|
220
|
|
221 void setDouble()
|
|
222 {
|
|
223 bool ok;
|
|
224 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"),
|
|
225 tr("Amount:"), 37.56, -10000, 10000, 2, ok);
|
|
226 if (ok)
|
211
|
227 version(Tango)
|
|
228 doubleLabel.setText(Format("${}", d));
|
|
229 else
|
|
230 integerLabel.setText(format("%g", d));
|
143
|
231 }
|
|
232
|
|
233 void setItem()
|
|
234 {
|
|
235 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")];
|
|
236
|
|
237 bool ok;
|
|
238 string item = QInputDialog.getItem(this, tr("QInputgetItem()"),
|
|
239 tr("Season:"), items, 0, false, ok);
|
|
240 if (ok && item.length)
|
|
241 itemLabel.setText(item);
|
|
242 }
|
|
243
|
|
244 void setText()
|
|
245 {
|
|
246 bool ok;
|
|
247 string text = QInputDialog.getText(this, tr("QInputgetText()"),
|
|
248 tr("User name:"), QLineEdit_EchoMode.Normal,
|
|
249 QDir.home().dirName(), ok);
|
|
250 if (ok && text.length)
|
|
251 textLabel.setText(text);
|
|
252 }
|
|
253
|
|
254 void setColor()
|
|
255 {
|
|
256 QColor color = QColorDialog.getColor(QColor.Green, this);
|
|
257 if (color.isValid()) {
|
|
258 colorLabel.setText(color.name());
|
|
259 colorLabel.setPalette(new QPalette(color));
|
|
260 colorLabel.setAutoFillBackground(true);
|
|
261 }
|
|
262 }
|
|
263
|
|
264 void setFont()
|
|
265 {
|
|
266 bool ok;
|
|
267 QFont font = QFontDialog.getFont(&ok, new QFont(fontLabel.text()), this);
|
|
268 if (ok) {
|
|
269 fontLabel.setText(font.key());
|
|
270 fontLabel.setFont(font);
|
|
271 }
|
|
272 }
|
|
273
|
|
274 void setExistingDirectory()
|
|
275 {
|
|
276 int options = QFileDialog_Option.DontResolveSymlinks | QFileDialog_Option.ShowDirsOnly;
|
|
277 if (!native.isChecked())
|
|
278 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
279 string directory = QFileDialog.getExistingDirectory(this,
|
|
280 tr("QFilegetExistingDirectory()"),
|
|
281 directoryLabel.text(),
|
|
282 options);
|
|
283 if (directory.length)
|
|
284 directoryLabel.setText(directory);
|
|
285 }
|
|
286
|
|
287 void setOpenFileName()
|
|
288 {
|
|
289 int options;
|
|
290 if (!native.isChecked())
|
|
291 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
292 string selectedFilter;
|
|
293 string fileName = QFileDialog.getOpenFileName(this,
|
|
294 tr("QFilegetOpenFileName()"),
|
|
295 openFileNameLabel.text(),
|
|
296 tr("All Files (*);;Text Files (*.txt)"),
|
|
297 selectedFilter,
|
|
298 options);
|
|
299 if (fileName.length)
|
|
300 openFileNameLabel.setText(fileName);
|
|
301 }
|
|
302
|
|
303 void setOpenFileNames()
|
|
304 {
|
|
305 int options;
|
|
306 if (!native.isChecked())
|
|
307 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
308 string selectedFilter;
|
|
309 string[] files = QFileDialog.getOpenFileNames(
|
|
310 this, tr("QFilegetOpenFileNames()"),
|
|
311 openFilesPath,
|
|
312 tr("All Files (*);;Text Files (*.txt)"),
|
|
313 selectedFilter,
|
|
314 options);
|
|
315 if (files.length) {
|
|
316 openFilesPath = files[0];
|
211
|
317 version(Tango)
|
|
318 openFileNamesLabel.setText(Format("{}", files));
|
|
319 else
|
|
320 {
|
|
321 openFileNamesLabel.setText(join(files, "; "));
|
|
322 }
|
143
|
323 }
|
|
324 }
|
|
325
|
|
326 void setSaveFileName()
|
|
327 {
|
|
328 int options;
|
|
329 if (!native.isChecked())
|
|
330 options |= QFileDialog_Option.DontUseNativeDialog;
|
|
331 string selectedFilter;
|
|
332 string fileName = QFileDialog.getSaveFileName(this,
|
|
333 tr("QFilegetSaveFileName()"),
|
|
334 saveFileNameLabel.text(),
|
|
335 tr("All Files (*);;Text Files (*.txt)"),
|
|
336 selectedFilter,
|
|
337 options);
|
|
338 if (fileName.length)
|
|
339 saveFileNameLabel.setText(fileName);
|
|
340 }
|
|
341
|
|
342 void criticalMessage()
|
|
343 {
|
|
344 QMessageBox.StandardButton reply;
|
|
345 reply = QMessageBox.critical(this, tr("QMessageBox.critical()"),
|
|
346 MESSAGE,
|
|
347 QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore);
|
|
348 if (reply == QMessageBox.Abort)
|
|
349 criticalLabel.setText(tr("Abort"));
|
|
350 else if (reply == QMessageBox.Retry)
|
|
351 criticalLabel.setText(tr("Retry"));
|
|
352 else
|
|
353 criticalLabel.setText(tr("Ignore"));
|
|
354 }
|
|
355
|
|
356 void informationMessage()
|
|
357 {
|
|
358 QMessageBox.StandardButton reply;
|
|
359 reply = QMessageBox.information(this, tr("QMessageBox.information()"), MESSAGE);
|
|
360 if (reply == QMessageBox.Ok)
|
|
361 informationLabel.setText(tr("OK"));
|
|
362 else
|
|
363 informationLabel.setText(tr("Escape"));
|
|
364 }
|
|
365
|
|
366 void questionMessage()
|
|
367 {
|
|
368 QMessageBox.StandardButton reply;
|
|
369 reply = QMessageBox.question(this, tr("QMessageBox.question()"),
|
|
370 MESSAGE,
|
|
371 QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel);
|
|
372 if (reply == QMessageBox.Yes)
|
|
373 questionLabel.setText(tr("Yes"));
|
|
374 else if (reply == QMessageBox.No)
|
|
375 questionLabel.setText(tr("No"));
|
|
376 else
|
|
377 questionLabel.setText(tr("Cancel"));
|
|
378 }
|
|
379
|
|
380 void warningMessage()
|
|
381 {
|
|
382 auto msgBox = new QMessageBox(QMessageBox.Warning, tr("QMessageBox.warning()"), MESSAGE, 0, this);
|
|
383 msgBox.addButton(tr("Save &Again"), QMessageBox.AcceptRole);
|
|
384 msgBox.addButton(tr("&Continue"), QMessageBox.RejectRole);
|
|
385 if (msgBox.exec() == QMessageBox.AcceptRole)
|
|
386 warningLabel.setText(tr("Save Again"));
|
|
387 else
|
|
388 warningLabel.setText(tr("Continue"));
|
|
389 }
|
|
390
|
|
391 void errorMessage()
|
|
392 {
|
|
393 errorMessageDialog.showMessage(
|
|
394 tr("This dialog shows and remembers error messages. "
|
|
395 "If the checkbox is checked (as it is by default), "
|
|
396 "the shown message will be shown again, "
|
|
397 "but if the user unchecks the box the message "
|
|
398 "will not appear again if QErrorMessage.showMessage() "
|
|
399 "is called with the same message."));
|
|
400 errorLabel.setText(tr("If the box is unchecked, the message won't appear again."));
|
|
401 }
|
|
402
|
|
403 private:
|
|
404
|
|
405 QCheckBox native;
|
|
406 QLabel integerLabel;
|
|
407 QLabel doubleLabel;
|
|
408 QLabel itemLabel;
|
|
409 QLabel textLabel;
|
|
410 QLabel colorLabel;
|
|
411 QLabel fontLabel;
|
|
412 QLabel directoryLabel;
|
|
413 QLabel openFileNameLabel;
|
|
414 QLabel openFileNamesLabel;
|
|
415 QLabel saveFileNameLabel;
|
|
416 QLabel criticalLabel;
|
|
417 QLabel informationLabel;
|
|
418 QLabel questionLabel;
|
|
419 QLabel warningLabel;
|
|
420 QLabel errorLabel;
|
|
421 QErrorMessage errorMessageDialog;
|
|
422
|
211
|
423 string openFilesPath;
|
143
|
424 }
|