VirtualBox

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

Last change on this file since 42533 was 42533, checked in by vboxsync, 12 years ago

FE/Qt: 6234: Support for VM groups: Group/machine menu shortcuts functionality restored.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 5.8 KB
Line 
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: */
30enum UIActionType
31{
32 UIActionType_Simple,
33 UIActionType_State,
34 UIActionType_Toggle,
35 UIActionType_Menu
36};
37
38/* Action keys: */
39enum 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: */
58class UIAction : public QIWithRetranslateUI3<QAction>
59{
60 Q_OBJECT;
61
62public:
63
64 UIActionType type() const { return m_type; }
65 virtual void setState(int /* iState */) {}
66 virtual void updateAppearance() {}
67
68 void showShortcut();
69 void hideShortcut();
70
71protected:
72
73 UIAction(QObject *pParent, UIActionType type);
74
75 QString menuText(const QString &strText);
76
77private:
78
79 UIActionType m_type;
80 QKeySequence m_shortcut;
81};
82
83/* Basic QMenu reimplemetation, extending interface: */
84class UIMenu : public QMenu
85{
86 Q_OBJECT;
87
88public:
89
90 UIMenu();
91
92 void setShowToolTips(bool fShowToolTips) { m_fShowToolTips = fShowToolTips; }
93 bool isToolTipsShown() const { return m_fShowToolTips; }
94
95private:
96
97 bool event(QEvent *pEvent);
98
99 bool m_fShowToolTips;
100};
101
102/* Abstract extention for UIAction, describing 'simple' action type: */
103class UIActionSimple : public UIAction
104{
105 Q_OBJECT;
106
107protected:
108
109 UIActionSimple(QObject *pParent,
110 const QString &strIcon = QString(), const QString &strIconDis = QString());
111 UIActionSimple(QObject *pParent,
112 const QSize &normalSize, const QSize &smallSize,
113 const QString &strNormalIcon, const QString &strSmallIcon,
114 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
115 UIActionSimple(QObject *pParent, const QIcon& icon);
116};
117
118/* Abstract extention for UIAction, describing 'state' action type: */
119class UIActionState : public UIAction
120{
121 Q_OBJECT;
122
123protected:
124
125 UIActionState(QObject *pParent,
126 const QString &strIcon = QString(), const QString &strIconDis = QString());
127 UIActionState(QObject *pParent,
128 const QSize &normalSize, const QSize &smallSize,
129 const QString &strNormalIcon, const QString &strSmallIcon,
130 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
131 UIActionState(QObject *pParent, const QIcon& icon);
132 void setState(int iState) { m_iState = iState; retranslateUi(); }
133
134 int m_iState;
135};
136
137/* Abstract extention for UIAction, describing 'toggle' action type: */
138class UIActionToggle : public UIAction
139{
140 Q_OBJECT;
141
142protected:
143
144 UIActionToggle(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
145 UIActionToggle(QObject *pParent,
146 const QSize &normalSize, const QSize &smallSize,
147 const QString &strNormalIcon, const QString &strSmallIcon,
148 const QString &strNormalIconDis = QString(), const QString &strSmallIconDis = QString());
149 UIActionToggle(QObject *pParent, const QString &strIconOn, const QString &strIconOff, const QString &strIconOnDis, const QString &strIconOffDis);
150 UIActionToggle(QObject *pParent, const QIcon &icon);
151 void updateAppearance() { sltUpdateAppearance(); }
152
153private slots:
154
155 void sltUpdateAppearance();
156
157private:
158
159 void init();
160};
161
162/* Abstract extention for UIAction, describing 'menu' action type: */
163class UIActionMenu : public UIAction
164{
165 Q_OBJECT;
166
167protected:
168
169 UIActionMenu(QObject *pParent, const QString &strIcon = QString(), const QString &strIconDis = QString());
170 UIActionMenu(QObject *pParent, const QIcon &icon);
171};
172
173/* Action pool types: */
174enum UIActionPoolType
175{
176 UIActionPoolType_Selector,
177 UIActionPoolType_Runtime
178};
179
180/* Singleton action pool: */
181class UIActionPool : public QObject
182{
183 Q_OBJECT;
184
185public:
186
187 /* Singleton methods: */
188 static UIActionPool* instance();
189
190 /* Constructor/destructor: */
191 UIActionPool(UIActionPoolType type);
192 ~UIActionPool();
193
194 /* Prepare/cleanup: */
195 void prepare();
196 void cleanup();
197
198 /* Return corresponding action: */
199 UIAction* action(int iIndex) const { return m_pool[iIndex]; }
200
201 /* Helping stuff: */
202 void recreateMenus() { createMenus(); }
203 bool processHotKey(const QKeySequence &key);
204
205 /* Action pool type: */
206 UIActionPoolType type() const { return m_type; }
207
208protected:
209
210 /* Virtual helping stuff: */
211 virtual void createActions();
212 virtual void createMenus();
213 virtual void destroyPool();
214
215 /* Event handler: */
216 bool event(QEvent *pEvent);
217
218 /* Instance: */
219 static UIActionPool *m_pInstance;
220
221 /* Action pool type: */
222 UIActionPoolType m_type;
223
224 /* Actions pool itself: */
225 QMap<int, UIAction*> m_pool;
226};
227
228#define gActionPool UIActionPool::instance()
229
230#endif /* __UIActionPool_h__ */
231
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use