Mercurial > projects > qtd
annotate examples/dialogs/standarddialogs/dialog.d @ 339:4e31cbd9e20c
fix enumeration problems. requires patched dmd
author | Eldar Insafutdinov |
---|---|
date | Sun, 09 May 2010 00:52:49 +0100 |
parents | 7a3c43424dca |
children | 31520b2c0b3c |
rev | line source |
---|---|
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 | |
215 | 58 import std.string; |
143 | 59 |
60 | |
211 | 61 string MESSAGE = tr("<p>Message boxes have a caption, a text, " |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
138 connect(integerButton, "clicked", this, "setInteger"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
139 connect(doubleButton, "clicked", this, "setDouble"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
140 connect(itemButton, "clicked", this, "setItem"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
141 connect(textButton, "clicked", this, "setText"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
142 connect(colorButton, "clicked", this, "setColor"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
143 connect(fontButton, "clicked", this, "setFont"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
144 connect(directoryButton, "clicked", this, "setExistingDirectory"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
145 connect(openFileNameButton, "clicked", this, "setOpenFileName"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
146 connect(openFileNamesButton, "clicked", this, "setOpenFileNames"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
147 connect(saveFileNameButton, "clicked", this, "setSaveFileName"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
148 connect(criticalButton, "clicked", this, "criticalMessage"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
149 connect(informationButton, "clicked", this, "informationMessage"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
150 connect(questionButton, "clicked", this, "questionMessage"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
151 connect(warningButton, "clicked", this, "warningMessage"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
152 connect(errorButton, "clicked", this, "errorMessage"); |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
205 private: // slots |
143 | 206 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
207 void slot_setInteger() |
143 | 208 { |
209 bool ok; | |
210 int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok); | |
211 if (ok) | |
215 | 212 integerLabel.setText(format("%d", i)); |
143 | 213 } |
214 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
215 void slot_setDouble() |
143 | 216 { |
217 bool ok; | |
218 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"), | |
219 tr("Amount:"), 37.56, -10000, 10000, 2, ok); | |
220 if (ok) | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
221 doubleLabel.setText(format("%g", d)); |
143 | 222 } |
223 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
224 void slot_setItem() |
143 | 225 { |
226 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")]; | |
227 | |
228 bool ok; | |
229 string item = QInputDialog.getItem(this, tr("QInputgetItem()"), | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
230 tr("Season:"), items.toQList, 0, false, ok); |
143 | 231 if (ok && item.length) |
232 itemLabel.setText(item); | |
233 } | |
234 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
235 void slot_setText() |
143 | 236 { |
237 bool ok; | |
238 string text = QInputDialog.getText(this, tr("QInputgetText()"), | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
239 tr("User name:"), QLineEdit.EchoMode.Normal, |
143 | 240 QDir.home().dirName(), ok); |
241 if (ok && text.length) | |
242 textLabel.setText(text); | |
243 } | |
244 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
245 void slot_setColor() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
255 void slot_setFont() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
265 void slot_setExistingDirectory() |
143 | 266 { |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
267 int options = QFileDialog.Option.DontResolveSymlinks | QFileDialog.Option.ShowDirsOnly; |
143 | 268 if (!native.isChecked()) |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
269 options |= QFileDialog.Option.DontUseNativeDialog; |
143 | 270 string directory = QFileDialog.getExistingDirectory(this, |
271 tr("QFilegetExistingDirectory()"), | |
272 directoryLabel.text(), | |
273 options); | |
274 if (directory.length) | |
275 directoryLabel.setText(directory); | |
276 } | |
277 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
278 void slot_setOpenFileName() |
143 | 279 { |
280 int options; | |
281 if (!native.isChecked()) | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
282 options |= QFileDialog.Option.DontUseNativeDialog; |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
294 void slot_setOpenFileNames() |
143 | 295 { |
296 int options; | |
297 if (!native.isChecked()) | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
298 options |= QFileDialog.Option.DontUseNativeDialog; |
143 | 299 string selectedFilter; |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
300 auto files = QFileDialog.getOpenFileNames( |
143 | 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]; | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
308 openFileNamesLabel.setText(join(files.toArray, "; ")); |
143 | 309 } |
310 } | |
311 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
312 void slot_setSaveFileName() |
143 | 313 { |
314 int options; | |
315 if (!native.isChecked()) | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
316 options |= QFileDialog.Option.DontUseNativeDialog; |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
328 void slot_criticalMessage() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
342 void slot_informationMessage() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
352 void slot_questionMessage() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
366 void slot_warningMessage() |
143 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
377 void slot_errorMessage() |
143 | 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 | |
211 | 409 string openFilesPath; |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
410 |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
411 mixin Q_OBJECT; |
143 | 412 } |