ui/qt/toolbar.cpp

Fri, 15 Nov 2024 21:25:35 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 15 Nov 2024 21:25:35 +0100
branch
newapi
changeset 385
e3a01a99236d
parent 157
0b33b9396851
permissions
-rw-r--r--

add ui_dialog_window reference counting (GTK)

55
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
9076eb40454d added toolbar (Qt)
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
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
157
0b33b9396851 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
29 #include <ucx/map.h>
55
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <inttypes.h>
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "toolbar.h"
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "menu.h"
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "stock.h"
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 static UcxMap *toolbar_items = ucx_map_new(16);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 static UcxList *defaults;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 /* ------------------------- UiToolItem ------------------------- */
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 UiToolItem::UiToolItem(char *label, ui_callback f, void *userdata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 this->label = label;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 this->image = NULL;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 this->callback = f;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 this->userdata = userdata;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 this->isimportant = false;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 this->groups = NULL;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 void UiToolItem::addGroup(int group) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 groups = ucx_list_append(groups, (void*)(intptr_t)group);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 void UiToolItem::addTo(UiObject *obj, QToolBar *toolbar) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 QString str = QString::fromUtf8(label);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 UiAction *action = new UiAction(obj, str, callback, userdata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 action->setIcon(QIcon::fromTheme(image));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 toolbar->addAction(action);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 /* ------------------------- UiStockToolItem ------------------------- */
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 UiStockToolItem::UiStockToolItem(char *stockid, ui_callback f, void *userdata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 this->stockid = stockid;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 this->callback = f;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 this->userdata = userdata;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 this->isimportant = false;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 this->groups = NULL;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 void UiStockToolItem::addGroup(int group) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 groups = ucx_list_append(groups, (void*)(intptr_t)group);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 void UiStockToolItem::addTo(UiObject *obj, QToolBar *toolbar) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 UiStockItem *stockItem = ui_get_stock_item(stockid);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 QString str = QString::fromUtf8(stockItem->label);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UiAction *action = new UiAction(obj, str, callback, userdata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 action->setIcon(QIcon::fromTheme(stockItem->icon_name));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 toolbar->addAction(action);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 void ui_toolitem_vstgr(
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 char *name,
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 char *stockid,
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 int isimportant,
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 ui_callback f,
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 void *userdata,
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 va_list ap)
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 UiStockToolItem *item = new UiStockToolItem(stockid, f, userdata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 item->isimportant = isimportant;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 // add groups
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 int group;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 while((group = va_arg(ap, int)) != -1) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 item->addGroup(group);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 ucx_map_cstr_put(toolbar_items, name, item);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 UiToolItem *item = new UiToolItem(label, f, udata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 item->image = img;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 item->isimportant = false;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 ucx_map_cstr_put(toolbar_items, name, item);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 ui_toolitem_img(name, label, NULL, f, udata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 ui_toolitem_stgr(name, stockid, f, userdata, -1);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 void ui_toolitem_sti(char *name, char *stockid, ui_callback f, void *userdata) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 ui_toolitem_stgri(name, stockid, f, userdata, -1);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *userdata, ...) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 va_list ap;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 va_start(ap, userdata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 ui_toolitem_vstgr(name, stockid, 0, f, userdata, ap);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 va_end(ap);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 void ui_toolitem_stgri(char *name, char *stockid, ui_callback f, void *userdata, ...) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 va_list ap;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 va_start(ap, userdata);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 ui_toolitem_vstgr(name, stockid, 1, f, userdata, ap);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 va_end(ap);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 void ui_toolbar_add_default(char *name) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 char *s = strdup(name);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 defaults = ucx_list_append(defaults, s);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 QToolBar* ui_create_toolbar(UiObject *obj) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 QToolBar *toolbar = new QToolBar();
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 UCX_FOREACH(elm, defaults) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 UiToolItemI *item = (UiToolItemI*)ucx_map_cstr_get(toolbar_items, (char*)elm->data);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 if(item) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 item->addTo(obj, toolbar);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 } else if(!strcmp((char*)elm->data, "@separator")) {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 } else {
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data);
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 return toolbar;
9076eb40454d added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }

mercurial