Changeset 72166 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- May 8, 2018 3:57:55 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 122581
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r72158 r72166 576 576 endif 577 577 endif 578 579 VirtualBox_QT_MOCHDRS.darwin += \580 src/platform/darwin/UIWindowMenuManager.h581 578 582 579 ifndef VBOX_GUI_WITH_SHARED_LIBRARY … … 723 720 724 721 VirtualBox_QT_MOCHDRS.darwin += \ 725 src/platform/darwin/UICocoaSpecialControls.h 722 src/platform/darwin/UICocoaSpecialControls.h \ 723 src/platform/darwin/UIWindowMenuManager.h 726 724 endif 727 725 … … 873 871 874 872 VBoxGlobal_QT_MOCHDRS.darwin += \ 875 src/platform/darwin/UICocoaSpecialControls.h 873 src/platform/darwin/UICocoaSpecialControls.h \ 874 src/platform/darwin/UIWindowMenuManager.h 876 875 877 876 … … 896 895 src/widgets/UITabBar.cpp \ 897 896 src/wizards/importappliance/UIWizardImportApp.cpp 898 899 VirtualBox_QT_MOCSRCS.darwin += \900 src/platform/darwin/UIWindowMenuManager.cpp901 897 902 898 ifndef VBOX_GUI_WITH_SHARED_LIBRARY … … 928 924 src/widgets/UIStatusBarEditorWindow.cpp 929 925 926 ifdef VBOX_GUI_WITH_NETWORK_MANAGER 927 VirtualBox_QT_MOCSRCS += \ 928 src/net/UINetworkReply.cpp \ 929 src/net/UIUpdateManager.cpp 930 endif 931 932 ifdef VBOX_WITH_XPCOM 933 VirtualBox_QT_MOCSRCS += \ 934 src/globals/COMDefs.cpp 935 endif 936 937 VirtualBox_QT_MOCSRCS.darwin += \ 938 src/platform/darwin/UIWindowMenuManager.cpp 939 930 940 VirtualBox_QT_MOCSRCS.linux += \ 931 941 src/globals/UIDesktopWidgetWatchdog.cpp … … 934 944 VirtualBox_QT_MOCSRCS.freebsd += \ 935 945 src/globals/UIDesktopWidgetWatchdog.cpp 936 937 ifdef VBOX_GUI_WITH_NETWORK_MANAGER938 VirtualBox_QT_MOCSRCS += \939 src/net/UINetworkReply.cpp \940 src/net/UIUpdateManager.cpp941 endif942 943 ifdef VBOX_WITH_XPCOM944 VirtualBox_QT_MOCSRCS += \945 src/globals/COMDefs.cpp946 endif947 946 endif 948 947 … … 979 978 src/widgets/UIStatusBarEditorWindow.cpp 980 979 980 ifdef VBOX_GUI_WITH_NETWORK_MANAGER 981 VBoxGlobal_QT_MOCSRCS += \ 982 src/net/UINetworkReply.cpp \ 983 src/net/UIUpdateManager.cpp 984 endif 985 986 ifdef VBOX_WITH_XPCOM 987 VBoxGlobal_QT_MOCSRCS += \ 988 src/globals/COMDefs.cpp 989 990 VBoxGlobal_QT_MOCSRCS.darwin += \ 991 src/platform/darwin/UIWindowMenuManager.cpp 992 981 993 VBoxGlobal_QT_MOCSRCS.linux += \ 982 994 src/globals/UIDesktopWidgetWatchdog.cpp … … 985 997 VBoxGlobal_QT_MOCSRCS.freebsd += \ 986 998 src/globals/UIDesktopWidgetWatchdog.cpp 987 988 ifdef VBOX_GUI_WITH_NETWORK_MANAGER989 VBoxGlobal_QT_MOCSRCS += \990 src/net/UINetworkReply.cpp \991 src/net/UIUpdateManager.cpp992 endif993 994 ifdef VBOX_WITH_XPCOM995 VBoxGlobal_QT_MOCSRCS += \996 src/globals/COMDefs.cpp997 999 endif 998 1000 … … 1127 1129 src/platform/darwin/UIAbstractDockIconPreview.cpp \ 1128 1130 src/platform/darwin/UICocoaDockIconPreview.mm \ 1129 src/platform/darwin/UIWindowMenuManager.cpp \ 1131 src/platform/darwin/UIDesktopServices_darwin.cpp \ 1132 src/platform/darwin/UIDesktopServices_darwin_cocoa.mm 1130 1133 1131 1134 if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # X11 … … 1137 1140 src/platform/win/VirtualBox.rc \ 1138 1141 src/platform/win/UIDesktopServices_win.cpp 1139 1140 VirtualBox_SOURCES.darwin += \1141 src/platform/darwin/UIDesktopServices_darwin.cpp \1142 src/platform/darwin/UIDesktopServices_darwin_cocoa.mm1143 1142 1144 1143 ifdef VBOX_WITH_ICHAT_THEATER … … 1335 1334 src/platform/darwin/UICocoaApplication.mm \ 1336 1335 src/platform/darwin/UICocoaSpecialControls.mm \ 1336 src/platform/darwin/UIWindowMenuManager.cpp \ 1337 1337 src/platform/darwin/VBoxUtils-darwin-cocoa.mm \ 1338 1338 src/platform/darwin/VBoxUtils-darwin.cpp … … 1511 1511 src/platform/darwin/UICocoaApplication.mm \ 1512 1512 src/platform/darwin/UICocoaSpecialControls.mm \ 1513 src/platform/darwin/UIWindowMenuManager.cpp \ 1513 1514 src/platform/darwin/VBoxUtils-darwin-cocoa.mm \ 1514 1515 src/platform/darwin/VBoxUtils-darwin.cpp -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.cpp
r69500 r72166 5 5 6 6 /* 7 * Copyright (C) 2010-201 7Oracle Corporation7 * Copyright (C) 2010-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 33 33 34 34 35 /** QObject extension 35 36 * used as Mac OS X 'Window' menu helper. */ … … 41 42 42 43 /** Constructs menu-helper on the basis of passed @a windows. */ 43 UIMenuHelper(const QList<QWidget*> &windows) 44 { 45 /* Prepare 'Window' menu: */ 46 m_pWindowMenu = new QMenu; 47 /* Prepare action group: */ 48 m_pGroup = new QActionGroup(this); 49 m_pGroup->setExclusive(true); 50 /* Prepare 'Minimize' action: */ 51 m_pMinimizeAction = new QAction(this); 52 m_pWindowMenu->addAction(m_pMinimizeAction); 53 connect(m_pMinimizeAction, SIGNAL(triggered(bool)), 54 this, SLOT(sltMinimizeActiveWindow())); 55 /* Make sure all already available windows are 56 * properly registered within this menu: */ 57 for (int i = 0; i < windows.size(); ++i) 58 addWindow(windows.at(i)); 59 /* Translate finally: */ 60 retranslateUi(); 61 } 62 44 UIMenuHelper(const QList<QWidget*> &windows); 63 45 /** Destructs menu-helper. */ 64 ~UIMenuHelper() 65 { 66 /* Cleanup 'Window' menu: */ 67 delete m_pWindowMenu; 68 /* Cleanup actions: */ 69 qDeleteAll(m_windows); 70 } 46 virtual ~UIMenuHelper() /* override */; 71 47 72 48 /** Returns 'Window' menu. */ 73 QMenu *menu() const { return m_pWindowMenu; }49 QMenu *menu() const { return m_pWindowMenu; } 74 50 75 51 /** Adds @a pWindow into 'Window' menu. */ 76 QAction* addWindow(QWidget *pWindow) 77 { 78 QAction *pAction = 0; 79 if ( pWindow 80 && !m_windows.contains(pWindow)) 52 QAction *addWindow(QWidget *pWindow); 53 /** Removes @a pWindow from 'Window' menu. */ 54 void removeWindow(QWidget *pWindow); 55 56 /** Handles translation event. */ 57 void retranslateUi(); 58 59 /** Updates toggle action states according to passed @a pActiveWindow. */ 60 void updateStatus(QWidget *pActiveWindow); 61 62 private slots: 63 64 /** Handles request to minimize active-window. */ 65 void sltMinimizeActiveWindow(); 66 67 /** Handles request to raise sender window. */ 68 void sltRaiseSender(); 69 70 private: 71 72 /** Holds the 'Window' menu instance. */ 73 QMenu *m_pWindowMenu; 74 /** Holds the action group instance. */ 75 QActionGroup *m_pGroup; 76 /** Holds the 'Minimize' action instance. */ 77 QAction *m_pMinimizeAction; 78 /** Holds the hash of the registered menu-helper instances. */ 79 QHash<QWidget*, QAction*> m_windows; 80 }; 81 82 83 /********************************************************************************************************************************* 84 * Class UIMenuHelper implementation. * 85 *********************************************************************************************************************************/ 86 87 UIMenuHelper::UIMenuHelper(const QList<QWidget*> &windows) 88 { 89 /* Prepare 'Window' menu: */ 90 m_pWindowMenu = new QMenu; 91 92 /* Prepare action group: */ 93 m_pGroup = new QActionGroup(this); 94 m_pGroup->setExclusive(true); 95 96 /* Prepare 'Minimize' action: */ 97 m_pMinimizeAction = new QAction(this); 98 m_pWindowMenu->addAction(m_pMinimizeAction); 99 connect(m_pMinimizeAction, SIGNAL(triggered(bool)), 100 this, SLOT(sltMinimizeActiveWindow())); 101 102 /* Make sure all already available windows are 103 * properly registered within this menu: */ 104 for (int i = 0; i < windows.size(); ++i) 105 addWindow(windows.at(i)); 106 107 /* Apply language settings: */ 108 retranslateUi(); 109 } 110 111 UIMenuHelper::~UIMenuHelper() 112 { 113 /* Cleanup 'Window' menu: */ 114 delete m_pWindowMenu; 115 116 /* Cleanup actions: */ 117 qDeleteAll(m_windows); 118 } 119 120 QAction *UIMenuHelper::addWindow(QWidget *pWindow) 121 { 122 QAction *pAction = 0; 123 if ( pWindow 124 && !m_windows.contains(pWindow)) 125 { 126 if (m_windows.size() < 2) 127 m_pWindowMenu->addSeparator(); 128 129 /* The main window always first: */ 130 pAction = new QAction(this); 131 pAction->setText(pWindow->windowTitle()); 132 pAction->setMenuRole(QAction::NoRole); 133 pAction->setData(QVariant::fromValue(pWindow)); 134 pAction->setCheckable(true); 135 136 /* The first registered one is always 137 * considered as the main window: */ 138 if (m_windows.size() == 0) 139 pAction->setShortcut(QKeySequence("Ctrl+0")); 140 m_pGroup->addAction(pAction); 141 connect(pAction, SIGNAL(triggered(bool)), 142 this, SLOT(sltRaiseSender())); 143 m_pWindowMenu->addAction(pAction); 144 m_windows[pWindow] = pAction; 145 } 146 return pAction; 147 } 148 149 void UIMenuHelper::removeWindow(QWidget *pWindow) 150 { 151 if (m_windows.contains(pWindow)) 152 { 153 delete m_windows.value(pWindow); 154 m_windows.remove(pWindow); 155 } 156 } 157 158 void UIMenuHelper::retranslateUi() 159 { 160 /* Translate menu: */ 161 m_pWindowMenu->setTitle(QApplication::translate("UIActionPool", "&Window")); 162 163 /* Translate menu 'Minimize' action: */ 164 m_pMinimizeAction->setText(QApplication::translate("UIActionPool", "&Minimize")); 165 m_pMinimizeAction->setShortcut(QKeySequence("Ctrl+M")); 166 167 /* Translate other menu-actions: */ 168 foreach (QAction *pAction, m_windows.values()) 169 { 170 /* Get corresponding window from action's data: */ 171 QWidget *pWindow = pAction->data().value<QWidget*>(); 172 /* Use the window's title as the action's text: */ 173 pAction->setText(pWindow->windowTitle()); 174 } 175 } 176 177 void UIMenuHelper::updateStatus(QWidget *pActiveWindow) 178 { 179 /* 'Minimize' action is enabled if there is active-window: */ 180 m_pMinimizeAction->setEnabled(pActiveWindow != 0); 181 182 /* If there is active-window: */ 183 if (pActiveWindow) 184 { 185 /* Toggle corresponding action on: */ 186 if (m_windows.contains(pActiveWindow)) 187 m_windows.value(pActiveWindow)->setChecked(true); 188 } 189 /* If there is no active-window: */ 190 else 191 { 192 /* Make sure corresponding action toggled off: */ 193 if (QAction *pChecked = m_pGroup->checkedAction()) 194 pChecked->setChecked(false); 195 } 196 } 197 198 void UIMenuHelper::sltMinimizeActiveWindow() 199 { 200 if (QWidget *pActiveWindow = qApp->activeWindow()) 201 pActiveWindow->showMinimized(); 202 } 203 204 void UIMenuHelper::sltRaiseSender() 205 { 206 AssertReturnVoid(sender()); 207 if (QAction *pAction = qobject_cast<QAction*>(sender())) 208 { 209 if (QWidget *pWidget = pAction->data().value<QWidget*>()) 81 210 { 82 if (m_windows.size() < 2) 83 m_pWindowMenu->addSeparator(); 84 /* The main window always first: */ 85 pAction = new QAction(this); 86 pAction->setText(pWindow->windowTitle()); 87 pAction->setMenuRole(QAction::NoRole); 88 pAction->setData(QVariant::fromValue(pWindow)); 89 pAction->setCheckable(true); 90 /* The first registered one is always 91 * considered as the main window: */ 92 if (m_windows.size() == 0) 93 pAction->setShortcut(QKeySequence("Ctrl+0")); 94 m_pGroup->addAction(pAction); 95 connect(pAction, SIGNAL(triggered(bool)), 96 this, SLOT(sltRaiseSender())); 97 m_pWindowMenu->addAction(pAction); 98 m_windows[pWindow] = pAction; 211 pWidget->show(); 212 pWidget->raise(); 213 pWidget->activateWindow(); 99 214 } 100 return pAction; 101 } 102 103 /** Removes @a pWindow from 'Window' menu. */ 104 void removeWindow(QWidget *pWindow) 105 { 106 if (m_windows.contains(pWindow)) 107 { 108 delete m_windows.value(pWindow); 109 m_windows.remove(pWindow); 110 } 111 } 112 113 /** Handles translation event. */ 114 void retranslateUi() 115 { 116 /* Translate menu: */ 117 m_pWindowMenu->setTitle(QApplication::translate("UIActionPool", "&Window")); 118 119 /* Translate menu 'Minimize' action: */ 120 m_pMinimizeAction->setText(QApplication::translate("UIActionPool", "&Minimize")); 121 m_pMinimizeAction->setShortcut(QKeySequence("Ctrl+M")); 122 123 /* Translate other menu-actions: */ 124 foreach (QAction *pAction, m_windows.values()) 125 { 126 /* Get corresponding window from action's data: */ 127 QWidget *pWindow = pAction->data().value<QWidget*>(); 128 /* Use the window's title as the action's text: */ 129 pAction->setText(pWindow->windowTitle()); 130 } 131 } 132 133 /** Updates toggle action states according to passed @a pActiveWindow. */ 134 void updateStatus(QWidget *pActiveWindow) 135 { 136 /* 'Minimize' action is enabled if there is active-window: */ 137 m_pMinimizeAction->setEnabled(pActiveWindow != 0); 138 /* If there is active-window: */ 139 if (pActiveWindow) 140 { 141 /* Toggle corresponding action on: */ 142 if (m_windows.contains(pActiveWindow)) 143 m_windows.value(pActiveWindow)->setChecked(true); 144 } 145 /* If there is no active-window: */ 146 else 147 { 148 /* Make sure corresponding action toggled off: */ 149 if (QAction *pChecked = m_pGroup->checkedAction()) 150 pChecked->setChecked(false); 151 } 152 } 153 154 private slots: 155 156 /** Handles request to minimize active-window. */ 157 void sltMinimizeActiveWindow() 158 { 159 if (QWidget *pActiveWindow = qApp->activeWindow()) 160 pActiveWindow->showMinimized(); 161 } 162 163 /** Handles request to raise sender window. */ 164 void sltRaiseSender() 165 { 166 AssertReturnVoid(sender()); 167 if (QAction *pAction = qobject_cast<QAction*>(sender())) 168 { 169 if (QWidget *pWidget = pAction->data().value<QWidget*>()) 170 { 171 pWidget->show(); 172 pWidget->raise(); 173 pWidget->activateWindow(); 174 } 175 } 176 } 177 178 private: 179 180 /** Holds the 'Window' menu instance. */ 181 QMenu *m_pWindowMenu; 182 /** Holds the action group instance. */ 183 QActionGroup *m_pGroup; 184 /** Holds the 'Minimize' action instance. */ 185 QAction *m_pMinimizeAction; 186 /** Holds the hash of the registered menu-helper instances. */ 187 QHash<QWidget*, QAction*> m_windows; 188 }; 215 } 216 } 189 217 190 218 … … 194 222 195 223 /* static */ 196 UIWindowMenuManager* UIWindowMenuManager:: m_spInstance = 0;224 UIWindowMenuManager* UIWindowMenuManager::s_pInstance = 0; 197 225 198 226 /* static */ … … 200 228 { 201 229 /* Make sure 'Window' menu Manager is not created: */ 202 AssertReturnVoid(! m_spInstance);230 AssertReturnVoid(!s_pInstance); 203 231 204 232 /* Create 'Window' menu Manager: */ … … 210 238 { 211 239 /* Make sure 'Window' menu Manager is created: */ 212 AssertPtrReturnVoid( m_spInstance);240 AssertPtrReturnVoid(s_pInstance); 213 241 214 242 /* Delete 'Window' menu Manager: */ 215 delete m_spInstance; 216 } 217 218 UIWindowMenuManager::UIWindowMenuManager() 219 { 220 /* Assign instance: */ 221 m_spInstance = this; 222 223 /* Install global event-filter: */ 224 qApp->installEventFilter(this); 225 } 226 227 UIWindowMenuManager::~UIWindowMenuManager() 228 { 229 /* Cleanup all helpers: */ 230 qDeleteAll(m_helpers); 231 232 /* Unassign instance: */ 233 m_spInstance = 0; 243 delete s_pInstance; 234 244 } 235 245 … … 282 292 } 283 293 294 UIWindowMenuManager::UIWindowMenuManager() 295 { 296 /* Assign instance: */ 297 s_pInstance = this; 298 299 /* Install global event-filter: */ 300 qApp->installEventFilter(this); 301 } 302 303 UIWindowMenuManager::~UIWindowMenuManager() 304 { 305 /* Cleanup all helpers: */ 306 qDeleteAll(m_helpers); 307 308 /* Unassign instance: */ 309 s_pInstance = 0; 310 } 311 284 312 bool UIWindowMenuManager::eventFilter(QObject *pObject, QEvent *pEvent) 285 313 { … … 288 316 289 317 #ifdef VBOX_OSE /// @todo Do we still need it? 290 /* Stupid Qt: Qt doesn't check if a window is minimized when a command is 291 * executed. This leads to strange behaviour. The minimized window is 292 * partly restored, but not usable. As a workaround we raise the parent 293 * window before we let execute the command. 294 * Note: fixed in our local Qt build since 4.7.0. */ 318 // WORKAROUND: 319 // Stupid Qt: Qt doesn't check if a window is minimized when a command is 320 // executed. This leads to strange behaviour. The minimized window is 321 // partly restored, but not usable. As a workaround we raise the parent 322 // window before we let execute the command. 323 // Note: fixed in our local Qt build since 4.7.0. 295 324 if (pObject && type == QEvent::Show) 296 325 { … … 335 364 } 336 365 366 337 367 #include "UIWindowMenuManager.moc" 338 -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.h
r69500 r72166 5 5 6 6 /* 7 * Copyright (C) 2010-201 7Oracle Corporation7 * Copyright (C) 2010-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 21 21 /* Qt includes: */ 22 #include <QHash> 22 23 #include <QObject> 23 #include <QHash>24 24 25 25 /* GUI includes: */ … … 27 27 28 28 /* Forward declarations: */ 29 class QMenu; 29 30 class UIMenuHelper; 30 class QMenu;31 31 32 32 /** Singleton QObject extension 33 33 * used as Mac OS X 'Window' menu Manager. */ 34 class UIWindowMenuManager : public QIWithRetranslateUI3<QObject>34 class SHARED_LIBRARY_STUFF UIWindowMenuManager : public QIWithRetranslateUI3<QObject> 35 35 { 36 36 Q_OBJECT; … … 38 38 public: 39 39 40 /** Static constructor. */40 /** Creates instance. */ 41 41 static void create(); 42 /** Static destructor. */42 /** Destroyes instance. */ 43 43 static void destroy(); 44 /** Static instance provider. */45 static UIWindowMenuManager * instance() { return m_spInstance; }44 /** Returns current instance. */ 45 static UIWindowMenuManager *instance() { return s_pInstance; } 46 46 47 47 /** Creates 'Window' menu for passed @a pWindow. */ 48 QMenu *createMenu(QWidget *pWindow);48 QMenu *createMenu(QWidget *pWindow); 49 49 /** Destroys 'Window' menu for passed @a pWindow. */ 50 50 void destroyMenu(QWidget *pWindow); … … 56 56 57 57 /** Handles translation event. */ 58 virtual void retranslateUi() ;58 virtual void retranslateUi() /* override */; 59 59 60 60 protected: … … 66 66 67 67 /** Preprocesses any Qt @a pEvent for passed @a pObject. */ 68 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) ;68 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 69 69 70 70 private: 71 71 72 72 /** Holds the static instance. */ 73 static UIWindowMenuManager * m_spInstance;73 static UIWindowMenuManager *s_pInstance; 74 74 75 75 /** Holds the list of the registered window references. */ 76 QList<QWidget*> m_windows;76 QList<QWidget*> m_windows; 77 77 78 78 /** Holds the hash of the registered menu-helper instances. */ 79 QHash<QWidget*, UIMenuHelper*> m_helpers;79 QHash<QWidget*, UIMenuHelper*> m_helpers; 80 80 }; 81 81 82 /** Singleton 'Window' menu Manager 'official' name. */ 82 83 #define gpWindowMenuManager UIWindowMenuManager::instance() 83 84 84 85 #endif /* !___UIWindowMenuManager_h___ */ 85
Note:
See TracChangeset
for help on using the changeset viewer.