| 36 #include "container.h" |
36 #include "container.h" |
| 37 |
37 |
| 38 #include <QVBoxLayout> |
38 #include <QVBoxLayout> |
| 39 #include <QFileDialog> |
39 #include <QFileDialog> |
| 40 #include <QPushButton> |
40 #include <QPushButton> |
| |
41 #include <QDockWidget> |
| |
42 #include <QMessageBox> |
| 41 |
43 |
| 42 static UiObject* create_window(const char *title, void *window_data, bool simple) { |
44 static UiObject* create_window(const char *title, void *window_data, bool simple, bool sidebar = false) { |
| 43 UiObject *obj = uic_object_new_toplevel(); |
45 UiObject *obj = uic_object_new_toplevel(); |
| 44 obj->window = window_data; |
46 obj->window = window_data; |
| 45 obj->next = NULL; |
47 obj->next = NULL; |
| 46 |
48 |
| 47 QMainWindow *window = new QMainWindow(); |
49 QMainWindow *window = new QMainWindow(); |
| 59 QBoxLayout *box = new QVBoxLayout(); |
61 QBoxLayout *box = new QVBoxLayout(); |
| 60 QWidget *boxWidget = new QWidget(); |
62 QWidget *boxWidget = new QWidget(); |
| 61 boxWidget->setLayout(box); |
63 boxWidget->setLayout(box); |
| 62 window->setCentralWidget(boxWidget); |
64 window->setCentralWidget(boxWidget); |
| 63 ui_container_add(obj, new UiBoxContainer(box)); |
65 ui_container_add(obj, new UiBoxContainer(box)); |
| |
66 if(sidebar) { |
| |
67 QDockWidget *dock = new QDockWidget(); |
| |
68 window->addDockWidget(Qt::LeftDockWidgetArea, dock); |
| |
69 window->setProperty("ui_sidebar", QVariant::fromValue((void*)dock)); |
| |
70 } |
| 64 |
71 |
| 65 obj->widget = window; |
72 obj->widget = window; |
| 66 return obj; |
73 return obj; |
| 67 } |
74 } |
| 68 |
75 |
| 69 UiObject* ui_window(const char *title, void *window_data) { |
76 UiObject* ui_window(const char *title, void *window_data) { |
| 70 return create_window(title, window_data, FALSE); |
77 return create_window(title, window_data, false); |
| 71 } |
78 } |
| 72 |
79 |
| 73 UiObject* ui_simplewindow(char *title, void *window_data) { |
80 UiObject* ui_simplewindow(char *title, void *window_data) { |
| 74 return create_window(title, window_data, TRUE); |
81 return create_window(title, window_data, true); |
| 75 } |
82 } |
| 76 |
83 |
| |
84 UiObject *ui_sidebar_window(const char *title, void *window_data) { |
| |
85 return create_window(title, window_data, false, true); |
| |
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 } |
| 77 |
130 |
| 78 char* ui_openfiledialog(UiObject *obj) { |
131 char* ui_openfiledialog(UiObject *obj) { |
| 79 QString fileName = QFileDialog::getOpenFileName(obj->widget); |
132 QString fileName = QFileDialog::getOpenFileName(obj->widget); |
| 80 if(fileName.size() > 0) { |
133 if(fileName.size() > 0) { |
| 81 QByteArray array = fileName.toLocal8Bit(); |
134 QByteArray array = fileName.toLocal8Bit(); |