Mercurial > projects > qtd
comparison examples/dialogs/standarddialogs/dialog.d @ 323:7a3c43424dca signals
make all examples compile with new signals/slots
author | eldar_ins@eldar-laptop |
---|---|
date | Mon, 28 Dec 2009 16:28:55 +0500 |
parents | 256ab6cb8e85 |
children | 4e31cbd9e20c |
comparison
equal
deleted
inserted
replaced
322:7c2cf27391c4 | 323:7a3c43424dca |
---|---|
133 | 133 |
134 errorLabel = new QLabel; | 134 errorLabel = new QLabel; |
135 errorLabel.setFrameStyle(frameStyle); | 135 errorLabel.setFrameStyle(frameStyle); |
136 QPushButton errorButton = new QPushButton(tr("QErrorMessage.show&M&essage()")); | 136 QPushButton errorButton = new QPushButton(tr("QErrorMessage.show&M&essage()")); |
137 | 137 |
138 connect!("clicked")(integerButton, &this.setInteger); | 138 connect(integerButton, "clicked", this, "setInteger"); |
139 connect!("clicked")(doubleButton, &this.setDouble); | 139 connect(doubleButton, "clicked", this, "setDouble"); |
140 connect!("clicked")(itemButton, &this.setItem); | 140 connect(itemButton, "clicked", this, "setItem"); |
141 connect!("clicked")(textButton, &this.setText); | 141 connect(textButton, "clicked", this, "setText"); |
142 connect!("clicked")(colorButton, &this.setColor); | 142 connect(colorButton, "clicked", this, "setColor"); |
143 connect!("clicked")(fontButton, &this.setFont); | 143 connect(fontButton, "clicked", this, "setFont"); |
144 connect!("clicked")(directoryButton, &this.setExistingDirectory); | 144 connect(directoryButton, "clicked", this, "setExistingDirectory"); |
145 connect!("clicked")(openFileNameButton, &this.setOpenFileName); | 145 connect(openFileNameButton, "clicked", this, "setOpenFileName"); |
146 connect!("clicked")(openFileNamesButton, &this.setOpenFileNames); | 146 connect(openFileNamesButton, "clicked", this, "setOpenFileNames"); |
147 connect!("clicked")(saveFileNameButton, &this.setSaveFileName); | 147 connect(saveFileNameButton, "clicked", this, "setSaveFileName"); |
148 connect!("clicked")(criticalButton, &this.criticalMessage); | 148 connect(criticalButton, "clicked", this, "criticalMessage"); |
149 connect!("clicked")(informationButton, &this.informationMessage); | 149 connect(informationButton, "clicked", this, "informationMessage"); |
150 connect!("clicked")(questionButton, &this.questionMessage); | 150 connect(questionButton, "clicked", this, "questionMessage"); |
151 connect!("clicked")(warningButton, &this.warningMessage); | 151 connect(warningButton, "clicked", this, "warningMessage"); |
152 connect!("clicked")(errorButton, &this.errorMessage); | 152 connect(errorButton, "clicked", this, "errorMessage"); |
153 | 153 |
154 native = new QCheckBox(this); | 154 native = new QCheckBox(this); |
155 native.setText("Use native file dialog."); | 155 native.setText("Use native file dialog."); |
156 native.setChecked(true); | 156 native.setChecked(true); |
157 | 157 |
200 setLayout(layout); | 200 setLayout(layout); |
201 | 201 |
202 setWindowTitle(tr("Standard Dialogs")); | 202 setWindowTitle(tr("Standard Dialogs")); |
203 } | 203 } |
204 | 204 |
205 private: | 205 private: // slots |
206 | 206 |
207 void setInteger() | 207 void slot_setInteger() |
208 { | 208 { |
209 bool ok; | 209 bool ok; |
210 int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok); | 210 int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok); |
211 if (ok) | 211 if (ok) |
212 integerLabel.setText(format("%d", i)); | 212 integerLabel.setText(format("%d", i)); |
213 } | 213 } |
214 | 214 |
215 void setDouble() | 215 void slot_setDouble() |
216 { | 216 { |
217 bool ok; | 217 bool ok; |
218 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"), | 218 double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"), |
219 tr("Amount:"), 37.56, -10000, 10000, 2, ok); | 219 tr("Amount:"), 37.56, -10000, 10000, 2, ok); |
220 if (ok) | 220 if (ok) |
221 integerLabel.setText(format("%g", d)); | 221 doubleLabel.setText(format("%g", d)); |
222 } | 222 } |
223 | 223 |
224 void setItem() | 224 void slot_setItem() |
225 { | 225 { |
226 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")]; | 226 string[] items = [tr("Spring"), tr("Summer"), tr("Fall"), tr("Winter")]; |
227 | 227 |
228 bool ok; | 228 bool ok; |
229 string item = QInputDialog.getItem(this, tr("QInputgetItem()"), | 229 string item = QInputDialog.getItem(this, tr("QInputgetItem()"), |
230 tr("Season:"), items, 0, false, ok); | 230 tr("Season:"), items.toQList, 0, false, ok); |
231 if (ok && item.length) | 231 if (ok && item.length) |
232 itemLabel.setText(item); | 232 itemLabel.setText(item); |
233 } | 233 } |
234 | 234 |
235 void setText() | 235 void slot_setText() |
236 { | 236 { |
237 bool ok; | 237 bool ok; |
238 string text = QInputDialog.getText(this, tr("QInputgetText()"), | 238 string text = QInputDialog.getText(this, tr("QInputgetText()"), |
239 tr("User name:"), QLineEdit_EchoMode.Normal, | 239 tr("User name:"), QLineEdit_EchoMode.Normal, |
240 QDir.home().dirName(), ok); | 240 QDir.home().dirName(), ok); |
241 if (ok && text.length) | 241 if (ok && text.length) |
242 textLabel.setText(text); | 242 textLabel.setText(text); |
243 } | 243 } |
244 | 244 |
245 void setColor() | 245 void slot_setColor() |
246 { | 246 { |
247 QColor color = QColorDialog.getColor(QColor.Green, this); | 247 QColor color = QColorDialog.getColor(QColor.Green, this); |
248 if (color.isValid()) { | 248 if (color.isValid()) { |
249 colorLabel.setText(color.name()); | 249 colorLabel.setText(color.name()); |
250 colorLabel.setPalette(new QPalette(color)); | 250 colorLabel.setPalette(new QPalette(color)); |
251 colorLabel.setAutoFillBackground(true); | 251 colorLabel.setAutoFillBackground(true); |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 void setFont() | 255 void slot_setFont() |
256 { | 256 { |
257 bool ok; | 257 bool ok; |
258 QFont font = QFontDialog.getFont(&ok, new QFont(fontLabel.text()), this); | 258 QFont font = QFontDialog.getFont(&ok, new QFont(fontLabel.text()), this); |
259 if (ok) { | 259 if (ok) { |
260 fontLabel.setText(font.key()); | 260 fontLabel.setText(font.key()); |
261 fontLabel.setFont(font); | 261 fontLabel.setFont(font); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 void setExistingDirectory() | 265 void slot_setExistingDirectory() |
266 { | 266 { |
267 int options = QFileDialog_Option.DontResolveSymlinks | QFileDialog_Option.ShowDirsOnly; | 267 int options = QFileDialog_Option.DontResolveSymlinks | QFileDialog_Option.ShowDirsOnly; |
268 if (!native.isChecked()) | 268 if (!native.isChecked()) |
269 options |= QFileDialog_Option.DontUseNativeDialog; | 269 options |= QFileDialog_Option.DontUseNativeDialog; |
270 string directory = QFileDialog.getExistingDirectory(this, | 270 string directory = QFileDialog.getExistingDirectory(this, |
273 options); | 273 options); |
274 if (directory.length) | 274 if (directory.length) |
275 directoryLabel.setText(directory); | 275 directoryLabel.setText(directory); |
276 } | 276 } |
277 | 277 |
278 void setOpenFileName() | 278 void slot_setOpenFileName() |
279 { | 279 { |
280 int options; | 280 int options; |
281 if (!native.isChecked()) | 281 if (!native.isChecked()) |
282 options |= QFileDialog_Option.DontUseNativeDialog; | 282 options |= QFileDialog_Option.DontUseNativeDialog; |
283 string selectedFilter; | 283 string selectedFilter; |
289 options); | 289 options); |
290 if (fileName.length) | 290 if (fileName.length) |
291 openFileNameLabel.setText(fileName); | 291 openFileNameLabel.setText(fileName); |
292 } | 292 } |
293 | 293 |
294 void setOpenFileNames() | 294 void slot_setOpenFileNames() |
295 { | 295 { |
296 int options; | 296 int options; |
297 if (!native.isChecked()) | 297 if (!native.isChecked()) |
298 options |= QFileDialog_Option.DontUseNativeDialog; | 298 options |= QFileDialog_Option.DontUseNativeDialog; |
299 string selectedFilter; | 299 string selectedFilter; |
300 string[] files = QFileDialog.getOpenFileNames( | 300 auto files = QFileDialog.getOpenFileNames( |
301 this, tr("QFilegetOpenFileNames()"), | 301 this, tr("QFilegetOpenFileNames()"), |
302 openFilesPath, | 302 openFilesPath, |
303 tr("All Files (*);;Text Files (*.txt)"), | 303 tr("All Files (*);;Text Files (*.txt)"), |
304 selectedFilter, | 304 selectedFilter, |
305 options); | 305 options); |
306 if (files.length) { | 306 if (files.length) { |
307 openFilesPath = files[0]; | 307 openFilesPath = files[0]; |
308 openFileNamesLabel.setText(join(files, "; ")); | 308 openFileNamesLabel.setText(join(files.toArray, "; ")); |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void setSaveFileName() | 312 void slot_setSaveFileName() |
313 { | 313 { |
314 int options; | 314 int options; |
315 if (!native.isChecked()) | 315 if (!native.isChecked()) |
316 options |= QFileDialog_Option.DontUseNativeDialog; | 316 options |= QFileDialog_Option.DontUseNativeDialog; |
317 string selectedFilter; | 317 string selectedFilter; |
323 options); | 323 options); |
324 if (fileName.length) | 324 if (fileName.length) |
325 saveFileNameLabel.setText(fileName); | 325 saveFileNameLabel.setText(fileName); |
326 } | 326 } |
327 | 327 |
328 void criticalMessage() | 328 void slot_criticalMessage() |
329 { | 329 { |
330 QMessageBox.StandardButton reply; | 330 QMessageBox.StandardButton reply; |
331 reply = QMessageBox.critical(this, tr("QMessageBox.critical()"), | 331 reply = QMessageBox.critical(this, tr("QMessageBox.critical()"), |
332 MESSAGE, | 332 MESSAGE, |
333 QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore); | 333 QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore); |
337 criticalLabel.setText(tr("Retry")); | 337 criticalLabel.setText(tr("Retry")); |
338 else | 338 else |
339 criticalLabel.setText(tr("Ignore")); | 339 criticalLabel.setText(tr("Ignore")); |
340 } | 340 } |
341 | 341 |
342 void informationMessage() | 342 void slot_informationMessage() |
343 { | 343 { |
344 QMessageBox.StandardButton reply; | 344 QMessageBox.StandardButton reply; |
345 reply = QMessageBox.information(this, tr("QMessageBox.information()"), MESSAGE); | 345 reply = QMessageBox.information(this, tr("QMessageBox.information()"), MESSAGE); |
346 if (reply == QMessageBox.Ok) | 346 if (reply == QMessageBox.Ok) |
347 informationLabel.setText(tr("OK")); | 347 informationLabel.setText(tr("OK")); |
348 else | 348 else |
349 informationLabel.setText(tr("Escape")); | 349 informationLabel.setText(tr("Escape")); |
350 } | 350 } |
351 | 351 |
352 void questionMessage() | 352 void slot_questionMessage() |
353 { | 353 { |
354 QMessageBox.StandardButton reply; | 354 QMessageBox.StandardButton reply; |
355 reply = QMessageBox.question(this, tr("QMessageBox.question()"), | 355 reply = QMessageBox.question(this, tr("QMessageBox.question()"), |
356 MESSAGE, | 356 MESSAGE, |
357 QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel); | 357 QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel); |
361 questionLabel.setText(tr("No")); | 361 questionLabel.setText(tr("No")); |
362 else | 362 else |
363 questionLabel.setText(tr("Cancel")); | 363 questionLabel.setText(tr("Cancel")); |
364 } | 364 } |
365 | 365 |
366 void warningMessage() | 366 void slot_warningMessage() |
367 { | 367 { |
368 auto msgBox = new QMessageBox(QMessageBox.Warning, tr("QMessageBox.warning()"), MESSAGE, 0, this); | 368 auto msgBox = new QMessageBox(QMessageBox.Warning, tr("QMessageBox.warning()"), MESSAGE, 0, this); |
369 msgBox.addButton(tr("Save &Again"), QMessageBox.AcceptRole); | 369 msgBox.addButton(tr("Save &Again"), QMessageBox.AcceptRole); |
370 msgBox.addButton(tr("&Continue"), QMessageBox.RejectRole); | 370 msgBox.addButton(tr("&Continue"), QMessageBox.RejectRole); |
371 if (msgBox.exec() == QMessageBox.AcceptRole) | 371 if (msgBox.exec() == QMessageBox.AcceptRole) |
372 warningLabel.setText(tr("Save Again")); | 372 warningLabel.setText(tr("Save Again")); |
373 else | 373 else |
374 warningLabel.setText(tr("Continue")); | 374 warningLabel.setText(tr("Continue")); |
375 } | 375 } |
376 | 376 |
377 void errorMessage() | 377 void slot_errorMessage() |
378 { | 378 { |
379 errorMessageDialog.showMessage( | 379 errorMessageDialog.showMessage( |
380 tr("This dialog shows and remembers error messages. " | 380 tr("This dialog shows and remembers error messages. " |
381 "If the checkbox is checked (as it is by default), " | 381 "If the checkbox is checked (as it is by default), " |
382 "the shown message will be shown again, " | 382 "the shown message will be shown again, " |
405 QLabel warningLabel; | 405 QLabel warningLabel; |
406 QLabel errorLabel; | 406 QLabel errorLabel; |
407 QErrorMessage errorMessageDialog; | 407 QErrorMessage errorMessageDialog; |
408 | 408 |
409 string openFilesPath; | 409 string openFilesPath; |
410 | |
411 mixin Q_OBJECT; | |
410 } | 412 } |