1 | /* $Id: UIActionPool.h 100323 2023-06-28 12:23:10Z 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_Options,
|
---|
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_Options,
|
---|
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_CreateNewDirectory,
|
---|
161 | UIActionIndex_M_VISOCreator_Rename,
|
---|
162 | UIActionIndex_M_VISOCreator_Reset,
|
---|
163 | UIActionIndex_M_VISOCreator_Open,
|
---|
164 | UIActionIndex_M_VISOCreator_ImportISO,
|
---|
165 | UIActionIndex_M_VISOCreator_VisoContent_GoHome,
|
---|
166 | UIActionIndex_M_VISOCreator_VisoContent_GoUp,
|
---|
167 | UIActionIndex_M_VISOCreator_VisoContent_GoForward,
|
---|
168 | UIActionIndex_M_VISOCreator_VisoContent_GoBackward,
|
---|
169 | UIActionIndex_M_VISOCreator_Host_GoHome,
|
---|
170 | UIActionIndex_M_VISOCreator_Host_GoUp,
|
---|
171 | UIActionIndex_M_VISOCreator_Host_GoForward,
|
---|
172 | UIActionIndex_M_VISOCreator_Host_GoBackward,
|
---|
173 |
|
---|
174 | /* Medium selector actions : */
|
---|
175 | UIActionIndex_M_MediumSelector,
|
---|
176 | UIActionIndex_M_MediumSelector_AddHD,
|
---|
177 | UIActionIndex_M_MediumSelector_AddFD,
|
---|
178 | UIActionIndex_M_MediumSelector_AddCD,
|
---|
179 | UIActionIndex_M_MediumSelector_CreateHD,
|
---|
180 | UIActionIndex_M_MediumSelector_CreateCD,
|
---|
181 | UIActionIndex_M_MediumSelector_CreateFD,
|
---|
182 | UIActionIndex_M_MediumSelector_Refresh,
|
---|
183 |
|
---|
184 | /* Maximum index: */
|
---|
185 | UIActionIndex_Max
|
---|
186 | };
|
---|
187 |
|
---|
188 | /** Action restriction levels. */
|
---|
189 | enum UIActionRestrictionLevel
|
---|
190 | {
|
---|
191 | UIActionRestrictionLevel_Base,
|
---|
192 | UIActionRestrictionLevel_Session,
|
---|
193 | UIActionRestrictionLevel_Logic
|
---|
194 | };
|
---|
195 |
|
---|
196 |
|
---|
197 | /** QMenu extension. */
|
---|
198 | class SHARED_LIBRARY_STUFF UIMenu : public QMenu
|
---|
199 | {
|
---|
200 | Q_OBJECT;
|
---|
201 |
|
---|
202 | public:
|
---|
203 |
|
---|
204 | /** Constructs menu. */
|
---|
205 | UIMenu();
|
---|
206 |
|
---|
207 | /** Defines whether tool-tip should be shown. */
|
---|
208 | void setShowToolTip(bool fShowToolTips) { m_fShowToolTip = fShowToolTips; }
|
---|
209 |
|
---|
210 | #ifdef VBOX_WS_MAC
|
---|
211 | /** Mac OS X: Returns whether this menu is consumable by the menu-bar. */
|
---|
212 | bool isConsumable() const { return m_fConsumable; }
|
---|
213 | /** Mac OS X: Defines whether this menu is @a fConsumable by the menu-bar. */
|
---|
214 | void setConsumable(bool fConsumable) { m_fConsumable = fConsumable; }
|
---|
215 |
|
---|
216 | /** Mac OS X: Returns whether this menu is consumed by the menu-bar. */
|
---|
217 | bool isConsumed() const { return m_fConsumed; }
|
---|
218 | /** Mac OS X: Defines whether this menu is @a fConsumed by the menu-bar. */
|
---|
219 | void setConsumed(bool fConsumed) { m_fConsumed = fConsumed; }
|
---|
220 | #endif /* VBOX_WS_MAC */
|
---|
221 |
|
---|
222 | protected:
|
---|
223 |
|
---|
224 | /** Handles any Qt @a pEvent. */
|
---|
225 | virtual bool event(QEvent *pEvent);
|
---|
226 |
|
---|
227 | private:
|
---|
228 |
|
---|
229 | /** Holds whether tool-tip should be shown. */
|
---|
230 | bool m_fShowToolTip;
|
---|
231 |
|
---|
232 | #ifdef VBOX_WS_MAC
|
---|
233 | /** Mac OS X: Holds whether this menu can be consumed by the menu-bar. */
|
---|
234 | bool m_fConsumable;
|
---|
235 | /** Mac OS X: Holds whether this menu is consumed by the menu-bar. */
|
---|
236 | bool m_fConsumed;
|
---|
237 | #endif /* VBOX_WS_MAC */
|
---|
238 | };
|
---|
239 |
|
---|
240 |
|
---|
241 | /** Abstract QAction extension. */
|
---|
242 | class SHARED_LIBRARY_STUFF UIAction : public QAction
|
---|
243 | {
|
---|
244 | Q_OBJECT;
|
---|
245 |
|
---|
246 | public:
|
---|
247 |
|
---|
248 | /** Constructs action passing @a pParent to the base-class.
|
---|
249 | * @param enmType Brings the action type. */
|
---|
250 | UIAction(UIActionPool *pParent, UIActionType enmType, bool fMachineMenuAction = false);
|
---|
251 | /** Destructs action. */
|
---|
252 | virtual ~UIAction() RT_OVERRIDE { delete menu(); QAction::setShortcuts(QList<QKeySequence>() /*unregister*/); }
|
---|
253 |
|
---|
254 | /** Returns action-pool this action belongs to. */
|
---|
255 | UIActionPool *actionPool() const { return m_pActionPool; }
|
---|
256 | /** Returns action type. */
|
---|
257 | UIActionType type() const { return m_enmType; }
|
---|
258 |
|
---|
259 | /** Returns menu contained by this action. */
|
---|
260 | UIMenu *menu() const;
|
---|
261 |
|
---|
262 | /** Returns current action state. */
|
---|
263 | int state() const { return m_iState; }
|
---|
264 | /** Defines current action @a iState. */
|
---|
265 | void setState(int iState);
|
---|
266 |
|
---|
267 | /** Defines @a icon for certain @a iState. */
|
---|
268 | void setIcon(int iState, const QIcon &icon);
|
---|
269 | /** Defines @a icon. */
|
---|
270 | void setIcon(const QIcon &icon);
|
---|
271 |
|
---|
272 | /** Returns current action name. */
|
---|
273 | QString name() const { return m_strName; }
|
---|
274 | /** Defines current action name. */
|
---|
275 | void setName(const QString &strName);
|
---|
276 |
|
---|
277 | /** Returns action shortcut scope. */
|
---|
278 | QString shortcutScope() const { return m_strShortcutScope; }
|
---|
279 | /** Defines action @a strShortcutScope. */
|
---|
280 | void setShortcutScope(const QString &strShortcutScope) { m_strShortcutScope = strShortcutScope; }
|
---|
281 |
|
---|
282 | /** Defines current keyboard shortcuts for this action. */
|
---|
283 | void setShortcuts(const QList<QKeySequence> &shortcuts);
|
---|
284 | /** Make action show keyboard shortcut. */
|
---|
285 | void showShortcut();
|
---|
286 | /** Make action hide keyboard shortcut. */
|
---|
287 | void hideShortcut();
|
---|
288 |
|
---|
289 | /** Returns action extra-data ID. */
|
---|
290 | virtual int extraDataID() const { return 0; }
|
---|
291 | /** Returns action extra-data key. */
|
---|
292 | virtual QString extraDataKey() const { return QString(); }
|
---|
293 | /** Returns whether action is allowed. */
|
---|
294 | virtual bool isAllowed() const { return true; }
|
---|
295 |
|
---|
296 | /** Returns extra-data ID to save keyboard shortcut under. */
|
---|
297 | virtual QString shortcutExtraDataID() const { return QString(); }
|
---|
298 | /** Returns default keyboard shortcut for this action. */
|
---|
299 | virtual QKeySequence defaultShortcut(UIActionPoolType) const { return QKeySequence(); }
|
---|
300 | /** Returns standard keyboard shortcut for this action. */
|
---|
301 | virtual QKeySequence standardShortcut(UIActionPoolType) const { return QKeySequence(); }
|
---|
302 |
|
---|
303 | /** Retranslates action. */
|
---|
304 | virtual void retranslateUi() = 0;
|
---|
305 |
|
---|
306 | protected:
|
---|
307 |
|
---|
308 | /** Handles state change. */
|
---|
309 | virtual void handleStateChange() {}
|
---|
310 |
|
---|
311 | /** Returns current action name in menu. */
|
---|
312 | QString nameInMenu() const;
|
---|
313 |
|
---|
314 | /** Updates action icon. */
|
---|
315 | void updateIcon();
|
---|
316 | /** Updates action text. */
|
---|
317 | void updateText();
|
---|
318 |
|
---|
319 | /** Simplifies passed @a strText by removing dots and ampersands.
|
---|
320 | * @note Used to simplify action names for tool-tip needs. */
|
---|
321 | static QString simplifyText(QString strText);
|
---|
322 |
|
---|
323 | /** Holds the reference to the action-pool this action belongs to. */
|
---|
324 | UIActionPool *m_pActionPool;
|
---|
325 | /** Holds the type of the action-pool this action belongs to. */
|
---|
326 | const UIActionPoolType m_enmActionPoolType;
|
---|
327 |
|
---|
328 | /** Holds the action type. */
|
---|
329 | const UIActionType m_enmType;
|
---|
330 | /** Holds whether this is machine-menu action. */
|
---|
331 | const bool m_fMachineMenuAction;
|
---|
332 |
|
---|
333 | /** Holds current action state. */
|
---|
334 | int m_iState;
|
---|
335 | /** Holds action icons. */
|
---|
336 | QVector<QIcon> m_icons;
|
---|
337 |
|
---|
338 | /** Holds the action name. */
|
---|
339 | QString m_strName;
|
---|
340 |
|
---|
341 | /** Holds the action shortcut scope. */
|
---|
342 | QString m_strShortcutScope;
|
---|
343 | /** Holds the action shortcuts. */
|
---|
344 | QList<QKeySequence> m_shortcuts;
|
---|
345 | /** Holds whether action shortcut hidden. */
|
---|
346 | bool m_fShortcutHidden;
|
---|
347 | };
|
---|
348 |
|
---|
349 |
|
---|
350 | /** Abstract UIAction extension for 'Menu' action type. */
|
---|
351 | class SHARED_LIBRARY_STUFF UIActionMenu : public UIAction
|
---|
352 | {
|
---|
353 | Q_OBJECT;
|
---|
354 |
|
---|
355 | protected:
|
---|
356 |
|
---|
357 | /** Constructs menu action passing @a pParent to the base-class.
|
---|
358 | * @param strIcon Brings the normal-icon name.
|
---|
359 | * @param strIconDisabled Brings the disabled-icon name. */
|
---|
360 | UIActionMenu(UIActionPool *pParent,
|
---|
361 | const QString &strIcon = QString(), const QString &strIconDisabled = QString());
|
---|
362 | /** Constructs menu action passing @a pParent to the base-class.
|
---|
363 | * @param strIconNormal Brings the normal-icon name.
|
---|
364 | * @param strIconSmall Brings the small-icon name.
|
---|
365 | * @param strIconNormalDisabled Brings the normal-disabled-icon name.
|
---|
366 | * @param strIconSmallDisabled Brings the small-disabled-icon name. */
|
---|
367 | UIActionMenu(UIActionPool *pParent,
|
---|
368 | const QString &strIconNormal, const QString &strIconSmall,
|
---|
369 | const QString &strIconNormalDisabled, const QString &strIconSmallDisabled);
|
---|
370 | /** Constructs menu action passing @a pParent to the base-class.
|
---|
371 | * @param icon Brings the icon. */
|
---|
372 | UIActionMenu(UIActionPool *pParent,
|
---|
373 | const QIcon &icon);
|
---|
374 |
|
---|
375 | /** Destructs menu action. */
|
---|
376 | virtual ~UIActionMenu() RT_OVERRIDE;
|
---|
377 |
|
---|
378 | /** Defines whether tool-tip should be shown. */
|
---|
379 | void setShowToolTip(bool fShowToolTip);
|
---|
380 |
|
---|
381 | /** Shows menu. */
|
---|
382 | void showMenu();
|
---|
383 | /** Hides menu. */
|
---|
384 | void hideMenu();
|
---|
385 |
|
---|
386 | private:
|
---|
387 |
|
---|
388 | /** Prepares all. */
|
---|
389 | void prepare();
|
---|
390 |
|
---|
391 | /** Holds the menu instance. */
|
---|
392 | UIMenu *m_pMenu;
|
---|
393 | };
|
---|
394 |
|
---|
395 |
|
---|
396 | /** Abstract UIAction extension for 'Simple' action type. */
|
---|
397 | class SHARED_LIBRARY_STUFF UIActionSimple : public UIAction
|
---|
398 | {
|
---|
399 | Q_OBJECT;
|
---|
400 |
|
---|
401 | protected:
|
---|
402 |
|
---|
403 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
404 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
405 | UIActionSimple(UIActionPool *pParent,
|
---|
406 | bool fMachineMenuAction = false);
|
---|
407 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
408 | * @param strIcon Brings the normal-icon name.
|
---|
409 | * @param strIconDisabled Brings the disabled-icon name.
|
---|
410 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
411 | UIActionSimple(UIActionPool *pParent,
|
---|
412 | const QString &strIcon, const QString &strIconDisabled,
|
---|
413 | bool fMachineMenuAction = false);
|
---|
414 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
415 | * @param strIconNormal Brings the normal-icon name.
|
---|
416 | * @param strIconSmall Brings the small-icon name.
|
---|
417 | * @param strIconNormalDisabled Brings the normal-disabled-icon name.
|
---|
418 | * @param strIconSmallDisabled Brings the small-disabled-icon name.
|
---|
419 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
420 | UIActionSimple(UIActionPool *pParent,
|
---|
421 | const QString &strIconNormal, const QString &strIconSmall,
|
---|
422 | const QString &strIconNormalDisabled, const QString &strIconSmallDisabled,
|
---|
423 | bool fMachineMenuAction = false);
|
---|
424 | /** Constructs simple action passing @a pParent to the base-class.
|
---|
425 | * @param icon Brings the icon.
|
---|
426 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
427 | UIActionSimple(UIActionPool *pParent,
|
---|
428 | const QIcon &icon,
|
---|
429 | bool fMachineMenuAction = false);
|
---|
430 | };
|
---|
431 |
|
---|
432 |
|
---|
433 | /** Abstract UIAction extension for 'Toggle' action type. */
|
---|
434 | class SHARED_LIBRARY_STUFF UIActionToggle : public UIAction
|
---|
435 | {
|
---|
436 | Q_OBJECT;
|
---|
437 |
|
---|
438 | protected:
|
---|
439 |
|
---|
440 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
441 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
442 | UIActionToggle(UIActionPool *pParent,
|
---|
443 | bool fMachineMenuAction = false);
|
---|
444 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
445 | * @param strIcon Brings the normal-icon name.
|
---|
446 | * @param strIconDisabled Brings the disabled-icon name.
|
---|
447 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
448 | UIActionToggle(UIActionPool *pParent,
|
---|
449 | const QString &strIcon, const QString &strIconDisabled,
|
---|
450 | bool fMachineMenuAction = false);
|
---|
451 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
452 | * @param strIconOn Brings the on-icon name.
|
---|
453 | * @param strIconOff Brings the off-icon name.
|
---|
454 | * @param strIconOnDisabled Brings the on-disabled-icon name.
|
---|
455 | * @param strIconOffDisabled Brings the off-disabled-icon name.
|
---|
456 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
457 | UIActionToggle(UIActionPool *pParent,
|
---|
458 | const QString &strIconOn, const QString &strIconOff,
|
---|
459 | const QString &strIconOnDisabled, const QString &strIconOffDisabled,
|
---|
460 | bool fMachineMenuAction = false);
|
---|
461 | /** Constructs toggle action passing @a pParent to the base-class.
|
---|
462 | * @param icon Brings the icon.
|
---|
463 | * @param fMachineMenuAction Brings whether this action is a part of machine menu. */
|
---|
464 | UIActionToggle(UIActionPool *pParent,
|
---|
465 | const QIcon &icon,
|
---|
466 | bool fMachineMenuAction = false);
|
---|
467 |
|
---|
468 | private:
|
---|
469 |
|
---|
470 | /** Prepares all. */
|
---|
471 | void prepare();
|
---|
472 | };
|
---|
473 |
|
---|
474 |
|
---|
475 | /** Abstract QObject extension
|
---|
476 | * representing action-pool interface and factory. */
|
---|
477 | class SHARED_LIBRARY_STUFF UIActionPool : public QIWithRetranslateUI3<QObject>
|
---|
478 | {
|
---|
479 | Q_OBJECT;
|
---|
480 |
|
---|
481 | #if RT_MSC_PREREQ(RT_MSC_VER_VS2019_U11)
|
---|
482 | # pragma warning(push)
|
---|
483 | # pragma warning(disable: 5243) /* warning C5243: 'UIActionPool::PTFActionPoolManager': using incomplete class 'UIActionPoolManager' can cause potential one definition rule violation due to ABI limitation */
|
---|
484 | #endif
|
---|
485 | /** Pointer to menu update-handler for this class. */
|
---|
486 | typedef void (UIActionPool::*PTFActionPool)();
|
---|
487 | /** Pointer to menu update-handler for Manager sub-class. */
|
---|
488 | typedef void (UIActionPoolManager::*PTFActionPoolManager)();
|
---|
489 | /** Pointer to menu update-handler for Runtime sub-class. */
|
---|
490 | typedef void (UIActionPoolRuntime::*PTFActionPoolRuntime)();
|
---|
491 | /** Union for three defines above. */
|
---|
492 | union PointerToFunction
|
---|
493 | {
|
---|
494 | PTFActionPool ptf;
|
---|
495 | PTFActionPoolManager ptfm;
|
---|
496 | PTFActionPoolRuntime ptfr;
|
---|
497 | };
|
---|
498 | #if RT_MSC_PREREQ(RT_MSC_VER_VS2019_U11)
|
---|
499 | # pragma warning(pop)
|
---|
500 | #endif
|
---|
501 |
|
---|
502 | signals:
|
---|
503 |
|
---|
504 | /** Notifies about menu prepare. */
|
---|
505 | void sigNotifyAboutMenuPrepare(int iIndex, QMenu *pMenu);
|
---|
506 |
|
---|
507 | #ifdef VBOX_WS_MAC
|
---|
508 | /** Notifies about @a pAction hovered. */
|
---|
509 | void sigActionHovered(UIAction *pAction);
|
---|
510 | #endif
|
---|
511 |
|
---|
512 | public:
|
---|
513 |
|
---|
514 | /** Creates singleton instance. */
|
---|
515 | static UIActionPool *create(UIActionPoolType enmType);
|
---|
516 | /** Destroys singleton instance. */
|
---|
517 | static void destroy(UIActionPool *pActionPool);
|
---|
518 |
|
---|
519 | /** Creates temporary singleton instance,
|
---|
520 | * used to initialize shortcuts-pool from action-pool of passed @a enmType. */
|
---|
521 | static void createTemporary(UIActionPoolType enmType);
|
---|
522 |
|
---|
523 | /** Cast action-pool to Manager one. */
|
---|
524 | UIActionPoolManager *toManager();
|
---|
525 | /** Cast action-pool to Runtime one. */
|
---|
526 | UIActionPoolRuntime *toRuntime();
|
---|
527 |
|
---|
528 | /** Returns action-pool type. */
|
---|
529 | UIActionPoolType type() const { return m_enmType; }
|
---|
530 | /** Returns whether this action-pool is temporary. */
|
---|
531 | bool isTemporary() const { return m_fTemporary; }
|
---|
532 |
|
---|
533 | /** Returns the action for the passed @a iIndex. */
|
---|
534 | UIAction *action(int iIndex) const;
|
---|
535 | /** Returns all the actions action-pool contains. */
|
---|
536 | QList<UIAction*> actions() const;
|
---|
537 |
|
---|
538 | /** Returns the action group for the passed @a iIndex.
|
---|
539 | * @note Only menu actions can have action groups. */
|
---|
540 | QActionGroup *actionGroup(int iIndex) const;
|
---|
541 |
|
---|
542 | /** Returns the list of main menus. */
|
---|
543 | QList<QMenu*> menus() const { return m_mainMenus; }
|
---|
544 |
|
---|
545 | /** Returns whether the menu with passed @a type is allowed in menu-bar. */
|
---|
546 | bool isAllowedInMenuBar(UIExtraDataMetaDefs::MenuType type) const;
|
---|
547 | /** Defines menu-bar @a enmRestriction for passed @a level. */
|
---|
548 | void setRestrictionForMenuBar(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuType enmRestriction);
|
---|
549 |
|
---|
550 | /** Returns whether the action with passed @a type is allowed in the 'Application' menu. */
|
---|
551 | bool isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType type) const;
|
---|
552 | /** Defines 'Application' menu @a enmRestriction for passed @a level. */
|
---|
553 | void setRestrictionForMenuApplication(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuApplicationActionType enmRestriction);
|
---|
554 |
|
---|
555 | #ifdef VBOX_WS_MAC
|
---|
556 | /** Mac OS X: Returns whether the action with passed @a type is allowed in the 'Window' menu. */
|
---|
557 | bool isAllowedInMenuWindow(UIExtraDataMetaDefs::MenuWindowActionType type) const;
|
---|
558 | /** Mac OS X: Defines 'Window' menu @a enmRestriction for passed @a level. */
|
---|
559 | void setRestrictionForMenuWindow(UIActionRestrictionLevel level, UIExtraDataMetaDefs::MenuWindowActionType enmRestriction);
|
---|
560 | #endif /* VBOX_WS_MAC */
|
---|
561 |
|
---|
562 | /** Returns whether the action with passed @a type is allowed in the 'Help' menu. */
|
---|
563 | bool isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType enmType) const;
|
---|
564 | /** Defines 'Help' menu @a enmRestriction for passed @a level. */
|
---|
565 | void setRestrictionForMenuHelp(UIActionRestrictionLevel enmLevel, UIExtraDataMetaDefs::MenuHelpActionType enmRestriction);
|
---|
566 |
|
---|
567 | /** Hot-key processing delegate. */
|
---|
568 | bool processHotKey(const QKeySequence &key);
|
---|
569 |
|
---|
570 | /** Defines whether shortcuts of menu actions with specified @a iIndex should be visible. */
|
---|
571 | virtual void setShortcutsVisible(int iIndex, bool fVisible) { Q_UNUSED(iIndex); Q_UNUSED(fVisible); }
|
---|
572 | /** Returns extra-data ID to save keyboard shortcuts under. */
|
---|
573 | virtual QString shortcutsExtraDataID() const = 0;
|
---|
574 |
|
---|
575 | public slots:
|
---|
576 |
|
---|
577 | /** Handles menu prepare. */
|
---|
578 | void sltHandleMenuPrepare();
|
---|
579 |
|
---|
580 | #ifdef VBOX_WS_MAC
|
---|
581 | /** Handles action hovered signal. */
|
---|
582 | void sltActionHovered();
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | protected slots:
|
---|
586 |
|
---|
587 | /** Loads keyboard shortcuts of action-pool into shortcuts-pool. */
|
---|
588 | void sltApplyShortcuts() { updateShortcuts(); }
|
---|
589 |
|
---|
590 | protected:
|
---|
591 |
|
---|
592 | /** Constructs probably @a fTemporary action-pool of passed @a enmType. */
|
---|
593 | UIActionPool(UIActionPoolType enmType, bool fTemporary = false);
|
---|
594 |
|
---|
595 | /** Prepares pool. */
|
---|
596 | virtual void preparePool();
|
---|
597 | /** Prepares connections. */
|
---|
598 | virtual void prepareConnections();
|
---|
599 | /** Cleanups connections. */
|
---|
600 | virtual void cleanupConnections();
|
---|
601 | /** Cleanups pool. */
|
---|
602 | virtual void cleanupPool();
|
---|
603 |
|
---|
604 | /** Updates configuration. */
|
---|
605 | virtual void updateConfiguration();
|
---|
606 |
|
---|
607 | /** Updates menu with certain @a iIndex. */
|
---|
608 | virtual void updateMenu(int iIndex);
|
---|
609 | /** Updates menus. */
|
---|
610 | virtual void updateMenus() = 0;
|
---|
611 |
|
---|
612 | /** Updates shortcuts. */
|
---|
613 | virtual void updateShortcuts();
|
---|
614 |
|
---|
615 | /** Handles any Qt @a pEvent */
|
---|
616 | virtual bool event(QEvent *pEvent) RT_OVERRIDE;
|
---|
617 |
|
---|
618 | /** Handles translation event. */
|
---|
619 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
620 |
|
---|
621 | /** Adds action into corresponding menu. */
|
---|
622 | bool addAction(UIMenu *pMenu, UIAction *pAction, bool fReallyAdd = true);
|
---|
623 | /** Adds action's menu into corresponding menu list. */
|
---|
624 | bool addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd = true);
|
---|
625 |
|
---|
626 | /** Updates 'Application' menu. */
|
---|
627 | void updateMenuApplication();
|
---|
628 | #ifdef VBOX_WS_MAC
|
---|
629 | /** Mac OS X: Updates 'Window' menu. */
|
---|
630 | void updateMenuWindow();
|
---|
631 | #endif
|
---|
632 | /** Updates 'Help' menu. */
|
---|
633 | void updateMenuHelp();
|
---|
634 | /** Updates 'Log Viewer Window' menu. */
|
---|
635 | void updateMenuLogViewerWindow();
|
---|
636 | /** Updates 'Log Viewer' menu. */
|
---|
637 | void updateMenuLogViewer();
|
---|
638 | /** Updates 'Log Viewer' @a pMenu. */
|
---|
639 | void updateMenuLogViewerWrapper(UIMenu *pMenu);
|
---|
640 | /** Updates 'Performance Monitor' menu. */
|
---|
641 | void updateMenuVMActivityMonitor();
|
---|
642 | /** Updates 'File Manager' menu. */
|
---|
643 | void updateMenuFileManager();
|
---|
644 | /** Updates 'File Manager' @a pMenu. */
|
---|
645 | void updateMenuFileManagerWrapper(UIMenu *pMenu);
|
---|
646 |
|
---|
647 | /** Holds the map of actions. */
|
---|
648 | QMap<int, UIAction*> m_pool;
|
---|
649 | /** Holds the map of action groups.
|
---|
650 | * @note Only menu actions can have action groups. */
|
---|
651 | QMap<int, QActionGroup*> m_groupPool;
|
---|
652 | /** Holds the map of validation handlers. */
|
---|
653 | QMap<int, PointerToFunction> m_menuUpdateHandlers;
|
---|
654 | /** Holds the set of invalidated action indexes. */
|
---|
655 | QSet<int> m_invalidations;
|
---|
656 |
|
---|
657 | /** Holds the list of main menus. */
|
---|
658 | QList<QMenu*> m_mainMenus;
|
---|
659 |
|
---|
660 | /** Holds restricted menu types. */
|
---|
661 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuType> m_restrictedMenus;
|
---|
662 | /** Holds restricted action types of the 'Application' menu. */
|
---|
663 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuApplicationActionType> m_restrictedActionsMenuApplication;
|
---|
664 | #ifdef VBOX_WS_MAC
|
---|
665 | /** Mac OS X: Holds restricted action types of the 'Window' menu. */
|
---|
666 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuWindowActionType> m_restrictedActionsMenuWindow;
|
---|
667 | #endif
|
---|
668 | /** Holds restricted action types of the Help menu. */
|
---|
669 | QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuHelpActionType> m_restrictedActionsMenuHelp;
|
---|
670 |
|
---|
671 | private:
|
---|
672 |
|
---|
673 | /** Prepares all. */
|
---|
674 | void prepare();
|
---|
675 | /** Cleanups all. */
|
---|
676 | void cleanup();
|
---|
677 |
|
---|
678 | /** Holds the action-pool type. */
|
---|
679 | const UIActionPoolType m_enmType;
|
---|
680 | /** Holds whether this action-pool is temporary. */
|
---|
681 | const bool m_fTemporary;
|
---|
682 | };
|
---|
683 |
|
---|
684 |
|
---|
685 | #endif /* !FEQT_INCLUDED_SRC_globals_UIActionPool_h */
|
---|