ui/qt/button.cpp

changeset 112
c3f2f16fa4b8
parent 109
c3dfcb8f0be7
equal deleted inserted replaced
111:81c4f73236a4 112:c3f2f16fa4b8
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);
36 35
37 QString str = QString::fromUtf8(args->label); 36 QString str = QString::fromUtf8(args->label);
38 QPushButton *button = new QPushButton(str); 37 QPushButton *button = new QPushButton(str);
39 38
40 if(args->onclick) { 39 if(args->onclick) {
41 UiEventWrapper *event = new UiEventWrapper(obj, args->onclick, args->onclickdata); 40 UiEventWrapper *event = new UiEventWrapper(obj, args->onclick, args->onclickdata);
42 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); 41 button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
43 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); 42 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy()));
44 } 43 }
45 44
46 ctn->add(button); 45 UiLayout layout = UI_ARGS2LAYOUT(args);
46 ctn->add(button, layout);
47 47
48 return button; 48 return button;
49 } 49 }
50 50
51 void ui_button_set_label(UIWIDGET button, const char *label) { 51 void ui_button_set_label(UIWIDGET button, const char *label) {
67 } 67 }
68 } 68 }
69 69
70 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) { 70 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) {
71 UiContainerPrivate *ctn = ui_obj_container(obj); 71 UiContainerPrivate *ctn = ui_obj_container(obj);
72 UI_APPLY_LAYOUT(ctn->layout, args);
73 72
74 QString str = QString::fromUtf8(args->label); 73 QString str = QString::fromUtf8(args->label);
75 QPushButton *button = new QPushButton(str); 74 QPushButton *button = new QPushButton(str);
76 button->setCheckable(true); 75 button->setCheckable(true);
77 76
96 i->obj = button; 95 i->obj = button;
97 i->get = ui_togglebutton_get; 96 i->get = ui_togglebutton_get;
98 i->set = ui_togglebutton_set; 97 i->set = ui_togglebutton_set;
99 } 98 }
100 99
101 ctn->add(button); 100 UiLayout layout = UI_ARGS2LAYOUT(args);
101 ctn->add(button, layout);
102 102
103 return button; 103 return button;
104 } 104 }
105 105
106 int64_t ui_togglebutton_get(UiInteger *value) { 106 int64_t ui_togglebutton_get(UiInteger *value) {
127 } 127 }
128 128
129 129
130 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { 130 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) {
131 UiContainerPrivate *ctn = ui_obj_container(obj); 131 UiContainerPrivate *ctn = ui_obj_container(obj);
132 UI_APPLY_LAYOUT(ctn->layout, args);
133 132
134 QString str = QString::fromUtf8(args->label); 133 QString str = QString::fromUtf8(args->label);
135 QCheckBox *checkbox = new QCheckBox(str); 134 QCheckBox *checkbox = new QCheckBox(str);
136 135
137 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER); 136 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER);
155 i->obj = checkbox; 154 i->obj = checkbox;
156 i->get = ui_checkbox_get; 155 i->get = ui_checkbox_get;
157 i->set = ui_checkbox_set; 156 i->set = ui_checkbox_set;
158 } 157 }
159 158
160 ctn->add(checkbox); 159 UiLayout layout = UI_ARGS2LAYOUT(args);
160 ctn->add(checkbox, layout);
161 161
162 return checkbox; 162 return checkbox;
163 } 163 }
164 164
165 int64_t ui_checkbox_get(UiInteger *value) { 165 int64_t ui_checkbox_get(UiInteger *value) {
186 } 186 }
187 } 187 }
188 188
189 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) { 189 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) {
190 UiContainerPrivate *ctn = ui_obj_container(obj); 190 UiContainerPrivate *ctn = ui_obj_container(obj);
191 UI_APPLY_LAYOUT(ctn->layout, args);
192 191
193 QString str = QString::fromUtf8(args->label); 192 QString str = QString::fromUtf8(args->label);
194 QRadioButton *button = new QRadioButton(str); 193 QRadioButton *button = new QRadioButton(str);
195 button->setAutoExclusive(false); 194 button->setAutoExclusive(false);
196 195
216 event->customdata1 = button; 215 event->customdata1 = button;
217 event->prepare_event = togglebutton_event; 216 event->prepare_event = togglebutton_event;
218 button->connect(button, SIGNAL(clicked()), event, SLOT(slot())); 217 button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
219 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy())); 218 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy()));
220 219
221 ctn->add(button); 220 UiLayout layout = UI_ARGS2LAYOUT(args);
221 ctn->add(button, layout);
222 222
223 return button; 223 return button;
224 } 224 }
225 225
226 int64_t ui_radiobutton_get(UiInteger *value) { 226 int64_t ui_radiobutton_get(UiInteger *value) {

mercurial