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