VirtualBox

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

Last change on this file since 39326 was 39326, checked in by vboxsync, 13 years ago

FE/Qt: Network/Update managers: Disable check-for-new-version function for VM window; Centralize signals for downloader embedding in Network manager.

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