VirtualBox

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

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

FE/Qt: Rework new version notifier to be a part of new UIUpdateManager class. Implement Extension Pack updater (new version check + download + update).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/* $Id: UIMachineMenuBar.cpp 38476 2011-08-16 13:25: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#include "UIUpdateManager.h"
29
30/* Global includes */
31#include <QMenuBar>
32#include <QPainter>
33#include <QPaintEvent>
34#include <QPixmapCache>
35
36/* Helper QMenu reimplementation which allows
37 * to highlight first menu item for popped up menu: */
38class UIMenu : public QMenu
39{
40 Q_OBJECT;
41
42public:
43
44 UIMenu() : QMenu(0) {}
45
46private slots:
47
48 void sltSelectFirstAction()
49 {
50#ifdef Q_WS_WIN
51 activateWindow();
52#endif
53 QMenu::focusNextChild();
54 }
55};
56
57class UIMenuBar: public QMenuBar
58{
59public:
60
61 UIMenuBar(QWidget *pParent = 0)
62 : QMenuBar(pParent)
63 , m_fShowBetaLabel(false)
64 {
65 /* Check for beta versions */
66 if (vboxGlobal().isBeta())
67 m_fShowBetaLabel = true;
68 }
69
70protected:
71
72 void paintEvent(QPaintEvent *pEvent)
73 {
74 QMenuBar::paintEvent(pEvent);
75 if (m_fShowBetaLabel)
76 {
77 QPixmap betaLabel;
78 const QString key("vbox:betaLabel");
79 if (!QPixmapCache::find(key, betaLabel))
80 {
81 betaLabel = ::betaLabel();
82 QPixmapCache::insert(key, betaLabel);
83 }
84 QSize s = size();
85 QPainter painter(this);
86 painter.setClipRect(pEvent->rect());
87 painter.drawPixmap(s.width() - betaLabel.width() - 10, (height() - betaLabel.height()) / 2, betaLabel);
88 }
89 }
90
91private:
92
93 /* Private member vars */
94 bool m_fShowBetaLabel;
95};
96
97UIMachineMenuBar::UIMachineMenuBar()
98 /* On the Mac we add some items only the first time, cause otherwise they
99 * will be merged more than once to the application menu by Qt. */
100 : m_fIsFirstTime(true)
101{
102}
103
104QMenu* UIMachineMenuBar::createMenu(UIMainMenuType fOptions /* = UIMainMenuType_All */)
105{
106 /* Create empty menu: */
107 QMenu *pMenu = new UIMenu;
108
109 /* Fill menu with prepared items: */
110 foreach (QMenu *pSubMenu, prepareSubMenus(fOptions))
111 pMenu->addMenu(pSubMenu);
112
113 /* Return filled menu: */
114 return pMenu;
115}
116
117QMenuBar* UIMachineMenuBar::createMenuBar(UIMainMenuType fOptions /* = UIMainMenuType_All */)
118{
119 /* Create empty menubar: */
120 QMenuBar *pMenuBar = new UIMenuBar;
121
122 /* Fill menubar with prepared items: */
123 foreach (QMenu *pSubMenu, prepareSubMenus(fOptions))
124 pMenuBar->addMenu(pSubMenu);
125
126 /* Return filled menubar: */
127 return pMenuBar;
128}
129
130QList<QMenu*> UIMachineMenuBar::prepareSubMenus(UIMainMenuType fOptions /* = UIMainMenuType_All */)
131{
132 /* Create empty submenu list: */
133 QList<QMenu*> preparedSubMenus;
134
135 /* Machine submenu: */
136 if (fOptions & UIMainMenuType_Machine)
137 {
138 QMenu *pMenuMachine = gActionPool->action(UIActionIndexRuntime_Menu_Machine)->menu();
139 prepareMenuMachine(pMenuMachine);
140 preparedSubMenus << pMenuMachine;
141 }
142
143 /* View submenu: */
144 if (fOptions & UIMainMenuType_View)
145 {
146 QMenu *pMenuView = gActionPool->action(UIActionIndexRuntime_Menu_View)->menu();
147 prepareMenuView(pMenuView);
148 preparedSubMenus << pMenuView;
149 }
150
151 /* Devices submenu: */
152 if (fOptions & UIMainMenuType_Devices)
153 {
154 QMenu *pMenuDevices = gActionPool->action(UIActionIndexRuntime_Menu_Devices)->menu();
155 prepareMenuDevices(pMenuDevices);
156 preparedSubMenus << pMenuDevices;
157 }
158
159#ifdef VBOX_WITH_DEBUGGER_GUI
160 /* Debug submenu: */
161 if (fOptions & UIMainMenuType_Debug)
162 {
163 CMachine machine; /** @todo we should try get the machine here. But we'll
164 * probably be fine with the cached values. */
165 if (vboxGlobal().isDebuggerEnabled(machine))
166 {
167 QMenu *pMenuDebug = gActionPool->action(UIActionIndexRuntime_Menu_Debug)->menu();
168 prepareMenuDebug(pMenuDebug);
169 preparedSubMenus << pMenuDebug;
170 }
171 }
172#endif
173
174 /* Help submenu: */
175 if (fOptions & UIMainMenuType_Help)
176 {
177 QMenu *pMenuHelp = gActionPool->action(UIActionIndex_Menu_Help)->menu();
178 prepareMenuHelp(pMenuHelp);
179 preparedSubMenus << pMenuHelp;
180 }
181
182 /* Return a list of prepared submenus: */
183 return preparedSubMenus;
184}
185
186void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu)
187{
188 /* Do not prepare if ready: */
189 if (!pMenu->isEmpty())
190 return;
191
192 /* Machine submenu: */
193 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SettingsDialog));
194 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeSnapshot));
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#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
277 if (m_fIsFirstTime)
278# endif
279 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Update));
280#ifndef Q_WS_MAC
281 pMenu->addSeparator();
282#endif /* !Q_WS_MAC */
283#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
284 if (m_fIsFirstTime)
285# endif
286 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_About));
287
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 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
298 gUpdateManager, SLOT(sltForceCheck()));
299#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
300 }
301#endif
302
303 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
304 &msgCenter(), SLOT(sltShowHelpHelpDialog()));
305 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
306 &msgCenter(), SLOT(sltShowHelpWebDialog()));
307 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
308 &msgCenter(), SLOT(sltResetSuppressedMessages()));
309#ifdef VBOX_WITH_REGISTRATION
310 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
311 &vboxGlobal(), SLOT(showRegistrationDialog()));
312 VBoxGlobal::connect(gEDataEvents, SIGNAL(sigCanShowRegistrationDlg(bool)),
313 gActionPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
314#endif /* VBOX_WITH_REGISTRATION */
315
316 m_fIsFirstTime = false;
317}
318
319#include "UIMachineMenuBar.moc"
320
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