Mercurial > projects > qtd
comparison examples/dialogs/standarddialogs/dialog_d1.d @ 216:06e7d3219464
ups....
author | SokoL_SD |
---|---|
date | Tue, 14 Jul 2009 15:28:22 +0000 |
parents | |
children | 256ab6cb8e85 |
comparison
equal
deleted
inserted
replaced
215:8aaa84d48451 | 216:06e7d3219464 |
---|---|
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_d1; | |
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 string 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 version(Tango) | |
213 integerLabel.setText(Format("{}", i)); | |
214 else | |
215 integerLabel.setText(format("%d", i)); | |
216 } | |
217 | |
218 void setDouble() | |
219 { | |
220 bool ok; | |
221 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"), | |
222 tr("Amount:"), 37.56, -10000, 10000, 2, ok); | |
223 if (ok) | |
224 version(Tango) | |
225 doubleLabel.setText(Format("${}", d)); | |
226 else | |
227 integerLabel.setText(format("%g", d)); | |
228 } | |
229 | |
230 void setItem() | |
231 { | |
232 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")]; | |
233 | |
234 bool ok; | |
235 string item = QInputDialog.getItem(this, tr("QInputgetItem()"), | |
236 tr("Season:"), items, 0, false, ok); | |
237 if (ok && item.length) | |
238 itemLabel.setText(item); | |
239 } | |
240 | |
241 void setText() | |
242 { | |
243 bool ok; | |
244 string text = QInputDialog.getText(this, tr("QInputgetText()"), | |
245 tr("User name:"), QLineEdit_EchoMode.Normal, | |
246 QDir.home().dirName(), ok); | |
247 if (ok && text.length) | |
248 textLabel.setText(text); | |
249 } | |
250 | |
251 void setColor() | |
252 { | |
253 QColor color = QColorDialog.getColor(QColor.Green, this); | |
254 if (color.isValid()) { | |
255 colorLabel.setText(color.name()); | |
256 colorLabel.setPalette(new QPalette(color)); | |
257 colorLabel.setAutoFillBackground(true); | |
258 } | |
259 } | |
260 | |
261 void setFont() | |
262 { | |
263 bool ok; | |
264 QFont font = QFontDialog.getFont(&ok, new QFont(fontLabel.text()), this); | |
265 if (ok) { | |
266 fontLabel.setText(font.key()); | |
267 fontLabel.setFont(font); | |
268 } | |
269 } | |
270 | |
271 void setExistingDirectory() | |
272 { | |
273 int options = QFileDialog_Option.DontResolveSymlinks | QFileDialog_Option.ShowDirsOnly; | |
274 if (!native.isChecked()) | |
275 options |= QFileDialog_Option.DontUseNativeDialog; | |
276 string directory = QFileDialog.getExistingDirectory(this, | |
277 tr("QFilegetExistingDirectory()"), | |
278 directoryLabel.text(), | |
279 options); | |
280 if (directory.length) | |
281 directoryLabel.setText(directory); | |
282 } | |
283 | |
284 void setOpenFileName() | |
285 { | |
286 int options; | |
287 if (!native.isChecked()) | |
288 options |= QFileDialog_Option.DontUseNativeDialog; | |
289 string selectedFilter; | |
290 string fileName = QFileDialog.getOpenFileName(this, | |
291 tr("QFilegetOpenFileName()"), | |
292 openFileNameLabel.text(), | |
293 tr("All Files (*);;Text Files (*.txt)"), | |
294 selectedFilter, | |
295 options); | |
296 if (fileName.length) | |
297 openFileNameLabel.setText(fileName); | |
298 } | |
299 | |
300 void setOpenFileNames() | |
301 { | |
302 int options; | |
303 if (!native.isChecked()) | |
304 options |= QFileDialog_Option.DontUseNativeDialog; | |
305 string selectedFilter; | |
306 string[] files = QFileDialog.getOpenFileNames( | |
307 this, tr("QFilegetOpenFileNames()"), | |
308 openFilesPath, | |
309 tr("All Files (*);;Text Files (*.txt)"), | |
310 selectedFilter, | |
311 options); | |
312 if (files.length) { | |
313 openFilesPath = files[0]; | |
314 version(Tango) | |
315 openFileNamesLabel.setText(Format("{}", files)); | |
316 else | |
317 { | |
318 openFileNamesLabel.setText(join(files, "; ")); | |
319 } | |
320 } | |
321 } | |
322 | |
323 void setSaveFileName() | |
324 { | |
325 int options; | |
326 if (!native.isChecked()) | |
327 options |= QFileDialog_Option.DontUseNativeDialog; | |
328 string selectedFilter; | |
329 string fileName = QFileDialog.getSaveFileName(this, | |
330 tr("QFilegetSaveFileName()"), | |
331 saveFileNameLabel.text(), | |
332 tr("All Files (*);;Text Files (*.txt)"), | |
333 selectedFilter, | |
334 options); | |
335 if (fileName.length) | |
336 saveFileNameLabel.setText(fileName); | |
337 } | |
338 | |
339 void criticalMessage() | |
340 { | |
341 QMessageBox.StandardButton reply; | |
342 reply = QMessageBox.critical(this, tr("QMessageBox.critical()"), | |
343 MESSAGE, | |
344 QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore); | |
345 if (reply == QMessageBox.Abort) | |
346 criticalLabel.setText(tr("Abort")); | |
347 else if (reply == QMessageBox.Retry) | |
348 criticalLabel.setText(tr("Retry")); | |
349 else | |
350 criticalLabel.setText(tr("Ignore")); | |
351 } | |
352 | |
353 void informationMessage() | |
354 { | |
355 QMessageBox.StandardButton reply; | |
356 reply = QMessageBox.information(this, tr("QMessageBox.information()"), MESSAGE); | |
357 if (reply == QMessageBox.Ok) | |
358 informationLabel.setText(tr("OK")); | |
359 else | |
360 informationLabel.setText(tr("Escape")); | |
361 } | |
362 | |
363 void questionMessage() | |
364 { | |
365 QMessageBox.StandardButton reply; | |
366 reply = QMessageBox.question(this, tr("QMessageBox.question()"), | |
367 MESSAGE, | |
368 QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel); | |
369 if (reply == QMessageBox.Yes) | |
370 questionLabel.setText(tr("Yes")); | |
371 else if (reply == QMessageBox.No) | |
372 questionLabel.setText(tr("No")); | |
373 else | |
374 questionLabel.setText(tr("Cancel")); | |
375 } | |
376 | |
377 void warningMessage() | |
378 { | |
379 auto msgBox = new QMessageBox(QMessageBox.Warning, tr("QMessageBox.warning()"), MESSAGE, 0, this); | |
380 msgBox.addButton(tr("Save &Again"), QMessageBox.AcceptRole); | |
381 msgBox.addButton(tr("&Continue"), QMessageBox.RejectRole); | |
382 if (msgBox.exec() == QMessageBox.AcceptRole) | |
383 warningLabel.setText(tr("Save Again")); | |
384 else | |
385 warningLabel.setText(tr("Continue")); | |
386 } | |
387 | |
388 void errorMessage() | |
389 { | |
390 errorMessageDialog.showMessage( | |
391 tr("This dialog shows and remembers error messages. " | |
392 "If the checkbox is checked (as it is by default), " | |
393 "the shown message will be shown again, " | |
394 "but if the user unchecks the box the message " | |
395 "will not appear again if QErrorMessage.showMessage() " | |
396 "is called with the same message.")); | |
397 errorLabel.setText(tr("If the box is unchecked, the message won't appear again.")); | |
398 } | |
399 | |
400 private: | |
401 | |
402 QCheckBox native; | |
403 QLabel integerLabel; | |
404 QLabel doubleLabel; | |
405 QLabel itemLabel; | |
406 QLabel textLabel; | |
407 QLabel colorLabel; | |
408 QLabel fontLabel; | |
409 QLabel directoryLabel; | |
410 QLabel openFileNameLabel; | |
411 QLabel openFileNamesLabel; | |
412 QLabel saveFileNameLabel; | |
413 QLabel criticalLabel; | |
414 QLabel informationLabel; | |
415 QLabel questionLabel; | |
416 QLabel warningLabel; | |
417 QLabel errorLabel; | |
418 QErrorMessage errorMessageDialog; | |
419 | |
420 string openFilesPath; | |
421 } |