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