1 | /* $Id: UIActionPool.h 82713 2020-01-10 12:39:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIActionPool class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_globals_UIActionPool_h
|
---|
19 | #define FEQT_INCLUDED_SRC_globals_UIActionPool_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QAction>
|
---|
26 | #include <QMenu>
|
---|
27 | #include <QVector>
|
---|
28 |
|
---|
29 | /* GUI includes: */
|
---|
30 | #include "QIWithRetranslateUI.h"
|
---|
31 | #include "UIExtraDataDefs.h"
|
---|
32 | #include "UILibraryDefs.h"
|
---|
33 |
|
---|
34 | /* Forward declarations: */
|
---|
35 | class QKeySequence;
|
---|
36 | class QString;
|
---|
37 | class UIActionPolymorphicMenu;
|
---|
38 | class UIActionPool;
|
---|
39 | class UIActionPoolRuntime;
|
---|
40 | class UIActionPoolManager;
|
---|
41 |
|
---|
42 |
|
---|
43 | /** Action-pool types. */
|
---|
44 | enum UIActionPoolType
|
---|
45 | {
|
---|
46 | UIActionPoolType_Manager,
|
---|
47 | UIActionPoolType_Runtime
|
---|
48 | };
|
---|
49 |
|
---|
50 | /** Action types. */
|
---|
51 | enum UIActionType
|
---|
52 | {
|
---|
53 | UIActionType_Menu,
|
---|
54 | UIActionType_Simple,
|
---|
55 | UIActionType_Toggle,
|
---|
56 | UIActionType_Polymorphic,
|
---|
57 | UIActionType_PolymorphicMenu
|
---|
58 | };
|
---|
59 |
|
---|
60 | /** Action indexes. */
|
---|
61 | enum UIActionIndex
|
---|
62 | {
|
---|
63 | /* 'Application' menu actions: */
|
---|
64 | UIActionIndex_M_Application,
|
---|
65 | #ifdef VBOX_WS_MAC
|
---|
66 | UIActionIndex_M_Application_S_About,
|
---|
67 | #endif
|
---|
68 | UIActionIndex_M_Application_S_Preferences,
|
---|
69 | #ifdef VBOX_GUI_WITH_NETWORK_MANAGER
|
---|
70 | UIActionIndex_M_Application_S_NetworkAccessManager,
|
---|
71 | UIActionIndex_M_Application_S_CheckForUpdates,
|
---|
72 | #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
|
---|
73 | UIActionIndex_M_Application_S_ResetWarnings,
|
---|
74 | UIActionIndex_M_Application_S_Close,
|
---|
75 |
|
---|
76 | #ifdef VBOX_WS_MAC
|
---|
77 | /* 'Window' menu actions: */
|
---|
78 | UIActionIndex_M_Window,
|
---|
79 | UIActionIndex_M_Window_S_Minimize,
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | /* 'Help' menu actions: */
|
---|
83 | UIActionIndex_Menu_Help,
|
---|
84 | UIActionIndex_Simple_Contents,
|
---|
85 | UIActionIndex_Simple_WebSite,
|
---|
86 | UIActionIndex_Simple_BugTracker,
|
---|
87 | UIActionIndex_Simple_Forums,
|
---|
88 | UIActionIndex_Simple_Oracle,
|
---|
89 | #ifndef VBOX_WS_MAC
|
---|
90 | UIActionIndex_Simple_About,
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | /* 'Log' menu actions: */
|
---|
94 | UIActionIndex_M_LogWindow,
|
---|
95 | UIActionIndex_M_Log,
|
---|
96 | UIActionIndex_M_Log_T_Find,
|
---|
97 | UIActionIndex_M_Log_T_Filter,
|
---|
98 | UIActionIndex_M_Log_T_Bookmark,
|
---|
99 | UIActionIndex_M_Log_T_Options,
|
---|
100 | UIActionIndex_M_Log_S_Refresh,
|
---|
101 | UIActionIndex_M_Log_S_Save,
|
---|
102 |
|
---|
103 | /* File Manager actions: */
|
---|
104 | UIActionIndex_M_FileManager,
|
---|
105 | UIActionIndex_M_FileManager_M_HostSubmenu,
|
---|
106 | UIActionIndex_M_FileManager_M_GuestSubmenu,
|
---|
107 | UIActionIndex_M_FileManager_S_CopyToGuest,
|
---|
108 | UIActionIndex_M_FileManager_S_CopyToHost,
|
---|
109 | UIActionIndex_M_FileManager_T_Options,
|
---|
110 | UIActionIndex_M_FileManager_T_Log,
|
---|
111 | UIActionIndex_M_FileManager_T_Operations,
|
---|
112 | UIActionIndex_M_FileManager_T_Session,
|
---|
113 | UIActionIndex_M_FileManager_S_Host_GoUp,
|
---|
114 | UIActionIndex_M_FileManager_S_Guest_GoUp,
|
---|
115 | UIActionIndex_M_FileManager_S_Host_GoHome,
|
---|
116 | UIActionIndex_M_FileManager_S_Guest_GoHome,
|
---|
117 | UIActionIndex_M_FileManager_S_Host_Refresh,
|
---|
118 | UIActionIndex_M_FileManager_S_Guest_Refresh,
|
---|
119 | UIActionIndex_M_FileManager_S_Host_Delete,
|
---|
120 | UIActionIndex_M_FileManager_S_Guest_Delete,
|
---|
121 | UIActionIndex_M_FileManager_S_Host_Rename,
|
---|
122 | UIActionIndex_M_FileManager_S_Guest_Rename,
|
---|
123 | UIActionIndex_M_FileManager_S_Host_CreateNewDirectory,
|
---|
124 | UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory,
|
---|
125 | UIActionIndex_M_FileManager_S_Host_Copy,
|
---|
126 | UIActionIndex_M_FileManager_S_Guest_Copy,
|
---|
127 | UIActionIndex_M_FileManager_S_Host_Cut,
|
---|
128 | UIActionIndex_M_FileManager_S_Guest_Cut,
|
---|
129 | UIActionIndex_M_FileManager_S_Host_Paste,
|
---|
130 | UIActionIndex_M_FileManager_S_Guest_Paste,
|
---|
131 | UIActionIndex_M_FileManager_S_Host_SelectAll,
|
---|
132 | UIActionIndex_M_FileManager_S_Guest_SelectAll,
|
---|
133 | UIActionIndex_M_FileManager_S_Host_InvertSelection,
|
---|
134 | UIActionIndex_M_FileManager_S_Guest_InvertSelection,
|
---|
135 | UIActionIndex_M_FileManager_S_Host_ShowProperties,
|
---|
136 | UIActionIndex_M_FileManager_S_Guest_ShowProperties,
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | /* Maximum index: */
|
---|
141 | UIActionIndex_Max
|
---|
142 | };
|
---|
143 |
|
---|
144 | /** Restriction levels. */
|
---|
145 | enum UIActionRestrictionLevel
|
---|
146 | {
|
---|
147 | UIActionRestrictionLevel_Base,
|
---|
148 | UIActionRestrictionLevel_Session,
|
---|
149 | UIActionRestrictionLevel_Logic
|
---|
150 | };
|
---|
151 |
|
---|
152 |
|
---|
153 | /** QMenu extension. */
|
---|
154 | class SHARED_LIBRARY_STUFF UIMenu : public QMenu
|
---|
155 | {
|
---|
156 | Q_OBJECT;
|
---|
157 |
|
---|
158 | public:
|
---|
159 |
|
---|
160 | /** Constructs menu. */
|
---|
161 | UIMenu();
|
---|
162 |
|
---|
163 | /** Defines whether tool-tip should be shown. */
|
---|
164 | void setShowToolTip(bool fShowToolTips) { m_fShowToolTip = fShowToolTips; }
|
---|
165 |
|
---|
166 | #ifdef VBOX_WS_MAC
|
---|
167 | /** Mac OS X: Returns whether this menu is consumable by the menu-bar. */
|
---|
168 | bool isConsumable() const { return m_fConsumable; }
|
---|
169 | /** Mac OS X: Defines whether this menu is @a fConsumable by the menu-bar. */
|
---|
170 | void setConsumable(bool fConsumable) { m_fConsumable = fConsumable; }
|
---|
171 |
|
---|
172 | /** Mac OS X: Returns whether this menu is consumed by the menu-bar. */
|
---|
173 | bool isConsumed() const { return m_fConsumed; }
|
---|
174 | /** Mac OS X: Defines whether this menu is @a fConsumed by the menu-bar. */
|
---|
175 | void setConsumed(bool fConsumed) { m_fConsumed = fConsumed; }
|
---|
176 | #endif /* VBOX_WS_MAC */
|
---|
177 |
|
---|
178 | protected:
|
---|
179 |
|
---|
180 | /** Handles any Qt @a pEvent. */
|
---|
181 | virtual bool event(QEvent *pEvent);
|
---|
182 |
|
---|
183 | private:
|
---|
184 |
|
---|
185 | /** Holds whether tool-tip should be shown. */
|
---|
186 | bool m_fShowToolTip;
|
---|
187 |
|
---|
188 | #ifdef VBOX_WS_MAC
|
---|
189 | /** Mac OS X: Holds whether this menu can be consumed by the menu-bar. */
|
---|
190 | bool m_fConsumable;
|
---|
191 | /** Mac OS X: Holds whether this menu is consumed by the menu-bar. */
|
---|
192 | bool m_fConsumed;
|
---|
193 | #endif /* VBOX_WS_MAC */
|
---|
194 | };
|
---|
195 |
|
---|
196 |
|
---|
197 | /** Abstract QAction extension. */
|
---|
198 | class SHARED_LIBRARY_STUFF UIAction : public QAction
|
---|
199 | {
|
---|
200 | Q_OBJECT;
|
---|
201 |
|
---|
202 | public:
|
---|
203 |
|
---|
204 | /** Returns action type. */
|
---|
205 | UIActionType type() const { return m_enmType; }
|
---|
206 | /** Returns whether this is machine-menu action. */
|
---|
207 | bool machineMenuAction() const { return m_fMachineMenuAction; }
|
---|
208 |
|
---|
209 | /** Returns menu contained by this action. */
|
---|
210 | UIMenu *menu() const;
|
---|
211 |
|
---|
212 | /** Returns action-pool this action belongs to. */
|
---|
213 | UIActionPool *actionPool() const { return m_pActionPool; }
|
---|
214 |
|
---|
215 | /** Casts action to polymorphic-menu-action. */
|
---|
216 | UIActionPolymorphicMenu *toActionPolymorphicMenu();
|
---|
217 |
|
---|
218 | /** Returns current action state. */
|
---|
219 | int state() const { return m_iState; }
|
---|
220 | /** Defines current action @a iState. */
|
---|
221 | void setState(int iState) { m_iState = iState; updateIcon(); retranslateUi(); }
|
---|
222 |
|
---|
223 | /** Defines @a icon for certain @a iState. */
|
---|
224 | void setIcon(int iState, const QIcon &icon);
|
---|
225 | /** Defines @a icon. */
|
---|
226 | void setIcon(const QIcon &icon);
|
---|
227 |
|
---|
228 | /** Returns current action name. */
|
---|
229 | const QString &name() const { return m_strName; }
|
---|
230 | /** Defines current action name. */
|
---|
231 | void setName(const QString &strName);
|
---|
232 |
|
---|
233 | /** Returns action shortcut scope. */
|
---|
234 | const QString &shortcutScope() const { return m_strShortcutScope; }
|
---|
235 | /** Defines action @a strShortcutScope. */
|
---|
236 | void setShortcutScope(const QString &strShortcutScope) { m_strShortcutScope = strShortcutScope; }
|
---|
237 |
|
---|
238 | /** Returns action extra-data ID. */
|
---|
239 | virtual int extraDataID() const { return 0; }
|
---|
240 | /** Returns action extra-data key. */
|
---|
241 | virtual QString extraDataKey() const { return QString(); }
|
---|
242 | /** Returns whether action is allowed. */
|
---|
243 | virtual bool isAllowed() const { return true; }
|
---|
244 |
|
---|
245 | /** Returns extra-data ID to save keyboard shortcut under. */
|
---|
246 | virtual QString shortcutExtraDataID() const { return QString(); }
|
---|
247 | /** Returns default keyboard shortcut for this action. */
|
---|
248 | virtual QKeySequence defaultShortcut(UIActionPoolType) const { return QKeySequence(); }
|
---|
249 | /** Returns standard keyboard shortcut for this action. */
|
---|
250 | virtual QKeySequence standardShortcut(UIActionPoolType) const { return QKeySequence(); }
|
---|
251 |
|
---|
252 | /** Defines current keyboard shortcuts for this action. */
|
---|
253 | void setShortcuts(const QList<QKeySequence> &shortcuts);
|
---|
254 | /** Make action show keyboard shortcut. */
|
---|
255 | void showShortcut();
|
---|
256 | /** Make action hide keyboard shortcut. */
|
---|
257 | void hideShortcut();
|
---|
258 |
|
---|
259 | /** Retranslates action. */
|
---|
260 | virtual void retranslateUi() = 0;
|
---|
261 | /** Destructs action. */
|
---|
262 | virtual ~UIAction() /* override */ { delete menu(); }
|
---|
263 |
|
---|
264 | protected:
|
---|
265 |
|
---|
266 | /** Constructs action passing @a pParent to the base-class.
|
---|
267 | * @param enmType Brings the action type. */
|
---|
268 | UIAction(UIActionPool *pParent, UIActionType enmType, bool fMachineMenuAction = false);
|
---|
269 |
|
---|
270 | /** Returns current action name in menu. */
|
---|
271 | QString nameInMenu() const;
|
---|
272 |
|
---|
273 | /** Updates action icon. */
|
---|
274 | virtual void updateIcon();
|
---|
275 |
|
---|
276 | /** Updates action text accordingly. */
|
---|
277 | virtual void updateText();
|
---|
278 |
|
---|
279 | /** Simplifies passed @a strText by removing dots and ampersands.
|
---|
280 | * @note Used to simplify action names for tool-tip needs. */
|
---|
281 | static QString simplifyText(QString strText);
|
---|
282 |
|
---|
283 | private:
|
---|
284 |
|
---|
285 | /** Holds the action type. */
|
---|
286 | UIActionType m_enmType;
|
---|
287 | /** Holds whether this is machine-menu action. */
|
---|
288 | bool m_fMachineMenuAction;
|
---|
289 |
|
---|
290 | /** Holds the reference to the action-pool this action belongs to. */
|
---|
291 | UIActionPool *m_pActionPool;
|
---|
292 | /** Holds the type of the action-pool this action belongs to. */
|
---|
293 | UIActionPoolType m_enmActionPoolType;
|
---|
294 |
|
---|
295 | /** Holds current action state. */
|
---|
296 | int m_iState;
|
---|
297 | /** Holds action icons. */
|
---|
298 | QVector<QIcon> m_icons;
|
---|
299 | /** Holds the action name. */
|
---|
300 | QString m_strName;
|
---|
301 | /** Holds the action shortcut scope. */
|
---|
302 | QString m_strShortcutScope;
|
---|
303 | /** Holds the action shortcuts. */
|
---|
304 | QList<QKeySequence> m_shortcuts;
|
---|
305 | /** Holds whether action shortcut hidden. */
|
---|
306 | bool m_fShortcutHidden;
|
---|
307 | };
|
---|
308 |
|
---|
309 |
|
---|
310 | /** Abstract UIAction extension for 'Menu' action type. */
|
---|
311 | class SHARED_LIBRARY_STUFF UIActionMenu : public UIAction
|
---|
312 | {
|
---|
313 | Q_OBJECT;
|
---|
314 |
|
---|
315 | protected:
|
---|
316 |
|
---|
317 | /** Constructs menu action passing @a pParent to the base-class.
|
---|
318 | * @param strIcon Brings the normal-icon name.
|
---|
319 | * @param strIconDisabled Brings the disabled-icon name. */
|
---|
320 | UIActionMenu(UIActionPool *pParent,
|
---|
321 | const QString &strIcon = QString(),
|
---|
322 | const QString &strIconDisabled = QString());
|
---|
323 | /** Constructs menu action passing @a pParent to the base-class.
|
---|
324 | * @param icon Brings the icon. */
|
---|
325 | UIActionMenu(UIActionPool *pParent,
|
---|
326 | const QIcon &icon);
|
---|
327 |
|
---|
328 | /** Defines whether tool-tip should be shown. */
|
---|
329 | void setShowToolTip(bool fShowToolTip);
|
---|
330 |
|
---|
331 | private:
|
---|
332 |
|
---|
333 | /** Prepare routine. */
|
---|
334 | void prepare();
|
---|
335 |
|
---|
336 | /** Updates action text accordingly. */
|
---|
337 | virtual void updateText();
|
---|
338 | };
|
---|
339 |
|
---|
340 |
|
---|
341 | /** Abstract UIAction extension for 'Simple' action type. */
|
---|
342 | class SHARED_LIBRARY_STUFF UIActionSimple : public UIAction
|
---|
343 | {
|
---|
344 | Q_OBJECT;
|
---|
345 |
|
---|
346 | protected:
|
---|
347 |
|
---|
348 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
349 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
350 | UIActionSimple(UIActionPool *pParent,
|
---|
351 | bool fMachineMenuAction = false);
|
---|
352 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
353 | * @param strIcon Brings the normal-icon name.
|
---|
354 | * @param strIconDisabled Brings the disabled-icon name.
|
---|
355 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
356 | UIActionSimple(UIActionPool *pParent,
|
---|
357 | const QString &strIcon, const QString &strIconDisabled,
|
---|
358 | bool fMachineMenuAction = false);
|
---|
359 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
360 | * @param strIconNormal Brings the normal-icon name.
|
---|
361 | * @param strIconSmall Brings the small-icon name.
|
---|
362 | * @param strIconNormalDisabled Brings the normal-disabled-icon name.
|
---|
363 | * @param strIconSmallDisabled Brings the small-disabled-icon name.
|
---|
364 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
365 | UIActionSimple(UIActionPool *pParent,
|
---|
366 | const QString &strIconNormal, const QString &strIconSmall,
|
---|
367 | const QString &strIconNormalDisabled, const QString &strIconSmallDisabled,
|
---|
368 | bool fMachineMenuAction = false);
|
---|
369 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
370 | * @param icon Brings the icon.
|
---|
371 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
372 | UIActionSimple(UIActionPool *pParent,
|
---|
373 | const QIcon &icon,
|
---|
374 | bool fMachineMenuAction = false);
|
---|
375 | };
|
---|
376 |
|
---|
377 |
|
---|
378 | /** Abstract UIAction extension for 'Toggle' action type. */
|
---|
379 | class SHARED_LIBRARY_STUFF UIActionToggle : public UIAction
|
---|
380 | {
|
---|
381 | Q_OBJECT;
|
---|
382 |
|
---|
383 | protected:
|
---|
384 |
|
---|
385 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
386 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
387 | UIActionToggle(UIActionPool *pParent,
|
---|
388 | bool fMachineMenuAction = false);
|
---|
389 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
390 | * @param strIcon Brings the normal-icon name.
|
---|
391 | * @param strIconDisabled Brings the disabled-icon name.
|
---|
392 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
393 | UIActionToggle(UIActionPool *pParent,
|
---|
394 | const QString &strIcon, const QString &strIconDisabled,
|
---|
395 | bool fMachineMenuAction = false);
|
---|
396 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
397 | * @param strIconOn Brings the on-icon name.
|
---|
398 | * @param strIconOff Brings the off-icon name.
|
---|
399 | * @param strIconOnDisabled Brings the on-disabled-icon name.
|
---|
400 | * @param strIconOffDisabled Brings the off-disabled-icon name.
|
---|
401 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
402 | UIActionToggle(UIActionPool *pParent,
|
---|
403 | const QString &strIconOn, const QString &strIconOff,
|
---|
404 | const QString &strIconOnDisabled, const QString &strIconOffDisabled,
|
---|
405 | bool fMachineMenuAction = false);
|
---|
406 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
407 | * @param icon Brings the icon.
|
---|
408 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
409 | UIActionToggle(UIActionPool *pParent,
|
---|
410 | const QIcon &icon,
|
---|
411 | bool fMachineMenuAction = false);
|
---|
412 |
|
---|
413 | private:
|
---|
414 |
|
---|
415 | /** Prepare routine. */
|
---|
416 | void prepare();
|
---|
417 | };
|
---|
418 |
|
---|
419 |
|
---|
420 | /** Abstract UIAction extension for 'Polymorphic Menu' action type. */
|
---|
421 | class SHARED_LIBRARY_STUFF UIActionPolymorphicMenu : public UIAction
|
---|
422 | {
|
---|
423 | Q_OBJECT;
|
---|
424 |
|
---|
425 | public:
|
---|
426 |
|
---|
427 | /** Returns current action state. */
|
---|
428 | int state() const { return m_iState; }
|
---|
429 | /** Defines current action state. */
|
---|
430 | void setState(int iState) { m_iState = iState; retranslateUi(); }
|
---|
431 |
|
---|
432 | protected:
|
---|
433 |
|
---|
434 | /** Constructs polymorphic menu action passing @a pParent to the base-class.
|
---|
435 | * @param strIcon Brings the normal-icon name.
|
---|
436 | * @param strIconDisabled Brings the disabled-icon name. */
|
---|
437 | UIActionPolymorphicMenu(UIActionPool *pParent,
|
---|
438 | const QString &strIcon = QString(), const QString &strIconDisabled = QString());
|
---|
439 | /** Constructs polymorphic menu action passing @a pParent to the base-class.
|
---|
440 | * @param strIconNormal Brings the normal-icon name.
|
---|
441 | * @param strIconSmall Brings the small-icon name.
|
---|
442 | * @param strIconNormalDisabled Brings the normal-disabled-icon name.
|
---|
443 | * @param strIconSmallDisabled Brings the small-disabled-icon name. */
|
---|
444 | UIActionPolymorphicMenu(UIActionPool *pParent,
|
---|
445 | const QString &strIconNormal, const QString &strIconSmall,
|
---|
446 | const QString &strIconNormalDisabled, const QString &strIconSmallDisabled);
|
---|
447 | /** Constructs polymorphic menu action passing @a pParent to the base-class.
|
---|
448 | * @param icon Brings the icon. */
|
---|
449 | UIActionPolymorphicMenu(UIActionPool *pParent,
|
---|
450 | const QIcon &icon);
|
---|
451 |
|
---|
452 | /** Destructs polymorphic menu action. */
|
---|
453 | ~UIActionPolymorphicMenu();
|
---|
454 |
|
---|
455 | /** Defines whether tool-tip should be shown. */
|
---|
456 | void setShowToolTip(bool fShowToolTip);
|
---|
457 |
|
---|
458 | /** Show menu. */
|
---|
459 | void showMenu();
|
---|
460 | /** Hide menu. */
|
---|
461 | void hideMenu();
|
---|
462 |
|
---|
463 | private:
|
---|
464 |
|
---|
465 | /** Prepare routine. */
|
---|
466 | void prepare();
|
---|
467 |
|
---|
468 | /** Updates action text accordingly. */
|
---|
469 | virtual void updateText();
|
---|
470 |
|
---|
471 | private:
|
---|
472 |
|
---|
473 | /** Holds the menu instance. */
|
---|
474 | UIMenu *m_pMenu;
|
---|
475 | /** Holds current action state. */
|
---|
476 | int m_iState;
|
---|
477 | };
|
---|
478 |
|
---|
479 |
|
---|
480 | /** Abstract QObject extension
|
---|
481 | * representing action-pool interface and factory. */
|
---|
482 | class SHARED_LIBRARY_STUFF UIActionPool : public QIWithRetranslateUI3<QObject>
|
---|
483 | {
|
---|
484 | Q_OBJECT;
|
---|
485 |
|
---|
486 | /** Pointer to menu update-handler for this class. */
|
---|
487 | typedef void (UIActionPool::*PTFActionPool)();
|
---|
488 | /** Pointer to menu update-handler for Manager sub-class. */
|
---|
489 | typedef void (UIActionPoolManager::*PTFActionPoolManager)();
|
---|
490 | /** Pointer to menu update-handler for Runtime sub-class. */
|
---|
491 | typedef void (UIActionPoolRuntime::*PTFActionPoolRuntime)();
|
---|
492 | /** Union for two defines above. */
|
---|
493 | union PointerToFunction
|
---|
494 | {
|
---|
495 | PTFActionPool ptf;
|
---|
496 | PTFActionPoolManager ptfm;
|
---|
497 | PTFActionPoolRuntime ptfr;
|
---|
498 | };
|
---|
499 |
|
---|
500 | signals:
|
---|
501 |
|
---|
502 | /** Notifies about menu prepare. */
|
---|
503 | void sigNotifyAboutMenuPrepare(int iIndex, QMenu *pMenu);
|
---|
504 |
|
---|
505 | #ifdef VBOX_WS_MAC
|
---|
506 | /** Notifies about @a pAction hovered. */
|
---|
507 | void sigActionHovered(UIAction *pAction);
|
---|
508 | #endif
|
---|
509 |
|
---|
510 | public:
|
---|
511 |
|
---|
512 | /** Creates singleton instance. */
|
---|
513 | static UIActionPool *create(UIActionPoolType enmType);
|
---|
514 | /** Destroys singleton instance. */
|
---|
515 | static void destroy(UIActionPool *pActionPool);
|
---|
516 |
|
---|
517 | /** Creates temporary singleton instance,
|
---|
518 | * used to initialize shortcuts-pool from action-pool of passed @a enmType. */
|
---|
519 | static void createTemporary(UIActionPoolType enmType);
|
---|
520 |
|
---|
521 | /** Cast action-pool to Runtime one. */
|
---|
522 | UIActionPoolRuntime *toRuntime();
|
---|
523 | /** Cast action-pool to Manager one. */
|
---|
524 | UIActionPoolManager *toManager();
|
---|
525 |
|
---|
526 | /** Returns action-pool type. */
|
---|
527 | UIActionPoolType type() const { return m_enmType; }
|
---|
528 |
|
---|
529 | /** Returns the action for the passed @a iIndex. */
|
---|
530 | UIAction *action(int iIndex) const { return m_pool.value(iIndex); }
|
---|
531 | /** Returns all the actions action-pool contains. */
|
---|
532 | QList<UIAction*> actions() const { return m_pool.values(); }
|
---|
533 |
|
---|
534 | /** Returns the action group for the passed @a iIndex.
|
---|
535 | * @note Only menu actions can have action groups. */
|
---|
536 | QActionGroup *actionGroup(int iIndex) const;
|
---|
537 |
|
---|
538 | /** Returns the list of main menus. */
|
---|
539 | QList<QMenu*> menus() const { return m_mainMenus; }
|
---|
540 |
|
---|
541 | /** Returns whether the menu with passed @a type is allowed in menu-bar. */
|
---|
542 | bool isAllowedInMenuBar(UIExtraDataMetaDefs::MenuType type) const;
|
---|
543 | /** Defines menu-bar @a enmRestriction for passed @a level. */
|
---|
544 | void setRestrictionForMenuBar(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuType enmRestriction);
|
---|
545 |
|
---|
546 | /** Returns whether the action with passed @a type is allowed in the 'Application' menu. */
|
---|
547 | bool isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType type) const;
|
---|
548 | /** Defines 'Application' menu @a enmRestriction for passed @a level. */
|
---|
549 | void setRestrictionForMenuApplication(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuApplicationActionType enmRestriction);
|
---|
550 |
|
---|
551 | #ifdef VBOX_WS_MAC
|
---|
552 | /** Mac OS X: Returns whether the action with passed @a type is allowed in the 'Window' menu. */
|
---|
553 | bool isAllowedInMenuWindow(UIExtraDataMetaDefs::MenuWindowActionType type) const;
|
---|
554 | /** Mac OS X: Defines 'Window' menu @a enmRestriction for passed @a level. */
|
---|
555 | void setRestrictionForMenuWindow(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuWindowActionType enmRestriction);
|
---|
556 | #endif /* VBOX_WS_MAC */
|
---|
557 |
|
---|
558 | /** Returns whether the action with passed @a type is allowed in the 'Help' menu. */
|
---|
559 | bool isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType enmType) const;
|
---|
560 | /** Defines 'Help' menu @a enmRestriction for passed @a level. */
|
---|
561 | void setRestrictionForMenuHelp(UIActionRestrictionLevel enmLevel, UIExtraDataMetaDefs::MenuHelpActionType enmRestriction);
|
---|
562 |
|
---|
563 | /** Hot-key processing delegate. */
|
---|
564 | bool processHotKey(const QKeySequence &key);
|
---|
565 |
|
---|
566 | /** Defines whether shortcuts of menu actions with specified @a iIndex should be visible. */
|
---|
567 | virtual void setShortcutsVisible(int iIndex, bool fVisible) { Q_UNUSED(iIndex); Q_UNUSED(fVisible); }
|
---|
568 |
|
---|
569 | /** Returns extra-data ID to save keyboard shortcuts under. */
|
---|
570 | virtual QString shortcutsExtraDataID() const = 0;
|
---|
571 |
|
---|
572 | public slots:
|
---|
573 |
|
---|
574 | /** Handles menu prepare. */
|
---|
575 | void sltHandleMenuPrepare();
|
---|
576 |
|
---|
577 | #ifdef VBOX_WS_MAC
|
---|
578 | /** Handles action hovered signal. */
|
---|
579 | void sltActionHovered();
|
---|
580 | #endif
|
---|
581 |
|
---|
582 | protected slots:
|
---|
583 |
|
---|
584 | /** Loads keyboard shortcuts of action-pool into shortcuts-pool. */
|
---|
585 | void sltApplyShortcuts() { updateShortcuts(); }
|
---|
586 |
|
---|
587 | protected:
|
---|
588 |
|
---|
589 | /** Constructs probably @a fTemporary action-pool of passed @a enmType. */
|
---|
590 | UIActionPool(UIActionPoolType enmType, bool fTemporary = false);
|
---|
591 |
|
---|
592 | /** Prepares all. */
|
---|
593 | void prepare();
|
---|
594 | /** Prepares pool. */
|
---|
595 | virtual void preparePool();
|
---|
596 | /** Prepares connections. */
|
---|
597 | virtual void prepareConnections();
|
---|
598 | /** Cleanups connections. */
|
---|
599 | virtual void cleanupConnections() {}
|
---|
600 | /** Cleanups pool. */
|
---|
601 | virtual void cleanupPool();
|
---|
602 | /** Cleanups all. */
|
---|
603 | void cleanup();
|
---|
604 |
|
---|
605 | /** Updates configuration. */
|
---|
606 | virtual void updateConfiguration();
|
---|
607 |
|
---|
608 | /** Updates menu with certain @a iIndex. */
|
---|
609 | virtual void updateMenu(int iIndex);
|
---|
610 | /** Updates menus. */
|
---|
611 | virtual void updateMenus() = 0;
|
---|
612 | /** Updates 'Application' menu. */
|
---|
613 | virtual void updateMenuApplication();
|
---|
614 | #ifdef VBOX_WS_MAC
|
---|
615 | /** Mac OS X: Updates 'Window' menu. */
|
---|
616 | virtual void updateMenuWindow();
|
---|
617 | #endif
|
---|
618 | /** Updates 'Help' menu. */
|
---|
619 | virtual void updateMenuHelp();
|
---|
620 | /** Updates 'Log Viewer Window' menu. */
|
---|
621 | virtual void updateMenuLogViewerWindow();
|
---|
622 | /** Updates 'Log Viewer' menu. */
|
---|
623 | virtual void updateMenuLogViewer();
|
---|
624 | /** Updates 'Log Viewer' @a pMenu. */
|
---|
625 | virtual void updateMenuLogViewerWrapper(UIMenu *pMenu);
|
---|
626 |
|
---|
627 | /** Updates 'File Manager' menu. */
|
---|
628 | virtual void updateMenuFileManager();
|
---|
629 | /** Updates 'File Manager' @a pMenu. */
|
---|
630 | virtual void updateMenuFileManagerWrapper(UIMenu *pMenu);
|
---|
631 |
|
---|
632 | /** Updates shortcuts. */
|
---|
633 | virtual void updateShortcuts();
|
---|
634 |
|
---|
635 | /** Handles translation event. */
|
---|
636 | virtual void retranslateUi() /* override */;
|
---|
637 |
|
---|
638 | /** Handles any Qt @a pEvent */
|
---|
639 | virtual bool event(QEvent *pEvent) /* override */;
|
---|
640 |
|
---|
641 | /** Adds action into corresponding menu. */
|
---|
642 | bool addAction(UIMenu *pMenu, UIAction *pAction, bool fReallyAdd = true);
|
---|
643 | /** Adds action's menu into corresponding menu list. */
|
---|
644 | bool addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd = true);
|
---|
645 |
|
---|
646 | /** Holds the action-pool type. */
|
---|
647 | const UIActionPoolType m_enmType;
|
---|
648 | /** Holds whether this action-pool is temporary. */
|
---|
649 | const bool m_fTemporary;
|
---|
650 |
|
---|
651 | /** Holds the map of actions. */
|
---|
652 | QMap<int, UIAction*> m_pool;
|
---|
653 | /** Holds the map of action groups.
|
---|
654 | * @note Only menu actions can have action groups. */
|
---|
655 | QMap<int, QActionGroup*> m_groupPool;
|
---|
656 | /** Holds the map of validation handlers. */
|
---|
657 | QMap<int, PointerToFunction> m_menuUpdateHandlers;
|
---|
658 | /** Holds the set of invalidated action indexes. */
|
---|
659 | QSet<int> m_invalidations;
|
---|
660 |
|
---|
661 | /** Holds the list of main menus. */
|
---|
662 | QList<QMenu*> m_mainMenus;
|
---|
663 |
|
---|
664 | /** Holds restricted menu types. */
|
---|
665 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuType> m_restrictedMenus;
|
---|
666 | /** Holds restricted action types of the 'Application' menu. */
|
---|
667 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuApplicationActionType> m_restrictedActionsMenuApplication;
|
---|
668 | #ifdef VBOX_WS_MAC
|
---|
669 | /** Mac OS X: Holds restricted action types of the 'Window' menu. */
|
---|
670 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuWindowActionType> m_restrictedActionsMenuWindow;
|
---|
671 | #endif
|
---|
672 | /** Holds restricted action types of the Help menu. */
|
---|
673 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuHelpActionType> m_restrictedActionsMenuHelp;
|
---|
674 | };
|
---|
675 |
|
---|
676 |
|
---|
677 | #endif /* !FEQT_INCLUDED_SRC_globals_UIActionPool_h */
|
---|