| 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, false); |
| 54 if(wrapper->var) { |
54 if(wrapper->var) { |
| 55 event->eventdata = wrapper->var->value; |
55 event->eventdata = wrapper->var->value; |
| 56 } |
56 } |
| 57 } |
57 } |
| 58 |
58 |
| 59 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
59 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) { |
| 60 UiContainerPrivate *ctn = ui_obj_container(obj); |
60 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 61 UI_APPLY_LAYOUT(ctn->layout, args); |
61 UI_APPLY_LAYOUT(ctn->layout, args); |
| 62 |
62 |
| 63 QString str = QString::fromUtf8(args.label); |
63 QString str = QString::fromUtf8(args->label); |
| 64 QPushButton *button = new QPushButton(str); |
64 QPushButton *button = new QPushButton(str); |
| 65 button->setCheckable(true); |
65 button->setCheckable(true); |
| 66 |
66 |
| 67 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
67 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 68 |
68 |
| 69 if(args.onchange) { |
69 if(args->onchange) { |
| 70 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
70 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 71 event->var = var; |
71 event->var = var; |
| 72 event->customdata1 = button; |
72 event->customdata1 = button; |
| 73 event->prepare_event = togglebutton_event; |
73 event->prepare_event = togglebutton_event; |
| 74 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
74 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
| 75 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
75 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 113 event->eventdata = wrapper->var->value; |
113 event->eventdata = wrapper->var->value; |
| 114 } |
114 } |
| 115 } |
115 } |
| 116 |
116 |
| 117 |
117 |
| 118 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
118 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
| 119 UiContainerPrivate *ctn = ui_obj_container(obj); |
119 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 120 UI_APPLY_LAYOUT(ctn->layout, args); |
120 UI_APPLY_LAYOUT(ctn->layout, args); |
| 121 |
121 |
| 122 QString str = QString::fromUtf8(args.label); |
122 QString str = QString::fromUtf8(args->label); |
| 123 QCheckBox *checkbox = new QCheckBox(str); |
123 QCheckBox *checkbox = new QCheckBox(str); |
| 124 |
124 |
| 125 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
125 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 126 |
126 |
| 127 if(args.onchange) { |
127 if(args->onchange) { |
| 128 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
128 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 129 event->var = var; |
129 event->var = var; |
| 130 event->customdata1 = checkbox; |
130 event->customdata1 = checkbox; |
| 131 event->prepare_event = checkbox_event; |
131 event->prepare_event = checkbox_event; |
| 132 checkbox->connect(checkbox, SIGNAL(clicked()), event, SLOT(slot())); |
132 checkbox->connect(checkbox, SIGNAL(clicked()), event, SLOT(slot())); |
| 133 checkbox->connect(checkbox, SIGNAL(destroyed()), event, SLOT(destroy())); |
133 checkbox->connect(checkbox, SIGNAL(destroyed()), event, SLOT(destroy())); |
| 171 event->eventdata = value; |
171 event->eventdata = value; |
| 172 event->intval = value->get(value); |
172 event->intval = value->get(value); |
| 173 } |
173 } |
| 174 } |
174 } |
| 175 |
175 |
| 176 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { |
176 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) { |
| 177 UiContainerPrivate *ctn = ui_obj_container(obj); |
177 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 178 UI_APPLY_LAYOUT(ctn->layout, args); |
178 UI_APPLY_LAYOUT(ctn->layout, args); |
| 179 |
179 |
| 180 QString str = QString::fromUtf8(args.label); |
180 QString str = QString::fromUtf8(args->label); |
| 181 QRadioButton *button = new QRadioButton(str); |
181 QRadioButton *button = new QRadioButton(str); |
| 182 button->setAutoExclusive(false); |
182 button->setAutoExclusive(false); |
| 183 |
183 |
| 184 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); |
184 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 185 if(var) { |
185 if(var) { |
| 186 UiInteger *value = (UiInteger*)var->value; |
186 UiInteger *value = (UiInteger*)var->value; |
| 187 QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; |
187 QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; |
| 188 if(!buttonGroup) { |
188 if(!buttonGroup) { |
| 189 buttonGroup = new QButtonGroup(); |
189 buttonGroup = new QButtonGroup(); |
| 196 } |
196 } |
| 197 value->get = ui_radiobutton_get; |
197 value->get = ui_radiobutton_get; |
| 198 value->set = ui_radiobutton_set; |
198 value->set = ui_radiobutton_set; |
| 199 } |
199 } |
| 200 |
200 |
| 201 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata); |
201 UiEventWrapper *event = new UiEventWrapper(obj, args->onchange, args->onchangedata); |
| 202 event->var = var; |
202 event->var = var; |
| 203 event->customdata1 = button; |
203 event->customdata1 = button; |
| 204 event->prepare_event = togglebutton_event; |
204 event->prepare_event = togglebutton_event; |
| 205 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
205 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); |
| 206 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |
206 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); |