1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * UIActionPool class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2010-2012 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 | /* Global includes: */
|
---|
23 | #include <QAction>
|
---|
24 | #include <QMenu>
|
---|
25 |
|
---|
26 | /* Local includes: */
|
---|
27 | #include "QIWithRetranslateUI.h"
|
---|
28 |
|
---|
29 | /* Action types: */
|
---|
30 | enum UIActionType
|
---|
31 | {
|
---|
32 | UIActionType_Simple,
|
---|
33 | UIActionType_State,
|
---|
34 | UIActionType_Toggle,
|
---|
35 | UIActionType_Menu
|
---|
36 | };
|
---|
37 |
|
---|
38 | /* Action keys: */
|
---|
39 | enum UIActionIndex
|
---|
40 | {
|
---|
41 | /* Various dialog actions: */
|
---|
42 | UIActionIndex_Simple_LogDialog,
|
---|
43 |
|
---|
44 | /* 'Help' menu actions: */
|
---|
45 | UIActionIndex_Menu_Help,
|
---|
46 | UIActionIndex_Simple_Contents,
|
---|
47 | UIActionIndex_Simple_WebSite,
|
---|
48 | UIActionIndex_Simple_ResetWarnings,
|
---|
49 | UIActionIndex_Simple_NetworkAccessManager,
|
---|
50 | UIActionIndex_Simple_CheckForUpdates,
|
---|
51 | UIActionIndex_Simple_About,
|
---|
52 |
|
---|
53 | /* Maximum index: */
|
---|
54 | UIActionIndex_Max
|
---|
55 | };
|
---|
56 |
|
---|
57 | /* Basic abstract QAction reimplemetation, extending interface: */
|
---|
58 | class UIAction : public QIWithRetranslateUI3<QAction>
|
---|
59 | {
|
---|
60 | Q_OBJECT;
|
---|
61 |
|
---|
62 | public:
|
---|
63 |
|
---|
64 | UIActionType type() const { return m_type; }
|
---|
65 | virtual void setState(int /* iState */) {}
|
---|
66 | virtual void updateAppearance() {}
|
---|
67 |
|
---|
68 | void setShortcut(const QKeySequence &shortcut);
|
---|
69 | void showShortcut();
|
---|
70 | void hideShortcut();
|
---|
71 |
|
---|
72 | protected:
|
---|
73 |
|
---|
74 | UIAction(QObject *pParent, UIActionType type);
|
---|
75 |
|
---|
76 | QString menuText(const QString &strText);
|
---|
77 |
|
---|
78 | private:
|
---|
79 |
|
---|
80 | UIActionType m_type;
|
---|
81 | QKeySequence m_shortcut;
|
---|
82 | };
|
---|
83 |
|
---|
84 | /* Basic QMenu reimplemetation, extending interface: */
|
---|
85 | class UIMenu : public QMenu
|
---|
86 | {
|
---|
87 | Q_OBJECT;
|
---|
88 |
|
---|
89 | public:
|
---|
90 |
|
---|
91 | UIMenu();
|
---|
92 |
|
---|
93 | void setShowToolTips(bool fShowToolTips) { m_fShowToolTips = fShowToolTips; }
|
---|
94 | bool isToolTipsShown() const { return m_fShowToolTips; }
|
---|
95 |
|
---|
96 | private:
|
---|
97 |
|
---|
98 | bool event(QEvent *pEvent);
|
---|
99 |
|
---|
100 | bool m_fShowToolTips;
|
---|
101 | };
|
---|
102 |
|
---|
103 | /* Abstract extention for UIAction, describing 'simple' action type: */
|
---|
104 | class UIActionSimple : public UIAction
|
---|
105 | {
|
---|
106 | Q_OBJECT;
|
---|
107 |
|
---|
108 | protected:
|
---|
109 |
|
---|
110 | UIActionSimple(QObject *pParent,
|
---|
111 | const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
112 | UIActionSimple(QObject *pParent,
|
---|
113 | const QSize &normalSize, const QSize &smallSize,
|
---|
114 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
115 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
116 | UIActionSimple(QObject *pParent, const QIcon& icon);
|
---|
117 | };
|
---|
118 |
|
---|
119 | /* Abstract extention for UIAction, describing 'state' action type: */
|
---|
120 | class UIActionState : public UIAction
|
---|
121 | {
|
---|
122 | Q_OBJECT;
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | UIActionState(QObject *pParent,
|
---|
127 | const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
128 | UIActionState(QObject *pParent,
|
---|
129 | const QSize &normalSize, const QSize &smallSize,
|
---|
130 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
131 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
132 | UIActionState(QObject *pParent, const QIcon& icon);
|
---|
133 | void setState(int iState) { m_iState = iState; retranslateUi(); }
|
---|
134 |
|
---|
135 | int m_iState;
|
---|
136 | };
|
---|
137 |
|
---|
138 | /* Abstract extention for UIAction, describing 'toggle' action type: */
|
---|
139 | class UIActionToggle : public UIAction
|
---|
140 | {
|
---|
141 | Q_OBJECT;
|
---|
142 |
|
---|
143 | protected:
|
---|
144 |
|
---|
145 | UIActionToggle(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
146 | UIActionToggle(QObject *pParent,
|
---|
147 | const QSize &normalSize, const QSize &smallSize,
|
---|
148 | const QString &strNormalIcon, const QString &strSmallIcon,
|
---|
149 | const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
|
---|
150 | UIActionToggle(QObject *pParent, const QString &strIconOn, const QString &strIconOff, const QString &strIconOnDis, const QString &strIconOffDis);
|
---|
151 | UIActionToggle(QObject *pParent, const QIcon &icon);
|
---|
152 | void updateAppearance() { sltUpdateAppearance(); }
|
---|
153 |
|
---|
154 | private slots:
|
---|
155 |
|
---|
156 | void sltUpdateAppearance();
|
---|
157 |
|
---|
158 | private:
|
---|
159 |
|
---|
160 | void init();
|
---|
161 | };
|
---|
162 |
|
---|
163 | /* Abstract extention for UIAction, describing 'menu' action type: */
|
---|
164 | class UIActionMenu : public UIAction
|
---|
165 | {
|
---|
166 | Q_OBJECT;
|
---|
167 |
|
---|
168 | protected:
|
---|
169 |
|
---|
170 | UIActionMenu(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
|
---|
171 | UIActionMenu(QObject *pParent, const QIcon &icon);
|
---|
172 | };
|
---|
173 |
|
---|
174 | /* Action pool types: */
|
---|
175 | enum UIActionPoolType
|
---|
176 | {
|
---|
177 | UIActionPoolType_Selector,
|
---|
178 | UIActionPoolType_Runtime
|
---|
179 | };
|
---|
180 |
|
---|
181 | /* Singleton action pool: */
|
---|
182 | class UIActionPool : public QObject
|
---|
183 | {
|
---|
184 | Q_OBJECT;
|
---|
185 |
|
---|
186 | public:
|
---|
187 |
|
---|
188 | /* Singleton methods: */
|
---|
189 | static UIActionPool* instance();
|
---|
190 |
|
---|
191 | /* Constructor/destructor: */
|
---|
192 | UIActionPool(UIActionPoolType type);
|
---|
193 | ~UIActionPool();
|
---|
194 |
|
---|
195 | /* Prepare/cleanup: */
|
---|
196 | void prepare();
|
---|
197 | void cleanup();
|
---|
198 |
|
---|
199 | /* Return corresponding action: */
|
---|
200 | UIAction* action(int iIndex) const { return m_pool[iIndex]; }
|
---|
201 |
|
---|
202 | /* Helping stuff: */
|
---|
203 | void recreateMenus() { createMenus(); }
|
---|
204 | bool processHotKey(const QKeySequence &key);
|
---|
205 |
|
---|
206 | /* Action pool type: */
|
---|
207 | UIActionPoolType type() const { return m_type; }
|
---|
208 |
|
---|
209 | protected:
|
---|
210 |
|
---|
211 | /* Virtual helping stuff: */
|
---|
212 | virtual void createActions();
|
---|
213 | virtual void createMenus();
|
---|
214 | virtual void destroyPool();
|
---|
215 |
|
---|
216 | /* Event handler: */
|
---|
217 | bool event(QEvent *pEvent);
|
---|
218 |
|
---|
219 | /* Instance: */
|
---|
220 | static UIActionPool *m_pInstance;
|
---|
221 |
|
---|
222 | /* Action pool type: */
|
---|
223 | UIActionPoolType m_type;
|
---|
224 |
|
---|
225 | /* Actions pool itself: */
|
---|
226 | QMap<int, UIAction*> m_pool;
|
---|
227 | };
|
---|
228 |
|
---|
229 | #define gActionPool UIActionPool::instance()
|
---|
230 |
|
---|
231 | #endif /* __UIActionPool_h__ */
|
---|
232 |
|
---|