VirtualBox

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

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

FE/Qt4: add screenshot functionality to the GUI

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/* $Id: UIMachineMenuBar.cpp 38477 2011-08-16 13:46:03Z 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_TakeScreenshot));
196 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InformationDialog));
197 pMenu->addSeparator();
198 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration));
199 pMenu->addSeparator();
200 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCAD));
201#ifdef Q_WS_X11
202 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCABS));
203#endif
204 pMenu->addSeparator();
205 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Pause));
206 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Reset));
207 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Shutdown));
208#ifndef Q_WS_MAC
209 pMenu->addSeparator();
210#endif /* !Q_WS_MAC */
211 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Close));
212}
213
214void UIMachineMenuBar::prepareMenuView(QMenu *pMenu)
215{
216 /* Do not prepare if ready: */
217 if (!pMenu->isEmpty())
218 return;
219
220 /* View submenu: */
221 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen));
222 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless));
223 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Scale));
224 pMenu->addSeparator();
225 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize));
226 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow));
227}
228
229void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu)
230{
231 /* Do not prepare if ready: */
232 if (!pMenu->isEmpty())
233 return;
234
235 /* Devices submenu: */
236 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices)->menu());
237 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices)->menu());
238 pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu());
239 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog));
240 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog));
241 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_VRDEServer));
242 pMenu->addSeparator();
243 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InstallGuestTools));
244}
245
246#ifdef VBOX_WITH_DEBUGGER_GUI
247void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu)
248{
249 /* Do not prepare if ready: */
250 if (!pMenu->isEmpty())
251 return;
252
253 /* Debug submenu: */
254 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Statistics));
255 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Simple_CommandLine));
256 pMenu->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Logging));
257}
258#endif /* VBOX_WITH_DEBUGGER_GUI */
259
260void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu)
261{
262 /* Do not prepare if ready: */
263 if (!pMenu->isEmpty())
264 return;
265
266 /* Help submenu: */
267 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Help));
268 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Web));
269 pMenu->addSeparator();
270 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_ResetWarnings));
271 pMenu->addSeparator();
272
273#ifdef VBOX_WITH_REGISTRATION
274 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Register));
275#endif
276
277#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
278 if (m_fIsFirstTime)
279# endif
280 pMenu->addAction(gActionPool->action(UIActionIndex_Simple_Update));
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
290#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
291 /* Because this connections are done to VBoxGlobal, they are needed once only.
292 * Otherwise we will get the slots called more than once. */
293 if (m_fIsFirstTime)
294 {
295#endif
296 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
297 &msgCenter(), SLOT(sltShowHelpAboutDialog()));
298 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
299 gUpdateManager, SLOT(sltForceCheck()));
300#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
301 }
302#endif
303
304 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
305 &msgCenter(), SLOT(sltShowHelpHelpDialog()));
306 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
307 &msgCenter(), SLOT(sltShowHelpWebDialog()));
308 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
309 &msgCenter(), SLOT(sltResetSuppressedMessages()));
310#ifdef VBOX_WITH_REGISTRATION
311 VBoxGlobal::connect(gActionPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
312 &vboxGlobal(), SLOT(showRegistrationDialog()));
313 VBoxGlobal::connect(gEDataEvents, SIGNAL(sigCanShowRegistrationDlg(bool)),
314 gActionPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
315#endif /* VBOX_WITH_REGISTRATION */
316
317 m_fIsFirstTime = false;
318}
319
320#include "UIMachineMenuBar.moc"
321
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