VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h@ 44453

Last change on this file since 44453 was 44448, checked in by vboxsync, 11 years ago

FE/Qt: 6065: Global/machine keyboard shortcut processing: Make sure shortcuts will be updated at runtime.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 7.5 KB
Line 
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: */
30class UIActionState;
31class UIActionPool;
32
33/* Action pool types: */
34enum UIActionPoolType
35{
36 UIActionPoolType_Selector,
37 UIActionPoolType_Runtime
38};
39
40/* Action types: */
41enum UIActionType
42{
43 UIActionType_Simple,
44 UIActionType_State,
45 UIActionType_Toggle,
46 UIActionType_Menu
47};
48
49/* Action keys: */
50enum UIActionIndex
51{
52 /* Various dialog actions: */
53 UIActionIndex_Simple_LogDialog,
54
55 /* 'Help' menu actions: */
56 UIActionIndex_Menu_Help,
57 UIActionIndex_Simple_Contents,
58 UIActionIndex_Simple_WebSite,
59 UIActionIndex_Simple_ResetWarnings,
60 UIActionIndex_Simple_NetworkAccessManager,
61 UIActionIndex_Simple_CheckForUpdates,
62 UIActionIndex_Simple_About,
63
64 /* Maximum index: */
65 UIActionIndex_Max
66};
67
68/* Basic abstract QAction reimplemetation, extending interface: */
69class UIAction : public QIWithRetranslateUI3<QAction>
70{
71 Q_OBJECT;
72
73public:
74
75 /* API: RTTI: */
76 UIActionType type() const { return m_type; }
77
78 /* API: Parent stuff: */
79 UIActionPool* actionPool() const { return m_pActionPool; }
80
81 /* API: Update stuff: */
82 virtual void update() {}
83
84 /* API: Cast stuff: */
85 UIActionState* toStateAction();
86
87 /* API: Name stuff: */
88 const QString& name() const { return m_strName; }
89 void setName(const QString &strName);
90
91 /* API: Shortcut stuff: */
92 virtual QString shortcutExtraDataID() const { return QString(); }
93 virtual QKeySequence defaultShortcut(UIActionPoolType) const { return QKeySequence(); }
94 void setShortcut(const QKeySequence &shortcut);
95 void showShortcut();
96 void hideShortcut();
97
98protected:
99
100 /* Constructor: */
101 UIAction(UIActionPool *pParent, UIActionType type);
102
103 /* Protected API: Menu stuff: */
104 QString nameInMenu() const;
105
106private:
107
108 /* Helper: Text stuff: */
109 void updateText();
110
111 /* Variables: */
112 UIActionPool *m_pActionPool;
113 UIActionType m_type;
114 UIActionPoolType m_actionPoolType;
115 QString m_strName;
116 QKeySequence m_shortcut;
117};
118
119/* Basic QMenu reimplemetation, extending interface: */
120class UIMenu : public QMenu
121{
122 Q_OBJECT;
123
124public:
125
126 /* Constructor: */
127 UIMenu();
128
129 /* API: Tool-tip stuff: */
130 void setShowToolTips(bool fShowToolTips) { m_fShowToolTips = fShowToolTips; }
131 bool isToolTipsShown() const { return m_fShowToolTips; }
132
133private:
134
135 /* Helper: Event stuff: */
136 bool event(QEvent *pEvent);
137
138 /* Variables: */
139 bool m_fShowToolTips;
140};
141
142/* Abstract extention for UIAction, describing 'simple' action type: */
143class UIActionSimple : public UIAction
144{
145 Q_OBJECT;
146
147protected:
148
149 /* Constructors: */
150 UIActionSimple(UIActionPool *pParent,
151 const QString &strIcon = QString(), const QString &strIconDis = QString());
152 UIActionSimple(UIActionPool *pParent,
153 const QSize &normalSize, const QSize &smallSize,
154 const QString &strNormalIcon, const QString &strSmallIcon,
155 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
156 UIActionSimple(UIActionPool *pParent,
157 const QIcon& icon);
158};
159
160/* Abstract extention for UIAction, describing 'state' action type: */
161class UIActionState : public UIAction
162{
163 Q_OBJECT;
164
165public:
166
167 /* API: State stuff: */
168 void setState(int iState) { m_iState = iState; retranslateUi(); }
169
170protected:
171
172 /* Constructors: */
173 UIActionState(UIActionPool *pParent,
174 const QString &strIcon = QString(), const QString &strIconDis = QString());
175 UIActionState(UIActionPool *pParent,
176 const QSize &normalSize, const QSize &smallSize,
177 const QString &strNormalIcon, const QString &strSmallIcon,
178 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
179 UIActionState(UIActionPool *pParent,
180 const QIcon& icon);
181
182 /* Variables: */
183 int m_iState;
184};
185
186/* Abstract extention for UIAction, describing 'toggle' action type: */
187class UIActionToggle : public UIAction
188{
189 Q_OBJECT;
190
191protected:
192
193 /* Constructors: */
194 UIActionToggle(UIActionPool *pParent,
195 const QString &strIcon = QString(), const QString &strIconDis = QString());
196 UIActionToggle(UIActionPool *pParent,
197 const QSize &normalSize, const QSize &smallSize,
198 const QString &strNormalIcon, const QString &strSmallIcon,
199 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
200 UIActionToggle(UIActionPool *pParent,
201 const QString &strIconOn, const QString &strIconOff, const QString &strIconOnDis, const QString &strIconOffDis);
202 UIActionToggle(UIActionPool *pParent,
203 const QIcon &icon);
204
205 /* API reimplementation: Update stuff: */
206 void update() { sltUpdate(); }
207
208private slots:
209
210 /* Handler: Update stuff: */
211 void sltUpdate();
212
213private:
214
215 /* Helper: Prepare stuff: */
216 void init();
217};
218
219/* Abstract extention for UIAction, describing 'menu' action type: */
220class UIActionMenu : public UIAction
221{
222 Q_OBJECT;
223
224protected:
225
226 /* Constructors: */
227 UIActionMenu(UIActionPool *pParent,
228 const QString &strIcon = QString(), const QString &strIconDis = QString());
229 UIActionMenu(UIActionPool *pParent,
230 const QIcon &icon);
231};
232
233/* Singleton action pool: */
234class UIActionPool : public QObject
235{
236 Q_OBJECT;
237
238public:
239
240 /* API: Singleton stuff: */
241 static UIActionPool* instance();
242 static void create(UIActionPoolType type);
243 static void destroy();
244
245 /* API: RTTI: */
246 UIActionPoolType type() const { return m_type; }
247
248 /* API: Action stuff: */
249 UIAction* action(int iIndex) const { return m_pool[iIndex]; }
250 QList<UIAction*> actions() const { return m_pool.values(); }
251
252 /* API: Shortcuts stuff: */
253 virtual QString shortcutsExtraDataID() const = 0;
254
255 /* API: Prepare stuff: */
256 void recreateMenus() { createMenus(); }
257
258 /* API: Hot-key handling stuff: */
259 bool processHotKey(const QKeySequence &key);
260
261protected slots:
262
263 /* Handler: Shortcuts stuff: */
264 void sltApplyShortcuts();
265
266protected:
267
268 /* Constructor/destructor: */
269 UIActionPool(UIActionPoolType type);
270 ~UIActionPool();
271
272 /* Helpers: Prepare/cleanup stuff: */
273 void prepare();
274 void cleanup();
275
276 /* Virtual helpers: Prepare/cleanup stuff: */
277 virtual void createActions();
278 virtual void createMenus();
279 virtual void destroyPool();
280
281 /* Helper: Event stuff: */
282 bool event(QEvent *pEvent);
283
284 /* Instance: */
285 static UIActionPool *m_pInstance;
286 /* Action pool type: */
287 UIActionPoolType m_type;
288 /* Actions pool itself: */
289 QMap<int, UIAction*> m_pool;
290};
291
292#define gActionPool UIActionPool::instance()
293
294#endif /* __UIActionPool_h__ */
295
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use