ui/qt/button.cpp

changeset 526
f6a6b0b08641
parent 520
ea1bba55de44
child 550
0412c4c1048e
equal deleted inserted replaced
525:878df45e6441 526:f6a6b0b08641
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 } 44 }
44 45
45 ctn->add(button, false); 46 ctn->add(button, false);
46 47
47 return button; 48 return button;
48 } 49 }
49 50
51 static void togglebutton_event(UiEvent *event, UiEventWrapper *wrapper) {
52 QPushButton *button = (QPushButton*)wrapper->customdata1;
53 event->intval = button->isChecked();
54 if(wrapper->var) {
55 event->eventdata = wrapper->var->value;
56 }
57 }
58
59 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) {
60 UiContainerPrivate *ctn = ui_obj_container(obj);
61 UI_APPLY_LAYOUT(ctn->layout, args);
62
63 QString str = QString::fromUtf8(args.label);
64 QPushButton *button = new QPushButton(str);
65 button->setCheckable(true);
66
67 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER);
68
69 if(args.onchange) {
70 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata);
71 event->var = var;
72 event->customdata1 = button;
73 event->prepare_event = togglebutton_event;
74 button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
75 button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy()));
76 }
77
78 if(var) {
79 UiInteger *i = (UiInteger*)var->value;
80
81 if(i->value) {
82 button->setChecked(true);
83 }
84
85 i->obj = button;
86 i->get = ui_togglebutton_get;
87 i->set = ui_togglebutton_set;
88 }
89
90 ctn->add(button, false);
91
92 return button;
93 }
94
95 int64_t ui_togglebutton_get(UiInteger *value) {
96 QPushButton *button = (QPushButton*)value->obj;
97 value->value = button->isChecked();
98 return value->value;
99 }
100
101 void ui_togglebutton_set(UiInteger *value, int64_t i) {
102 QPushButton *button = (QPushButton*)value->obj;
103 value->value = i;
104 if(i != 0) {
105 button->setChecked(true);
106 }
107 }
108
109 static void checkbox_event(UiEvent *event, UiEventWrapper *wrapper) {
110 QPushButton *button = (QPushButton*)wrapper->customdata1;
111 event->intval = button->isChecked();
112 if(wrapper->var) {
113 event->eventdata = wrapper->var->value;
114 }
115 }
116
117
118 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) {
119 UiContainerPrivate *ctn = ui_obj_container(obj);
120 UI_APPLY_LAYOUT(ctn->layout, args);
121
122 QString str = QString::fromUtf8(args.label);
123 QCheckBox *checkbox = new QCheckBox(str);
124
125 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER);
126
127 if(args.onchange) {
128 UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata);
129 event->var = var;
130 event->customdata1 = checkbox;
131 event->prepare_event = checkbox_event;
132 checkbox->connect(checkbox, SIGNAL(clicked()), event, SLOT(slot()));
133 checkbox->connect(checkbox, SIGNAL(destroyed()), event, SLOT(destroy()));
134 }
135
136 if(var) {
137 UiInteger *i = (UiInteger*)var->value;
138
139 if(i->value) {
140 checkbox->setChecked(true);
141 }
142
143 i->obj = checkbox;
144 i->get = ui_checkbox_get;
145 i->set = ui_checkbox_set;
146 }
147
148 ctn->add(checkbox, false);
149
150 return checkbox;
151 }
152
153 int64_t ui_checkbox_get(UiInteger *value) {
154 QPushButton *button = (QPushButton*)value->obj;
155 value->value = button->isChecked();
156 return value->value;
157 }
158
159 void ui_checkbox_set(UiInteger *value, int64_t i) {
160 QPushButton *button = (QPushButton*)value->obj;
161 value->value = i;
162 if(i != 0) {
163 button->setChecked(true);
164 }
165 }

mercurial