1 | /* $Id: UIMachineMenuBar.cpp 45842 2013-04-30 15:37:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineMenuBar class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010-2013 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Qt includes: */
|
---|
21 | #include <QMenuBar>
|
---|
22 | #include <QPainter>
|
---|
23 | #include <QPaintEvent>
|
---|
24 | #include <QPixmapCache>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "UIMachineMenuBar.h"
|
---|
28 | #include "UISession.h"
|
---|
29 | #include "UIActionPoolRuntime.h"
|
---|
30 | #include "VBoxGlobal.h"
|
---|
31 | #include "UIMessageCenter.h"
|
---|
32 | #include "UIExtraDataEventHandler.h"
|
---|
33 | #include "UIImageTools.h"
|
---|
34 | #include "UINetworkManager.h"
|
---|
35 |
|
---|
36 | /* COM includes: */
|
---|
37 | #include "CMachine.h"
|
---|
38 |
|
---|
39 | /* Helper QMenu reimplementation which allows
|
---|
40 | * to highlight first menu item for popped up menu: */
|
---|
41 | class QIMenu : public QMenu
|
---|
42 | {
|
---|
43 | Q_OBJECT;
|
---|
44 |
|
---|
45 | public:
|
---|
46 |
|
---|
47 | QIMenu() : QMenu(0) {}
|
---|
48 |
|
---|
49 | private slots:
|
---|
50 |
|
---|
51 | void sltSelectFirstAction()
|
---|
52 | {
|
---|
53 | #ifdef Q_WS_WIN
|
---|
54 | activateWindow();
|
---|
55 | #endif
|
---|
56 | QMenu::focusNextChild();
|
---|
57 | }
|
---|
58 | };
|
---|
59 |
|
---|
60 | class UIMenuBar: public QMenuBar
|
---|
61 | {
|
---|
62 | public:
|
---|
63 |
|
---|
64 | UIMenuBar(QWidget *pParent = 0)
|
---|
65 | : QMenuBar(pParent)
|
---|
66 | , m_fShowBetaLabel(false)
|
---|
67 | {
|
---|
68 | /* Check for beta versions */
|
---|
69 | if (vboxGlobal().isBeta())
|
---|
70 | m_fShowBetaLabel = true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected:
|
---|
74 |
|
---|
75 | void paintEvent(QPaintEvent *pEvent)
|
---|
76 | {
|
---|
77 | QMenuBar::paintEvent(pEvent);
|
---|
78 | if (m_fShowBetaLabel)
|
---|
79 | {
|
---|
80 | QPixmap betaLabel;
|
---|
81 | const QString key("vbox:betaLabel");
|
---|
82 | if (!QPixmapCache::find(key, betaLabel))
|
---|
83 | {
|
---|
84 | betaLabel = ::betaLabel();
|
---|
85 | QPixmapCache::insert(key, betaLabel);
|
---|
86 | }
|
---|
87 | QSize s = size();
|
---|
88 | QPainter painter(this);
|
---|
89 | painter.setClipRect(pEvent->rect());
|
---|
90 | painter.drawPixmap(s.width() - betaLabel.width() - 10, (height() - betaLabel.height()) / 2, betaLabel);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | private:
|
---|
95 |
|
---|
96 | /* Private member vars */
|
---|
97 | bool m_fShowBetaLabel;
|
---|
98 | };
|
---|
99 |
|
---|
100 | UIMachineMenuBar::UIMachineMenuBar()
|
---|
101 | /* On the Mac we add some items only the first time, cause otherwise they
|
---|
102 | * will be merged more than once to the application menu by Qt. */
|
---|
103 | : m_fIsFirstTime(true)
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | QMenu* UIMachineMenuBar::createMenu(UIMainMenuType fOptions /* = UIMainMenuType_All */)
|
---|
108 | {
|
---|
109 | /* Create empty menu: */
|
---|
110 | QMenu *pMenu = new QIMenu;
|
---|
111 |
|
---|
112 | /* Fill menu with prepared items: */
|
---|
113 | foreach (QMenu *pSubMenu, prepareSubMenus(fOptions))
|
---|
114 | pMenu->addMenu(pSubMenu);
|
---|
115 |
|
---|
116 | /* Return filled menu: */
|
---|
117 | return pMenu;
|
---|
118 | }
|
---|
119 |
|
---|
120 | QMenuBar* UIMachineMenuBar::createMenuBar(UIMainMenuType fOptions /* = UIMainMenuType_All */)
|
---|
121 | {
|
---|
122 | /* Create empty menubar: */
|
---|
123 | QMenuBar *pMenuBar = new UIMenuBar;
|
---|
124 |
|
---|
125 | /* Fill menubar with prepared items: */
|
---|
126 | foreach (QMenu *pSubMenu, prepareSubMenus(fOptions))
|
---|
127 | pMenuBar->addMenu(pSubMenu);
|
---|
128 |
|
---|
129 | /* Return filled menubar: */
|
---|
130 | return pMenuBar;
|
---|
131 | }
|
---|
132 |
|
---|
133 | QList<QMenu*> UIMachineMenuBar::prepareSubMenus(UIMainMenuType fOptions /* = UIMainMenuType_All */)
|
---|
134 | {
|
---|
135 | /* Create empty submenu list: */
|
---|
136 | QList<QMenu*> preparedSubMenus;
|
---|
137 |
|
---|
138 | /* Machine submenu: */
|
---|
139 | if (fOptions & UIMainMenuType_Machine)
|
---|
140 | {
|
---|
141 | QMenu *pMenuMachine = gActionPool->action(UIActionIndexRuntime_Menu_Machine)->menu();
|
---|
142 | prepareMenuMachine(pMenuMachine);
|
---|
143 | preparedSubMenus << pMenuMachine;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /* View submenu: */
|
---|
147 | if (fOptions & UIMainMenuType_View)
|
---|
148 | {
|
---|
149 | QMenu *pMenuView = gActionPool->action(UIActionIndexRuntime_Menu_View)->menu();
|
---|
150 | prepareMenuView(pMenuView);
|
---|
151 | preparedSubMenus << pMenuView;
|
---|
152 | }
|
---|
153 |
|
---|
154 | /* Devices submenu: */
|
---|
155 | if (fOptions & UIMainMenuType_Devices)
|
---|
156 | {
|
---|
157 | QMenu *pMenuDevices = gActionPool->action(UIActionIndexRuntime_Menu_Devices)->menu();
|
---|
158 | prepareMenuDevices(pMenuDevices);
|
---|
159 | preparedSubMenus << pMenuDevices;
|
---|
160 | }
|
---|
161 |
|
---|
162 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
163 | /* Debug submenu: */
|
---|
164 | if (fOptions & UIMainMenuType_Debug)
|
---|
165 | {
|
---|
166 | CMachine machine; /** @todo we should try get the machine here. But we'll
|
---|
167 | * probably be fine with the cached values. */
|
---|
168 | if (vboxGlobal().isDebuggerEnabled(machine))
|
---|
169 | {
|
---|
170 | QMenu *pMenuDebug = gActionPool->action(UIActionIndexRuntime_Menu_Debug)->menu();
|
---|
171 | prepareMenuDebug(pMenuDebug);
|
---|
172 | preparedSubMenus << pMenuDebug;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | /* Help submenu: */
|
---|
178 | if (fOptions & UIMainMenuType_Help)
|
---|
179 | {
|
---|
180 | QMenu *pMenuHelp = gActionPool->action(UIActionIndex_Menu_Help)->menu();
|
---|
181 | prepareMenuHelp(pMenuHelp);
|
---|
182 | preparedSubMenus << pMenuHelp;
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* Return a list of prepared submenus: */
|
---|
186 | return preparedSubMenus;
|
---|
187 | }
|
---|
188 |
|
---|
189 | void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu)
|
---|
190 | {
|
---|
191 | /* Do not prepare if ready: */
|
---|
192 | if (!pMenu->isEmpty())
|
---|
193 | return;
|
---|
194 |
|
---|
195 | /* Machine submenu: */
|
---|
196 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SettingsDialog));
|
---|
197 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeSnapshot));
|
---|
198 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeScreenshot));
|
---|
199 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InformationDialog));
|
---|
200 | pMenu->addSeparator();
|
---|
201 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration));
|
---|
202 | pMenu->addSeparator();
|
---|
203 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCAD));
|
---|
204 | #ifdef Q_WS_X11
|
---|
205 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCABS));
|
---|
206 | #endif
|
---|
207 | pMenu->addSeparator();
|
---|
208 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Pause));
|
---|
209 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Reset));
|
---|
210 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Shutdown));
|
---|
211 | #ifndef Q_WS_MAC
|
---|
212 | pMenu->addSeparator();
|
---|
213 | #endif /* !Q_WS_MAC */
|
---|
214 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Close));
|
---|
215 | }
|
---|
216 |
|
---|
217 | void UIMachineMenuBar::prepareMenuView(QMenu *pMenu)
|
---|
218 | {
|
---|
219 | /* Do not prepare if ready: */
|
---|
220 | if (!pMenu->isEmpty())
|
---|
221 | return;
|
---|
222 |
|
---|
223 | /* View submenu: */
|
---|
224 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen));
|
---|
225 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless));
|
---|
226 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Scale));
|
---|
227 | pMenu->addSeparator();
|
---|
228 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize));
|
---|
229 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow));
|
---|
230 | }
|
---|
231 |
|
---|
232 | void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu)
|
---|
233 | {
|
---|
234 | /* Do not prepare if ready: */
|
---|
235 | if (!pMenu->isEmpty())
|
---|
236 | return;
|
---|
237 |
|
---|
238 | /* Devices submenu: */
|
---|
239 | pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices)->menu());
|
---|
240 | pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices)->menu());
|
---|
241 | pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu());
|
---|
242 | pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_SharedClipboard)->menu());
|
---|
243 | pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_DragAndDrop)->menu());
|
---|
244 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog));
|
---|
245 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog));
|
---|
246 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_VRDEServer));
|
---|
247 | pMenu->addSeparator();
|
---|
248 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InstallGuestTools));
|
---|
249 | }
|
---|
250 |
|
---|
251 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
252 | void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu)
|
---|
253 | {
|
---|
254 | /* Do not prepare if ready: */
|
---|
255 | if (!pMenu->isEmpty())
|
---|
256 | return;
|
---|
257 |
|
---|
258 | /* Debug submenu: */
|
---|
259 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Statistics));
|
---|
260 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_CommandLine));
|
---|
261 | pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Logging));
|
---|
262 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_LogDialog));
|
---|
263 | }
|
---|
264 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
265 |
|
---|
266 | void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu)
|
---|
267 | {
|
---|
268 | /* Do not prepare if ready: */
|
---|
269 | if (!pMenu->isEmpty())
|
---|
270 | return;
|
---|
271 |
|
---|
272 | /* Help submenu: */
|
---|
273 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Contents));
|
---|
274 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_WebSite));
|
---|
275 | pMenu->addSeparator();
|
---|
276 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_ResetWarnings));
|
---|
277 | pMenu->addSeparator();
|
---|
278 |
|
---|
279 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_NetworkAccessManager));
|
---|
280 |
|
---|
281 | #ifndef Q_WS_MAC
|
---|
282 | pMenu->addSeparator();
|
---|
283 | #endif /* !Q_WS_MAC */
|
---|
284 | #if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
|
---|
285 | if (m_fIsFirstTime)
|
---|
286 | # endif
|
---|
287 | pMenu->addAction(gActionPool->action(UIActionIndex_Simple_About));
|
---|
288 |
|
---|
289 | #if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
|
---|
290 | /* Because this connections are done to VBoxGlobal, they are needed once only.
|
---|
291 | * Otherwise we will get the slots called more than once. */
|
---|
292 | if (m_fIsFirstTime)
|
---|
293 | {
|
---|
294 | #endif
|
---|
295 | VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
|
---|
296 | &msgCenter(), SLOT(sltShowHelpAboutDialog()));
|
---|
297 | #if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
|
---|
298 | }
|
---|
299 | #endif
|
---|
300 |
|
---|
301 | VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Contents), SIGNAL(triggered()),
|
---|
302 | &msgCenter(), SLOT(sltShowHelpHelpDialog()));
|
---|
303 | VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_WebSite), SIGNAL(triggered()),
|
---|
304 | &msgCenter(), SLOT(sltShowHelpWebDialog()));
|
---|
305 | VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
|
---|
306 | &msgCenter(), SLOT(sltResetSuppressedMessages()));
|
---|
307 | VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_NetworkAccessManager), SIGNAL(triggered()),
|
---|
308 | gNetworkManager, SLOT(show()));
|
---|
309 |
|
---|
310 | m_fIsFirstTime = false;
|
---|
311 | }
|
---|
312 |
|
---|
313 | #include "UIMachineMenuBar.moc"
|
---|
314 |
|
---|