VirtualBox

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

Last change on this file since 49466 was 49466, checked in by vboxsync, 11 years ago

FE/Qt: Runtime UI: Close actions handling rework (step 2): Make sure menu/menubar Application Close action is disabled if SaveState, Shutdown and PowerOff close actions are restricted.

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