ui/qt/menu.cpp

Wed, 30 Oct 2024 15:32:38 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 30 Oct 2024 15:32:38 +0100
branch
newapi
changeset 376
5578494147cb
parent 115
102fc0b8fe3e
permissions
-rw-r--r--

fix condvar windows implementation

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"
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
41 #include "container.h"
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 static UcxList *menus;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 static UcxList *current;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 /* -------------------------- UiMenu -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 UiMenu::UiMenu(char* label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 this->items = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 this->label = label;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 void UiMenu::addMenuItem(UiMenuItemI* item) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 items = ucx_list_append(items, item);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 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
58 QMenu *m = NULL;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 if(menubar) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 m = menubar->addMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 } else {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 m = menu->addMenu(label);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 UCX_FOREACH(elm, items) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UiMenuItemI *item = (UiMenuItemI*)elm->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 item->addTo(obj, NULL, m);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /* -------------------------- UiMenuItem -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 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
75 this->label = label;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 this->userdata = userdata;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 this->groups = NULL;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 void UiMenuItem::addGroup(int group) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 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
83 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
85 void UiMenuItem::setCheckable(bool c) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
86 checkable = c;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
87 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
88
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 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
90 QString str = QString::fromUtf8(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 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
92 action->setCheckable(checkable);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
93 if(checkable) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
94 action->setChecked(false);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
95 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 menu->addAction(action);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 /* -------------------------- UiStMenuItem -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 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
104 this->stockid = stockid;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 this->userdata = userdata;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 this->groups = NULL;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 void UiStMenuItem::addGroup(int group) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 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
112 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 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
115 UiStockItem *stockItem = ui_get_stock_item(stockid);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 QString str = QString::fromUtf8(stockItem->label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 UiAction *action = new UiAction(obj, str, callback, userdata);
55
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
119 action->setIcon(QIcon::fromTheme(stockItem->icon_name));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
120 action->setIconVisibleInMenu(true);
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 menu->addAction(action);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 //UiEventWrapper *ev = new UiEventWrapper(callback, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
127 /* -------------------------- UiMenuSeparator -------------------------- */
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
128
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
129 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
130 menu->addSeparator();
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
134 /* -------------------------- UiCheckItemNV -------------------------- */
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
135
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
136 UiCheckItemNV::UiCheckItemNV(char* label, char* varname) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
137 this->label = label;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
138 this->varname = varname;
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
141 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
142 QString str = QString::fromUtf8(label);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
143 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
144 action->setCheckable(true);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
145 menu->addAction(action);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
146 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
147
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
148 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
149 if(var) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
150 UiInteger *value = (UiInteger*)var->value;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
151 action->setChecked(value->value);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
152 value->obj = action;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
153 value->get = ui_checkitem_get;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
154 value->set = ui_checkitem_set;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
155 value = 0;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
156 } else {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
157 // TODO: error
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
161
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 /* -------------------------- UiAction -------------------------- */
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 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
165 //QAction(label, NULL);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 this->obj = obj;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 this->callback = f;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 this->userdata = userdata;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 void UiAction::trigger() {
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
172 if(!callback) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
173 return;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
174 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
175
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UiEvent e;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 e.obj = obj;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 e.window = obj->window;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 e.document = obj->ctx->document;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 e.eventdata = NULL;
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
181
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
182 if(isCheckable()) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
183 e.intval = isChecked();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
184 } else {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
185 e.intval = 0;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
186 }
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
187
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 callback(&e, userdata);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 void ui_menu(char *label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 // free current menu hierarchy
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 ucx_list_free(current);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 // create menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 UiMenu *menu = new UiMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 current = ucx_list_prepend(NULL, menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 menus = ucx_list_append(menus, menu);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 void ui_submenu(char *label) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 UiMenu *menu = new UiMenu(label);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 // add submenu to current menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 cm->addMenuItem(menu);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 // set the submenu to current menu
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 current = ucx_list_prepend(current, menu);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 void ui_submenu_end() {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 if(ucx_list_size(current) < 2) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 return;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 current = ucx_list_remove(current, current);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 //UcxList *c = current;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 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
224 ui_menuitem_gr(label, f, userdata, -1);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 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
228 ui_menuitem_stgr(stockid, f, userdata, -1);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 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
232 if(!current) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 return;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 UiMenuItem *item = new UiMenuItem(label, f, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 // add groups
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 va_list ap;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 va_start(ap, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 int group;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 while((group = va_arg(ap, int)) != -1) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 item->addGroup(group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 va_end(ap);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 cm->addMenuItem(item);
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 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
252 if(!current) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 return;
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
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 UiStMenuItem *item = new UiStMenuItem(stockid, f, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 // add groups
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 va_list ap;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 va_start(ap, userdata);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 int group;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 while((group = va_arg(ap, int)) != -1) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 item->addGroup(group);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 va_end(ap);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 UiMenu *cm = (UiMenu*)current->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 cm->addMenuItem(item);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
271 void ui_menuseparator() {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
272 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
273 return;
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
276 UiMenuSeparator *item = new UiMenuSeparator();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
277 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
278 cm->addMenuItem(item);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
279 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
281 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
282 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
283 return;
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
286 UiMenuItem *item = new UiMenuItem(label, f, userdata);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
287 item->setCheckable(true);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
288
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
289 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
290 cm->addMenuItem(item);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
291 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
293 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
294 if(!current) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
295 return;
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
298 UiCheckItemNV *item = new UiCheckItemNV(label, vname);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
299
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
300 UiMenu *cm = (UiMenu*)current->data;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
301 cm->addMenuItem(item);
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
304 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
305
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
306 }
54
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 void ui_add_menus(UiObject *obj, QMainWindow *window) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 QMenuBar *mb = window->menuBar();
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 UCX_FOREACH(elm, menus) {
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 UiMenu *menu = (UiMenu*)elm->data;
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 menu->addTo(obj, mb, NULL);
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 }
97bafeca1c7c added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 }
71
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
316
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
317 int ui_checkitem_get(UiInteger *i) {
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
318 QAction *action = (QAction*)i->obj;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
319 i->value = action->isChecked();
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
320 return i->value;
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
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
323 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
324 QAction *action = (QAction*)i->obj;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
325 i->value = value;
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
326 action->setChecked(value);
3e021c5f18a0 added check item for menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
327 }
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
328
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
329
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
330 /*
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
331 * widget menu functions
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
332 */
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
333
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
334 UiContextMenuHandler::UiContextMenuHandler(QWidget *widget, QMenu* menu) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
335 this->widget = widget;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
336 this->menu = menu;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
337 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
338
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
339 void UiContextMenuHandler::contextMenuEvent(const QPoint & pos) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
340 menu->popup(widget->mapToGlobal(pos));
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
341 }
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
342 UIMENU ui_contextmenu(UiObject *obj) {
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
343 UiContainer *ct = uic_get_current_container(obj);
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
344 return ui_contextmenu_w(obj, ct->current);
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
345 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
346
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
347 UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) {
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
348 UiContainer *ct = uic_get_current_container(obj);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
349
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
350 QMenu *menu = new QMenu(widget);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
351 widget->setContextMenuPolicy(Qt::CustomContextMenu);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
352
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
353 UiContextMenuHandler *handler = new UiContextMenuHandler(widget, menu);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
354 QObject::connect(
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
355 widget,
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
356 SIGNAL(customContextMenuRequested(QPoint)),
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
357 handler,
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
358 SLOT(contextMenuEvent(QPoint)));
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
359
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
360 ct->menu = menu;
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
361
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
362 return menu;
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
363 }
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
364
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
365 void ui_contextmenu_popup(UIMENU menu) {
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
366
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
367 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
368
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
369 void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
370 ui_widget_menuitem_gr(obj, label, f, userdata, -1);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
371 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
372
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
373 void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
374 UiContainer *ct = uic_get_current_container(obj);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
375 if(!ct->menu) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
376 return;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
377 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
378
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
379 // add groups
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
380 UcxList *groups = NULL;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
381 va_list ap;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
382 va_start(ap, userdata);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
383 int group;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
384 while((group = va_arg(ap, int)) != -1) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
385 ucx_list_append(groups, (void*)(intptr_t)group);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
386 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
387 va_end(ap);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
388
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
389 // create menuitem
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
390 QString str = QString::fromUtf8(label);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
391 UiAction *action = new UiAction(obj, str, f, userdata);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
392 ct->menu->addAction(action);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
393 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
394 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
395
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
396 void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
397 ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
398 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
399
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
400 void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
401 UiContainer *ct = uic_get_current_container(obj);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
402 if(!ct->menu) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
403 return;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
404 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
405
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
406 // add groups
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
407 UcxList *groups = NULL;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
408 va_list ap;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
409 va_start(ap, userdata);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
410 int group;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
411 while((group = va_arg(ap, int)) != -1) {
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
412 ucx_list_append(groups, (void*)(intptr_t)group);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
413 }
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
414 va_end(ap);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
415
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
416 // create menuitem
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
417 UiStockItem *stockItem = ui_get_stock_item(stockid);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
418
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
419 QString str = QString::fromUtf8(stockItem->label);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
420 UiAction *action = new UiAction(obj, str, f, userdata);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
421 action->setIcon(QIcon::fromTheme(stockItem->icon_name));
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
422 action->setIconVisibleInMenu(true);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
423 ct->menu->addAction(action);
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
424 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
425 }

mercurial