VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineMenuBar.cpp@ 45736

Last change on this file since 45736 was 45736, checked in by vboxsync, 12 years ago

FE/Qt: Added 'save-state' and 'power-off' Runtime UI actions; Added a possibility to predefine close-action through the extra-data 'GUI/DefaultCloseAction' string flag; Performed a lot of related functionality cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/* $Id: UIMachineMenuBar.cpp 45736 2013-04-25 15:59:59Z 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: */
41class QIMenu : public QMenu
42{
43 Q_OBJECT;
44
45public:
46
47 QIMenu() : QMenu(0) {}
48
49private slots:
50
51 void sltSelectFirstAction()
52 {
53#ifdef Q_WS_WIN
54 activateWindow();
55#endif
56 QMenu::focusNextChild();
57 }
58};
59
60class UIMenuBar: public QMenuBar
61{
62public:
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
73protected:
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
94private:
95
96 /* Private member vars */
97 bool m_fShowBetaLabel;
98};
99
100UIMachineMenuBar::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
107QMenu* 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
120QMenuBar* 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
133QList<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
189void 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_Save));
211 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Shutdown));
212 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_PowerOff));
213#ifndef Q_WS_MAC
214 pMenu->addSeparator();
215#endif /* !Q_WS_MAC */
216 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Close));
217}
218
219void UIMachineMenuBar::prepareMenuView(QMenu *pMenu)
220{
221 /* Do not prepare if ready: */
222 if (!pMenu->isEmpty())
223 return;
224
225 /* View submenu: */
226 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen));
227 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless));
228 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Scale));
229 pMenu->addSeparator();
230 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize));
231 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow));
232}
233
234void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu)
235{
236 /* Do not prepare if ready: */
237 if (!pMenu->isEmpty())
238 return;
239
240 /* Devices submenu: */
241 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices)->menu());
242 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices)->menu());
243 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu());
244 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_SharedClipboard)->menu());
245 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_DragAndDrop)->menu());
246 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog));
247 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog));
248 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_VRDEServer));
249 pMenu->addSeparator();
250 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InstallGuestTools));
251}
252
253#ifdef VBOX_WITH_DEBUGGER_GUI
254void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu)
255{
256 /* Do not prepare if ready: */
257 if (!pMenu->isEmpty())
258 return;
259
260 /* Debug submenu: */
261 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Statistics));
262 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_CommandLine));
263 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Logging));
264 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_LogDialog));
265}
266#endif /* VBOX_WITH_DEBUGGER_GUI */
267
268void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu)
269{
270 /* Do not prepare if ready: */
271 if (!pMenu->isEmpty())
272 return;
273
274 /* Help submenu: */
275 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Contents));
276 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_WebSite));
277 pMenu->addSeparator();
278 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_ResetWarnings));
279 pMenu->addSeparator();
280
281 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_NetworkAccessManager));
282
283#ifndef Q_WS_MAC
284 pMenu->addSeparator();
285#endif /* !Q_WS_MAC */
286#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
287 if (m_fIsFirstTime)
288# endif
289 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_About));
290
291#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
292 /* Because this connections are done to VBoxGlobal, they are needed once only.
293 * Otherwise we will get the slots called more than once. */
294 if (m_fIsFirstTime)
295 {
296#endif
297 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
298 &msgCenter(), SLOT(sltShowHelpAboutDialog()));
299#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
300 }
301#endif
302
303 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Contents), SIGNAL(triggered()),
304 &msgCenter(), SLOT(sltShowHelpHelpDialog()));
305 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_WebSite), SIGNAL(triggered()),
306 &msgCenter(), SLOT(sltShowHelpWebDialog()));
307 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
308 &msgCenter(), SLOT(sltResetSuppressedMessages()));
309 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_NetworkAccessManager), SIGNAL(triggered()),
310 gNetworkManager, SLOT(show()));
311
312 m_fIsFirstTime = false;
313}
314
315#include "UIMachineMenuBar.moc"
316
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette