| 37 |
37 |
| 38 #include <QVBoxLayout> |
38 #include <QVBoxLayout> |
| 39 #include <QFileDialog> |
39 #include <QFileDialog> |
| 40 #include <QPushButton> |
40 #include <QPushButton> |
| 41 #include <QDockWidget> |
41 #include <QDockWidget> |
| |
42 #include <QMessageBox> |
| 42 |
43 |
| 43 static UiObject* create_window(const char *title, void *window_data, bool simple, bool sidebar = false) { |
44 static UiObject* create_window(const char *title, void *window_data, bool simple, bool sidebar = false) { |
| 44 UiObject *obj = uic_object_new_toplevel(); |
45 UiObject *obj = uic_object_new_toplevel(); |
| 45 obj->window = window_data; |
46 obj->window = window_data; |
| 46 obj->next = NULL; |
47 obj->next = NULL; |
| 78 |
79 |
| 79 UiObject* ui_simplewindow(char *title, void *window_data) { |
80 UiObject* ui_simplewindow(char *title, void *window_data) { |
| 80 return create_window(title, window_data, true); |
81 return create_window(title, window_data, true); |
| 81 } |
82 } |
| 82 |
83 |
| 83 UiObject *ui_sidebar_window(const char *title, void *window_data) { |
84 UiObject *ui_sidebar_window(const char *title, void *window_data) { |
| 84 return create_window(title, window_data, false, true); |
85 return create_window(title, window_data, false, true); |
| 85 } |
86 } |
| 86 |
87 |
| |
88 void ui_dialog_create(UiObject *parent, UiDialogArgs *args) { |
| |
89 if(args->input || args->password) { |
| |
90 // TODO: QInputDialog |
| |
91 } else { |
| |
92 QMessageBox msgBox; |
| |
93 if(args->title) { |
| |
94 msgBox.setWindowTitle(args->title); |
| |
95 } |
| |
96 if(args->content) { |
| |
97 msgBox.setText(args->content); |
| |
98 } |
| |
99 QPushButton *btn1; |
| |
100 QPushButton *btn2; |
| |
101 if(args->button1_label) { |
| |
102 btn1 = msgBox.addButton(args->button1_label, QMessageBox::ActionRole); |
| |
103 } |
| |
104 if(args->button2_label) { |
| |
105 btn2 = msgBox.addButton(args->button2_label, QMessageBox::ActionRole); |
| |
106 } |
| |
107 if(args->closebutton_label) { |
| |
108 msgBox.addButton(args->closebutton_label, QMessageBox::DestructiveRole); |
| |
109 } |
| |
110 |
| |
111 msgBox.exec(); |
| |
112 |
| |
113 UiEvent evt; |
| |
114 evt.obj = parent; |
| |
115 evt.document = evt.obj->ctx->document; |
| |
116 evt.window = evt.obj->window; |
| |
117 evt.eventdata = NULL; |
| |
118 evt.eventdatatype = 0; |
| |
119 evt.intval = 0; |
| |
120 if(msgBox.clickedButton() == btn1) { |
| |
121 evt.intval = 1; |
| |
122 } else if(msgBox.clickedButton() == btn2) { |
| |
123 evt.intval = 2; |
| |
124 } |
| |
125 if(args->result) { |
| |
126 args->result(&evt, args->resultdata); |
| |
127 } |
| |
128 } |
| |
129 } |
| 87 |
130 |
| 88 char* ui_openfiledialog(UiObject *obj) { |
131 char* ui_openfiledialog(UiObject *obj) { |
| 89 QString fileName = QFileDialog::getOpenFileName(obj->widget); |
132 QString fileName = QFileDialog::getOpenFileName(obj->widget); |
| 90 if(fileName.size() > 0) { |
133 if(fileName.size() > 0) { |
| 91 QByteArray array = fileName.toLocal8Bit(); |
134 QByteArray array = fileName.toLocal8Bit(); |