ui/qt/menu.cpp

Mon, 12 Jan 2015 12:03:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Jan 2015 12:03:05 +0100
changeset 72
a00b46d92c54
parent 71
3e021c5f18a0
child 73
473acef47ddd
permissions
-rw-r--r--

added list view (Qt)

54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <inttypes.h>
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <QMenuBar>
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <QAction>
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "menu.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "toolkit.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../common/context.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../ui/properties.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "../ui/window.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "stock.h"
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 static UcxList *menus;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 static UcxList *current;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 /* -------------------------- UiMenu -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 UiMenu::UiMenu(char* label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 this->items = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 this->label = label;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 void UiMenu::addMenuItem(UiMenuItemI* item) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 items = ucx_list_append(items, item);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 void UiMenu::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 QMenu *m = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 if(menubar) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 m = menubar->addMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 } else {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 m = menu->addMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UCX_FOREACH(elm, items) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 UiMenuItemI *item = (UiMenuItemI*)elm->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 item->addTo(obj, NULL, m);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 /* -------------------------- UiMenuItem -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 UiMenuItem::UiMenuItem(char* label, ui_callback f, void* userdata) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 this->label = label;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 this->userdata = userdata;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 this->groups = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 void UiMenuItem::addGroup(int group) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 groups = ucx_list_append(groups, (void*)(intptr_t)group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
84 void UiMenuItem::setCheckable(bool c) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
85 checkable = c;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
86 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
87
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 void UiMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 QString str = QString::fromUtf8(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 UiAction *action = new UiAction(obj, str, callback, userdata);
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
91 action->setCheckable(checkable);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
92 if(checkable) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
93 action->setChecked(false);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
94 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 menu->addAction(action);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 /* -------------------------- UiStMenuItem -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UiStMenuItem::UiStMenuItem(char* stockid, ui_callback f, void* userdata) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 this->stockid = stockid;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 this->userdata = userdata;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 this->groups = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 void UiStMenuItem::addGroup(int group) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 groups = ucx_list_append(groups, (void*)(intptr_t)group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 void UiStMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 UiStockItem *stockItem = ui_get_stock_item(stockid);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 QString str = QString::fromUtf8(stockItem->label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 UiAction *action = new UiAction(obj, str, callback, userdata);
55
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
118 action->setIcon(QIcon::fromTheme(stockItem->icon_name));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
119 action->setIconVisibleInMenu(true);
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 menu->addAction(action);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 //UiEventWrapper *ev = new UiEventWrapper(callback, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
126 /* -------------------------- UiMenuSeparator -------------------------- */
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
127
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
128 void UiMenuSeparator::addTo(UiObject* obj, QMenuBar* menubar, QMenu* menu) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
129 menu->addSeparator();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
130 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
131
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
132
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
133 /* -------------------------- UiCheckItemNV -------------------------- */
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
134
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
135 UiCheckItemNV::UiCheckItemNV(char* label, char* varname) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
136 this->label = label;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
137 this->varname = varname;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
138 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
139
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
140 void UiCheckItemNV::addTo(UiObject* obj, QMenuBar* menubar, QMenu* menu) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
141 QString str = QString::fromUtf8(label);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
142 UiAction *action = new UiAction(obj, str, NULL, NULL);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
143 action->setCheckable(true);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
144 menu->addAction(action);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
145 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
146
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
147 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_INTEGER);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
148 if(var) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
149 UiInteger *value = (UiInteger*)var->value;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
150 action->setChecked(value->value);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
151 value->obj = action;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
152 value->get = ui_checkitem_get;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
153 value->set = ui_checkitem_set;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
154 value = 0;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
155 } else {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
156 // TODO: error
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
157 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
158 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
159
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
160
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 /* -------------------------- UiAction -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 UiAction::UiAction(UiObject *obj, QString &label, ui_callback f, void* userdata) : QAction(label, NULL) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 //QAction(label, NULL);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 this->obj = obj;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 this->userdata = userdata;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 void UiAction::trigger() {
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
171 if(!callback) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
172 return;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
173 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
174
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 UiEvent e;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 e.obj = obj;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 e.window = obj->window;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 e.document = obj->ctx->document;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 e.eventdata = NULL;
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
180
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
181 if(isCheckable()) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
182 e.intval = isChecked();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
183 } else {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
184 e.intval = 0;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
185 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
186
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 callback(&e, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 void ui_menu(char *label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 // free current menu hierarchy
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 ucx_list_free(current);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 // create menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 UiMenu *menu = new UiMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 current = ucx_list_prepend(NULL, menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 menus = ucx_list_append(menus, menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 void ui_submenu(char *label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 UiMenu *menu = new UiMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 // add submenu to current menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 cm->addMenuItem(menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 // set the submenu to current menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 current = ucx_list_prepend(current, menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 void ui_submenu_end() {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 if(ucx_list_size(current) < 2) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 return;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 current = ucx_list_remove(current, current);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 //UcxList *c = current;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 void ui_menuitem(char *label, ui_callback f, void *userdata) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 ui_menuitem_gr(label, f, userdata, -1);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 ui_menuitem_stgr(stockid, f, userdata, -1);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 if(!current) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 return;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 UiMenuItem *item = new UiMenuItem(label, f, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 // add groups
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 va_list ap;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 va_start(ap, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 int group;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 while((group = va_arg(ap, int)) != -1) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 item->addGroup(group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 va_end(ap);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 cm->addMenuItem(item);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 void ui_menuitem_stgr(char *stockid, ui_callback f, void *userdata, ...) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 if(!current) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 return;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 UiStMenuItem *item = new UiStMenuItem(stockid, f, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 // add groups
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 va_list ap;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 va_start(ap, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 int group;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 while((group = va_arg(ap, int)) != -1) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 item->addGroup(group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 va_end(ap);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 cm->addMenuItem(item);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
270 void ui_menuseparator() {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
271 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
272 return;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
273 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
274
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
275 UiMenuSeparator *item = new UiMenuSeparator();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
276 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
277 cm->addMenuItem(item);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
278 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
280 void ui_checkitem(char *label, ui_callback f, void *userdata) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
281 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
282 return;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
283 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
284
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
285 UiMenuItem *item = new UiMenuItem(label, f, userdata);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
286 item->setCheckable(true);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
287
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
288 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
289 cm->addMenuItem(item);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
290 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
292 void ui_checkitem_nv(char *label, char *vname) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
293 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
294 return;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
295 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
296
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
297 UiCheckItemNV *item = new UiCheckItemNV(label, vname);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
298
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
299 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
300 cm->addMenuItem(item);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
301 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
302
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
303 void ui_menuitem_list(UiList *items, ui_callback f, void *userdata) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
304
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
305 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 void ui_add_menus(UiObject *obj, QMainWindow *window) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 QMenuBar *mb = window->menuBar();
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 UCX_FOREACH(elm, menus) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 UiMenu *menu = (UiMenu*)elm->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 menu->addTo(obj, mb, NULL);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 }
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
315
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
316 int ui_checkitem_get(UiInteger *i) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
317 QAction *action = (QAction*)i->obj;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
318 i->value = action->isChecked();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
319 return i->value;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
320 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
321
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
322 void ui_checkitem_set(UiInteger *i, int value) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
323 QAction *action = (QAction*)i->obj;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
324 i->value = value;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
325 action->setChecked(value);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
326 }

mercurial