79 |
79 |
80 void UiMenuItem::addGroup(int group) { |
80 void UiMenuItem::addGroup(int group) { |
81 groups = ucx_list_append(groups, (void*)(intptr_t)group); |
81 groups = ucx_list_append(groups, (void*)(intptr_t)group); |
82 } |
82 } |
83 |
83 |
|
84 void UiMenuItem::setCheckable(bool c) { |
|
85 checkable = c; |
|
86 } |
|
87 |
84 void UiMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { |
88 void UiMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { |
85 QString str = QString::fromUtf8(label); |
89 QString str = QString::fromUtf8(label); |
86 UiAction *action = new UiAction(obj, str, callback, userdata); |
90 UiAction *action = new UiAction(obj, str, callback, userdata); |
|
91 action->setCheckable(checkable); |
|
92 if(checkable) { |
|
93 action->setChecked(false); |
|
94 } |
87 menu->addAction(action); |
95 menu->addAction(action); |
88 //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); |
|
89 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
96 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
90 } |
97 } |
91 |
98 |
92 |
99 |
93 /* -------------------------- UiStMenuItem -------------------------- */ |
100 /* -------------------------- UiStMenuItem -------------------------- */ |
114 //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); |
121 //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); |
115 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
122 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
116 } |
123 } |
117 |
124 |
118 |
125 |
|
126 /* -------------------------- UiMenuSeparator -------------------------- */ |
|
127 |
|
128 void UiMenuSeparator::addTo(UiObject* obj, QMenuBar* menubar, QMenu* menu) { |
|
129 menu->addSeparator(); |
|
130 } |
|
131 |
|
132 |
|
133 /* -------------------------- UiCheckItemNV -------------------------- */ |
|
134 |
|
135 UiCheckItemNV::UiCheckItemNV(char* label, char* varname) { |
|
136 this->label = label; |
|
137 this->varname = varname; |
|
138 } |
|
139 |
|
140 void UiCheckItemNV::addTo(UiObject* obj, QMenuBar* menubar, QMenu* menu) { |
|
141 QString str = QString::fromUtf8(label); |
|
142 UiAction *action = new UiAction(obj, str, NULL, NULL); |
|
143 action->setCheckable(true); |
|
144 menu->addAction(action); |
|
145 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
|
146 |
|
147 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_INTEGER); |
|
148 if(var) { |
|
149 UiInteger *value = (UiInteger*)var->value; |
|
150 action->setChecked(value->value); |
|
151 value->obj = action; |
|
152 value->get = ui_checkitem_get; |
|
153 value->set = ui_checkitem_set; |
|
154 value = 0; |
|
155 } else { |
|
156 // TODO: error |
|
157 } |
|
158 } |
|
159 |
|
160 |
119 /* -------------------------- UiAction -------------------------- */ |
161 /* -------------------------- UiAction -------------------------- */ |
120 |
162 |
121 UiAction::UiAction(UiObject *obj, QString &label, ui_callback f, void* userdata) : QAction(label, NULL) { |
163 UiAction::UiAction(UiObject *obj, QString &label, ui_callback f, void* userdata) : QAction(label, NULL) { |
122 //QAction(label, NULL); |
164 //QAction(label, NULL); |
123 this->obj = obj; |
165 this->obj = obj; |
124 this->callback = f; |
166 this->callback = f; |
125 this->userdata = userdata; |
167 this->userdata = userdata; |
126 } |
168 } |
127 |
169 |
128 void UiAction::trigger() { |
170 void UiAction::trigger() { |
|
171 if(!callback) { |
|
172 return; |
|
173 } |
|
174 |
129 UiEvent e; |
175 UiEvent e; |
130 e.obj = obj; |
176 e.obj = obj; |
131 e.window = obj->window; |
177 e.window = obj->window; |
132 e.document = obj->ctx->document; |
178 e.document = obj->ctx->document; |
133 e.eventdata = NULL; |
179 e.eventdata = NULL; |
134 e.intval = 0; |
180 |
|
181 if(isCheckable()) { |
|
182 e.intval = isChecked(); |
|
183 } else { |
|
184 e.intval = 0; |
|
185 } |
|
186 |
135 callback(&e, userdata); |
187 callback(&e, userdata); |
136 } |
188 } |
137 |
189 |
138 |
190 |
139 void ui_menu(char *label) { |
191 void ui_menu(char *label) { |
213 |
265 |
214 UiMenu *cm = (UiMenu*)current->data; |
266 UiMenu *cm = (UiMenu*)current->data; |
215 cm->addMenuItem(item); |
267 cm->addMenuItem(item); |
216 } |
268 } |
217 |
269 |
218 |
270 void ui_menuseparator() { |
219 |
271 if(!current) { |
|
272 return; |
|
273 } |
|
274 |
|
275 UiMenuSeparator *item = new UiMenuSeparator(); |
|
276 UiMenu *cm = (UiMenu*)current->data; |
|
277 cm->addMenuItem(item); |
|
278 } |
|
279 |
|
280 void ui_checkitem(char *label, ui_callback f, void *userdata) { |
|
281 if(!current) { |
|
282 return; |
|
283 } |
|
284 |
|
285 UiMenuItem *item = new UiMenuItem(label, f, userdata); |
|
286 item->setCheckable(true); |
|
287 |
|
288 UiMenu *cm = (UiMenu*)current->data; |
|
289 cm->addMenuItem(item); |
|
290 } |
|
291 |
|
292 void ui_checkitem_nv(char *label, char *vname) { |
|
293 if(!current) { |
|
294 return; |
|
295 } |
|
296 |
|
297 UiCheckItemNV *item = new UiCheckItemNV(label, vname); |
|
298 |
|
299 UiMenu *cm = (UiMenu*)current->data; |
|
300 cm->addMenuItem(item); |
|
301 } |
|
302 |
|
303 void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) { |
|
304 |
|
305 } |
220 |
306 |
221 void ui_add_menus(UiObject *obj, QMainWindow *window) { |
307 void ui_add_menus(UiObject *obj, QMainWindow *window) { |
222 QMenuBar *mb = window->menuBar(); |
308 QMenuBar *mb = window->menuBar(); |
223 |
309 |
224 UCX_FOREACH(elm, menus) { |
310 UCX_FOREACH(elm, menus) { |
225 UiMenu *menu = (UiMenu*)elm->data; |
311 UiMenu *menu = (UiMenu*)elm->data; |
226 menu->addTo(obj, mb, NULL); |
312 menu->addTo(obj, mb, NULL); |
227 } |
313 } |
228 } |
314 } |
|
315 |
|
316 int ui_checkitem_get(UiInteger *i) { |
|
317 QAction *action = (QAction*)i->obj; |
|
318 i->value = action->isChecked(); |
|
319 return i->value; |
|
320 } |
|
321 |
|
322 void ui_checkitem_set(UiInteger *i, int value) { |
|
323 QAction *action = (QAction*)i->obj; |
|
324 i->value = value; |
|
325 action->setChecked(value); |
|
326 } |