|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2014 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef MENU_H |
|
30 #define MENU_H |
|
31 |
|
32 #include "../ui/menu.h" |
|
33 #include <ucx/list.h> |
|
34 |
|
35 #include <QMainWindow> |
|
36 #include <QMenu> |
|
37 #include <QMenuBar> |
|
38 #include <QContextMenuEvent> |
|
39 |
|
40 class UiMenuItemI { |
|
41 public: |
|
42 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) = 0; |
|
43 }; |
|
44 |
|
45 class UiMenu : public UiMenuItemI { |
|
46 public: |
|
47 |
|
48 UcxList *items; |
|
49 char *label; |
|
50 |
|
51 UiMenu(char *label); |
|
52 |
|
53 void addMenuItem(UiMenuItemI *item); |
|
54 |
|
55 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); |
|
56 }; |
|
57 |
|
58 class UiMenuItem : public UiMenuItemI { |
|
59 char *label; |
|
60 ui_callback callback; |
|
61 void *userdata; |
|
62 UcxList *groups; |
|
63 bool checkable = false; |
|
64 |
|
65 public: |
|
66 UiMenuItem(char *label, ui_callback f, void *userdata); |
|
67 void addGroup(int group); |
|
68 void setCheckable(bool c); |
|
69 |
|
70 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); |
|
71 }; |
|
72 |
|
73 class UiStMenuItem : public UiMenuItemI { |
|
74 char *stockid; |
|
75 ui_callback callback; |
|
76 void *userdata; |
|
77 UcxList *groups; |
|
78 |
|
79 public: |
|
80 UiStMenuItem(char *stockid, ui_callback f, void *userdata); |
|
81 void addGroup(int group); |
|
82 |
|
83 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); |
|
84 }; |
|
85 |
|
86 class UiMenuSeparator : public UiMenuItemI { |
|
87 public: |
|
88 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); |
|
89 }; |
|
90 |
|
91 class UiCheckItemNV : public UiMenuItemI { |
|
92 char *label; |
|
93 char *varname; |
|
94 |
|
95 public: |
|
96 UiCheckItemNV(char *label, char *varname); |
|
97 virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); |
|
98 }; |
|
99 |
|
100 |
|
101 class UiAction : public QAction { |
|
102 Q_OBJECT |
|
103 |
|
104 UiObject *obj; |
|
105 ui_callback callback; |
|
106 void *userdata; |
|
107 |
|
108 public: |
|
109 UiAction(UiObject *obj, QString &label, ui_callback f, void *userdata); |
|
110 |
|
111 private slots: |
|
112 void trigger(); |
|
113 }; |
|
114 |
|
115 void ui_add_menus(UiObject *obj, QMainWindow *window); |
|
116 |
|
117 extern "C" int ui_checkitem_get(UiInteger *i); |
|
118 extern "C" void ui_checkitem_set(UiInteger *i, int value); |
|
119 |
|
120 class UiContextMenuHandler : public QObject { |
|
121 Q_OBJECT |
|
122 |
|
123 QWidget *widget; |
|
124 QMenu *menu; |
|
125 |
|
126 public: |
|
127 UiContextMenuHandler(QWidget *widget, QMenu *menu); |
|
128 |
|
129 public slots: |
|
130 void contextMenuEvent(const QPoint & pos); |
|
131 }; |
|
132 |
|
133 #endif /* MENU_H */ |
|
134 |