| 28 |
28 |
| 29 #include "button.h" |
29 #include "button.h" |
| 30 #include "container.h" |
30 #include "container.h" |
| 31 #include "toolkit.h" |
31 #include "toolkit.h" |
| 32 |
32 |
| 33 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { |
33 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs *args) { |
| 34 UiContainerPrivate *ctn = ui_obj_container(obj); |
34 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 35 UI_APPLY_LAYOUT(ctn->layout, args); |
35 UI_APPLY_LAYOUT(ctn->layout, args); |
| 36 |
36 |
| 37 QString str = QString::fromUtf8(args.label); |
37 QString str = QString::fromUtf8(args->label); |
| 38 QPushButton *button = new QPushButton(str); |
38 QPushButton *button = new QPushButton(str); |
| 39 |
39 |
| 40 if(args.onclick) { |
40 if(args->onclick) { |
| 41 UiEventWrapper *event = new UiEventWrapper(obj, args.onclick, args.onclickdata); |
41 UiEventWrapper *event = new UiEventWrapper(obj, args->onclick, args->onclickdata); |
| 42 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
42 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
| 43 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
43 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 44 } |
44 } |
| 45 |
45 |
| 46 ctn->add(button, false); |
46 ctn->add(button); |
| 47 |
47 |
| 48 return button; |
48 return button; |
| 49 } |
49 } |
| 50 |
50 |
| 51 static void togglebutton_event(UiEvent *event, UiEventWrapper *wrapper) { |
51 static void togglebutton_event(UiEvent *event, UiEventWrapper *wrapper) { |
| 52 QPushButton *button = (QPushButton*)wrapper->customdata1; |
52 QPushButton *button = (QPushButton*)wrapper->customdata1; |
| 53 event->intval = button->isChecked(); |
53 event->intval = button->isChecked(); |
| 54 if(wrapper->var) { |
54 if(wrapper->var) { |
| 55 event->eventdata = wrapper->var->value; |
55 event->eventdata = wrapper->var->value; |
| 56 } |
56 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE; |
| 57 } |
57 } |
| 58 |
58 } |
| 59 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
59 |
| 60 UiContainerPrivate *ctn = ui_obj_container(obj); |
60 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) { |
| 61 UI_APPLY_LAYOUT(ctn->layout, args); |
61 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 62 |
62 UI_APPLY_LAYOUT(ctn->layout, args); |
| 63 QString str = QString::fromUtf8(args.label); |
63 |
| |
64 QString str = QString::fromUtf8(args->label); |
| 64 QPushButton *button = new QPushButton(str); |
65 QPushButton *button = new QPushButton(str); |
| 65 button->setCheckable(true); |
66 button->setCheckable(true); |
| 66 |
67 |
| 67 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
68 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 68 |
69 |
| 69 if(args.onchange) { |
70 if(args->onchange) { |
| 70 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
71 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 71 event->var = var; |
72 event->var = var; |
| 72 event->customdata1 = button; |
73 event->customdata1 = button; |
| 73 event->prepare_event = togglebutton_event; |
74 event->prepare_event = togglebutton_event; |
| 74 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
75 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
| 75 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
76 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 109 static void checkbox_event(UiEvent *event, UiEventWrapper *wrapper) { |
110 static void checkbox_event(UiEvent *event, UiEventWrapper *wrapper) { |
| 110 QPushButton *button = (QPushButton*)wrapper->customdata1; |
111 QPushButton *button = (QPushButton*)wrapper->customdata1; |
| 111 event->intval = button->isChecked(); |
112 event->intval = button->isChecked(); |
| 112 if(wrapper->var) { |
113 if(wrapper->var) { |
| 113 event->eventdata = wrapper->var->value; |
114 event->eventdata = wrapper->var->value; |
| 114 } |
115 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE; |
| 115 } |
116 } |
| 116 |
117 } |
| 117 |
118 |
| 118 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
119 |
| 119 UiContainerPrivate *ctn = ui_obj_container(obj); |
120 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
| 120 UI_APPLY_LAYOUT(ctn->layout, args); |
121 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 121 |
122 UI_APPLY_LAYOUT(ctn->layout, args); |
| 122 QString str = QString::fromUtf8(args.label); |
123 |
| |
124 QString str = QString::fromUtf8(args->label); |
| 123 QCheckBox *checkbox = new QCheckBox(str); |
125 QCheckBox *checkbox = new QCheckBox(str); |
| 124 |
126 |
| 125 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
127 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 126 |
128 |
| 127 if(args.onchange) { |
129 if(args->onchange) { |
| 128 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
130 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 129 event->var = var; |
131 event->var = var; |
| 130 event->customdata1 = checkbox; |
132 event->customdata1 = checkbox; |
| 131 event->prepare_event = checkbox_event; |
133 event->prepare_event = checkbox_event; |
| 132 checkbox->connect(checkbox, SIGNAL(clicked()), event, SLOT(slot())); |
134 checkbox->connect(checkbox, SIGNAL(clicked()), event, SLOT(slot())); |
| 133 checkbox->connect(checkbox, SIGNAL(destroyed()), event, SLOT(destroy())); |
135 checkbox->connect(checkbox, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 165 } |
167 } |
| 166 |
168 |
| 167 |
169 |
| 168 static void radiobutton_event(UiEvent *event, UiEventWrapper *wrapper) { |
170 static void radiobutton_event(UiEvent *event, UiEventWrapper *wrapper) { |
| 169 if(wrapper->var) { |
171 if(wrapper->var) { |
| 170 UiInteger *value = wrapper->var->value; |
172 UiInteger *value = (UiInteger*)wrapper->var->value; |
| 171 event->eventdata = value; |
173 event->eventdata = value; |
| 172 event->intval = ui_get(value); |
174 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE; |
| 173 } |
175 event->intval = value->get(value); |
| 174 } |
176 } |
| 175 |
177 } |
| 176 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { |
178 |
| 177 UiContainerPrivate *ctn = ui_obj_container(obj); |
179 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) { |
| 178 UI_APPLY_LAYOUT(ctn->layout, args); |
180 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 179 |
181 UI_APPLY_LAYOUT(ctn->layout, args); |
| 180 QString str = QString::fromUtf8(args.label); |
182 |
| |
183 QString str = QString::fromUtf8(args->label); |
| 181 QRadioButton *button = new QRadioButton(str); |
184 QRadioButton *button = new QRadioButton(str); |
| 182 button->setAutoExclusive(false); |
185 button->setAutoExclusive(false); |
| 183 |
186 |
| 184 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
187 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 185 if(var) { |
188 if(var) { |
| 186 UiInteger *value = (UiInteger*)var->value; |
189 UiInteger *value = (UiInteger*)var->value; |
| 187 QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; |
190 QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; |
| 188 if(!buttonGroup) { |
191 if(!buttonGroup) { |
| 189 buttonGroup = new QButtonGroup(); |
192 buttonGroup = new QButtonGroup(); |
| 196 } |
199 } |
| 197 value->get = ui_radiobutton_get; |
200 value->get = ui_radiobutton_get; |
| 198 value->set = ui_radiobutton_set; |
201 value->set = ui_radiobutton_set; |
| 199 } |
202 } |
| 200 |
203 |
| 201 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
204 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 202 event->var = var; |
205 event->var = var; |
| 203 event->customdata1 = button; |
206 event->customdata1 = button; |
| 204 event->prepare_event = togglebutton_event; |
207 event->prepare_event = togglebutton_event; |
| 205 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
208 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
| 206 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
209 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 207 |
210 |
| 208 ctn->add(button, false); |
211 ctn->add(button); |
| 209 |
212 |
| 210 return button; |
213 return button; |
| 211 } |
214 } |
| 212 |
215 |
| 213 int64_t ui_radiobutton_get(UiInteger *value) { |
216 int64_t ui_radiobutton_get(UiInteger *value) { |