1 module examplewidgets.tabdialogs; 2 3 import qt.config; 4 import qt.core.string; 5 import qt.helpers; 6 import qt.widgets.errormessage; 7 import qt.widgets.ui; 8 import qt.widgets.widget; 9 import core.stdcpp.new_; 10 11 class TabDialogs : QWidget 12 { 13 mixin(Q_OBJECT_D); 14 15 public: 16 /+ explicit +/this(QWidget parent = null) 17 { 18 import core.stdcpp.new_; 19 import qt.widgets.spinbox; 20 super(parent); 21 this.ui = cpp_new!(typeof(*ui)); 22 23 ui.setupUi(this); 24 25 errorMessage = cpp_new!QErrorMessage(this); 26 27 connect(ui.spinBoxRed.signal!("valueChanged", int), this.slot!"updateColor"); 28 connect(ui.spinBoxGreen.signal!("valueChanged", int), this.slot!"updateColor"); 29 connect(ui.spinBoxBlue.signal!("valueChanged", int), this.slot!"updateColor"); 30 updateColor(); 31 } 32 ~this() 33 { 34 import core.stdcpp.new_; 35 36 cpp_delete(ui); 37 } 38 39 private /+ slots +/: 40 @QSlot final void on_pushButtonShowMessageBox_clicked() 41 { 42 import qt.widgets.messagebox; 43 44 QMessageBox msgBox = cpp_new!QMessageBox; 45 msgBox.setIcon(cast(/+ QMessageBox::Icon +/QMessageBox.Icon)ui.comboBoxIcon.currentIndex()); 46 msgBox.setText(ui.plainTextEditText.toPlainText()); 47 auto tmp = ui.plainTextEditDetailed.toPlainText(); msgBox.setDetailedText(tmp); 48 QMessageBox.StandardButtons buttons; 49 if(ui.checkBoxOK.isChecked()) 50 buttons |= QMessageBox.StandardButton.Ok; 51 if(ui.checkBoxCancel.isChecked()) 52 buttons |= QMessageBox.StandardButton.Cancel; 53 if(ui.checkBoxYes.isChecked()) 54 buttons |= QMessageBox.StandardButton.Yes; 55 if(ui.checkBoxNo.isChecked()) 56 buttons |= QMessageBox.StandardButton.No; 57 msgBox.setStandardButtons(buttons); 58 int ret = msgBox.exec(); 59 const(char)* buttonName; 60 switch(ret) 61 { 62 case QMessageBox.StandardButton.Ok: 63 buttonName = "OK"; 64 break; 65 case QMessageBox.StandardButton.Cancel: 66 buttonName = "Cancel"; 67 break; 68 case QMessageBox.StandardButton.Yes: 69 buttonName = "Yes"; 70 break; 71 case QMessageBox.StandardButton.No: 72 buttonName = "No"; 73 break; 74 default: 75 buttonName = "Unknown"; 76 } 77 QString text = QString("Clicked: ") ~ buttonName; 78 ui.labelResult.setText(text); 79 cpp_delete(msgBox); 80 } 81 82 @QSlot final void on_pushButtonShowColorDialog_clicked() 83 { 84 import qt.gui.color; 85 import qt.widgets.colordialog; 86 87 QColor color = QColor.fromRgb(ui.spinBoxRed.value(), ui.spinBoxGreen.value(), ui.spinBoxBlue.value()); 88 color = QColorDialog.getColor(color, this, globalInitVar!QString); 89 ui.spinBoxRed.setValue(color.red()); 90 ui.spinBoxGreen.setValue(color.green()); 91 ui.spinBoxBlue.setValue(color.blue()); 92 } 93 94 @QSlot final void updateColor() 95 { 96 import qt.gui.color; 97 import qt.gui.palette; 98 99 QColor color = QColor.fromRgb(ui.spinBoxRed.value(), ui.spinBoxGreen.value(), ui.spinBoxBlue.value()); 100 QPalette palette = QPalette(color); 101 palette.setColor(QPalette.ColorRole.Background, color); 102 ui.widgetColor.setPalette(palette); 103 ui.widgetColor.update(); 104 } 105 106 @QSlot final void on_pushButtonShowError_clicked() 107 { 108 auto tmp = ui.plainTextEditErrorMessage.toPlainText(); errorMessage.showMessage(tmp); 109 } 110 111 @QSlot final void on_pushButtonOpenFile_clicked() 112 { 113 import qt.widgets.filedialog; 114 115 QString path = ui.lineEditPath.text(); 116 path = QFileDialog.getOpenFileName(this, globalInitVar!QString, path); 117 ui.lineEditPath.setText(path); 118 } 119 120 @QSlot final void on_pushButtonSaveFile_clicked() 121 { 122 import qt.widgets.filedialog; 123 124 QString path = ui.lineEditPath.text(); 125 path = QFileDialog.getSaveFileName(this, globalInitVar!QString, path); 126 ui.lineEditPath.setText(path); 127 } 128 129 @QSlot final void on_pushButtonSelectDirectory_clicked() 130 { 131 import qt.widgets.filedialog; 132 133 QString path = ui.lineEditPath.text(); 134 path = QFileDialog.getExistingDirectory(this, globalInitVar!QString, path); 135 ui.lineEditPath.setText(path); 136 } 137 138 private: 139 UIStruct!"tabdialogs.ui"* ui; 140 QErrorMessage errorMessage; 141 } 142