1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * UIActionPool class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2010-2013 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef __UIActionPool_h__
|
---|
20 | #define __UIActionPool_h__
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | #include <QAction>
|
---|
24 | #include <QMenu>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "QIWithRetranslateUI.h"
|
---|
28 |
|
---|
29 | /* Forward declarations: */
|
---|
30 | class UIActionState;
|
---|
31 |
|
---|
32 | /* Action types: */
|
---|
33 | enum UIActionType
|
---|
34 | {
|
---|
35 | UIActionType_Simple,
|
---|
36 | UIActionType_State,
|
---|
37 | UIActionType_Toggle,
|
---|
38 | UIActionType_Menu
|
---|
39 | };
|
---|
40 |
|
---|
41 | /* Action keys: */
|
---|
42 | enum UIActionIndex
|
---|
43 | {
|
---|
44 | /* Various dialog actions: */
|
---|
45 | UIActionIndex_Simple_LogDialog,
|
---|
46 |
|
---|
47 | /* 'Help' menu actions: */
|
---|
48 | UIActionIndex_Menu_Help,
|
---|
49 | UIActionIndex_Simple_Contents,
|
---|
50 | UIActionIndex_Simple_WebSite,
|
---|
51 | UIActionIndex_Simple_ResetWarnings,
|
---|
52 | UIActionIndex_Simple_NetworkAccessManager,
|
---|
53 | UIActionIndex_Simple_CheckForUpdates,
|
---|
54 | UIActionIndex_Simple_About,
|
---|
55 |
|
---|
56 | /* Maximum index: */
|
---|
57 | UIActionIndex_Max
|
---|
58 | };
|
---|
59 |
|
---|
60 | /* Basic abstract QAction reimplemetation, extending interface: */
|
---|
61 | class UIAction : public QIWithRetranslateUI3<QAction>
|
---|
62 | {
|
---|
63 | Q_OBJECT;
|
---|
64 |
|
---|
65 | public:
|
---|
66 |
|
---|
67 | /* API: RTTI: */
|
---|
68 | UIActionType type() const { return m_type; }
|
---|
69 |
|
---|
70 | /* API: Update stuff: */
|
---|
71 | virtual void update() {}
|
---|
72 |
|
---|
73 | /* API: Cast stuff: */
|
---|
74 | UIActionState* toStateAction();
|
---|
75 |
|
---|
76 | /* API: Shortcut stuff: */
|
---|
77 | void setShortcut(const QKeySequence &shortcut);
|
---|
78 | void showShortcut();
|
---|
79 | void hideShortcut();
|
---|
80 |
|
---|
81 | protected:
|
---|
82 |
|
---|
83 | /* Constructor: */
|
---|
84 | UIAction(QObject *pParent, UIActionType type);
|
---|
85 |
|
---|
86 | /* Protected API: Menu stuff: */
|
---|
87 | QString menuText(const QString &strText);
|
---|
88 |
|
---|
89 | private:
|
---|
90 |
|
---|
91 | /* Variables: */
|
---|
92 | UIActionType m_type;
|
---|
93 | QKeySequence m_shortcut;
|
---|
94 | };
|
---|
95 |
|
---|
96 | /* Basic QMenu reimplemetation, extending interface: */
|
---|
97 | class UIMenu : public QMenu
|
---|
98 | {
|
---|
99 | Q_OBJECT;
|
---|
100 |
|
---|
101 | public:
|
---|
102 |
|
---|
103 | /* Constructor: */
|
---|
104 | UIMenu();
|
---|
105 |
|
---|
106 | /* API: Tool-tip stuff: */
|
---|
107 | void setShowToolTips(bool fShowToolTips) { m_fShowToolTips = fShowToolTips; }
|
---|
108 | bool isToolTipsShown() const { return m_fShowToolTips; }
|
---|
109 |
|
---|
110 | private:
|
---|
111 |
|
---|
112 | /* Helper: Event stuff: */
|
---|
113 | bool event(QEvent *pEvent);
|
---|
114 |
|
---|
115 | /* Variables: */
|
---|
116 | bool m_fShowToolTips;
|
---|
117 | };
|
---|
118 |
|
---|
119 | /* Abstract extention for UIAction, describing 'simple' action type: */
|
---|
120 | class UIActionSimple : public UIAction
|
---|
121 | {
|
---|
122 | Q_OBJECT;
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | /* Constructors: */
|
---|
127 | UIActionSimple(QObject *pParent,
|
---|
128 | const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
129 | UIActionSimple(QObject *pParent,
|
---|
130 | const QSize &normalSize, const QSize &smallSize,
|
---|
131 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
132 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
133 | UIActionSimple(QObject *pParent, const QIcon& icon);
|
---|
134 | };
|
---|
135 |
|
---|
136 | /* Abstract extention for UIAction, describing 'state' action type: */
|
---|
137 | class UIActionState : public UIAction
|
---|
138 | {
|
---|
139 | Q_OBJECT;
|
---|
140 |
|
---|
141 | public:
|
---|
142 |
|
---|
143 | /* API: State stuff: */
|
---|
144 | void setState(int iState) { m_iState = iState; retranslateUi(); }
|
---|
145 |
|
---|
146 | protected:
|
---|
147 |
|
---|
148 | /* Constructors: */
|
---|
149 | UIActionState(QObject *pParent,
|
---|
150 | const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
151 | UIActionState(QObject *pParent,
|
---|
152 | const QSize &normalSize, const QSize &smallSize,
|
---|
153 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
154 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
155 | UIActionState(QObject *pParent, const QIcon& icon);
|
---|
156 |
|
---|
157 | /* Variables: */
|
---|
158 | int m_iState;
|
---|
159 | };
|
---|
160 |
|
---|
161 | /* Abstract extention for UIAction, describing 'toggle' action type: */
|
---|
162 | class UIActionToggle : public UIAction
|
---|
163 | {
|
---|
164 | Q_OBJECT;
|
---|
165 |
|
---|
166 | protected:
|
---|
167 |
|
---|
168 | /* Constructors: */
|
---|
169 | UIActionToggle(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
170 | UIActionToggle(QObject *pParent,
|
---|
171 | const QSize &normalSize, const QSize &smallSize,
|
---|
172 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
173 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
174 | UIActionToggle(QObject *pParent, const QString &strIconOn, const QString &strIconOff, const QString &strIconOnDis, const QString &strIconOffDis);
|
---|
175 | UIActionToggle(QObject *pParent, const QIcon &icon);
|
---|
176 |
|
---|
177 | /* API reimplementation: Update stuff: */
|
---|
178 | void update() { sltUpdate(); }
|
---|
179 |
|
---|
180 | private slots:
|
---|
181 |
|
---|
182 | /* Handler: Update stuff: */
|
---|
183 | void sltUpdate();
|
---|
184 |
|
---|
185 | private:
|
---|
186 |
|
---|
187 | /* Helper: Prepare stuff: */
|
---|
188 | void init();
|
---|
189 | };
|
---|
190 |
|
---|
191 | /* Abstract extention for UIAction, describing 'menu' action type: */
|
---|
192 | class UIActionMenu : public UIAction
|
---|
193 | {
|
---|
194 | Q_OBJECT;
|
---|
195 |
|
---|
196 | protected:
|
---|
197 |
|
---|
198 | /* Constructors: */
|
---|
199 | UIActionMenu(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
200 | UIActionMenu(QObject *pParent, const QIcon &icon);
|
---|
201 | };
|
---|
202 |
|
---|
203 | /* Action pool types: */
|
---|
204 | enum UIActionPoolType
|
---|
205 | {
|
---|
206 | UIActionPoolType_Selector,
|
---|
207 | UIActionPoolType_Runtime
|
---|
208 | };
|
---|
209 |
|
---|
210 | /* Singleton action pool: */
|
---|
211 | class UIActionPool : public QObject
|
---|
212 | {
|
---|
213 | Q_OBJECT;
|
---|
214 |
|
---|
215 | public:
|
---|
216 |
|
---|
217 | /* API: Singleton stuff: */
|
---|
218 | static UIActionPool* instance();
|
---|
219 | static void create(UIActionPoolType type);
|
---|
220 | static void destroy();
|
---|
221 |
|
---|
222 | /* API: RTTI: */
|
---|
223 | UIActionPoolType type() const { return m_type; }
|
---|
224 |
|
---|
225 | /* API: Action stuff: */
|
---|
226 | UIAction* action(int iIndex) const { return m_pool[iIndex]; }
|
---|
227 |
|
---|
228 | /* API: Prepare stuff: */
|
---|
229 | void recreateMenus() { createMenus(); }
|
---|
230 |
|
---|
231 | /* API: Hot-key handling stuff: */
|
---|
232 | bool processHotKey(const QKeySequence &key);
|
---|
233 |
|
---|
234 | protected:
|
---|
235 |
|
---|
236 | /* Constructor/destructor: */
|
---|
237 | UIActionPool(UIActionPoolType type);
|
---|
238 | ~UIActionPool();
|
---|
239 |
|
---|
240 | /* Helpers: Prepare/cleanup stuff: */
|
---|
241 | void prepare();
|
---|
242 | void cleanup();
|
---|
243 |
|
---|
244 | /* Virtual helping stuff: */
|
---|
245 | virtual void createActions();
|
---|
246 | virtual void createMenus();
|
---|
247 | virtual void destroyPool();
|
---|
248 |
|
---|
249 | /* Helper: Event stuff: */
|
---|
250 | bool event(QEvent *pEvent);
|
---|
251 |
|
---|
252 | /* Instance: */
|
---|
253 | static UIActionPool *m_pInstance;
|
---|
254 | /* Action pool type: */
|
---|
255 | UIActionPoolType m_type;
|
---|
256 | /* Actions pool itself: */
|
---|
257 | QMap<int, UIAction*> m_pool;
|
---|
258 | };
|
---|
259 |
|
---|
260 | #define gActionPool UIActionPool::instance()
|
---|
261 |
|
---|
262 | #endif /* __UIActionPool_h__ */
|
---|
263 |
|
---|