VirtualBox

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

Last change on this file since 36083 was 36083, checked in by vboxsync, 14 years ago

FE/Qt: 5410: Add View menu: Initial commit.

  • 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 36083 2011-02-25 12:33:58Z 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 "UIActionsPool.h"
24#include "VBoxGlobal.h"
25#include "VBoxProblemReporter.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(UIActionsPool *pActionsPool, 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(pActionsPool, fOptions))
110 pMenu->addMenu(pSubMenu);
111
112 /* Return filled menu: */
113 return pMenu;
114}
115
116QMenuBar* UIMachineMenuBar::createMenuBar(UIActionsPool *pActionsPool, 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(pActionsPool, fOptions))
123 pMenuBar->addMenu(pSubMenu);
124
125 /* Return filled menubar: */
126 return pMenuBar;
127}
128
129QList<QMenu*> UIMachineMenuBar::prepareSubMenus(UIActionsPool *pActionsPool, 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 = pActionsPool->action(UIActionIndex_Menu_Machine)->menu();
138 prepareMenuMachine(pMenuMachine, pActionsPool);
139 preparedSubMenus << pMenuMachine;
140 }
141
142 /* View submenu: */
143 if (fOptions & UIMainMenuType_View)
144 {
145 QMenu *pMenuView = pActionsPool->action(UIActionIndex_Menu_View)->menu();
146 prepareMenuView(pMenuView, pActionsPool);
147 preparedSubMenus << pMenuView;
148 }
149
150 /* Devices submenu: */
151 if (fOptions & UIMainMenuType_Devices)
152 {
153 QMenu *pMenuDevices = pActionsPool->action(UIActionIndex_Menu_Devices)->menu();
154 prepareMenuDevices(pMenuDevices, pActionsPool);
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 = pActionsPool->action(UIActionIndex_Menu_Debug)->menu();
167 prepareMenuDebug(pMenuDebug, pActionsPool);
168 preparedSubMenus << pMenuDebug;
169 }
170 }
171#endif
172
173 /* Help submenu: */
174 if (fOptions & UIMainMenuType_Help)
175 {
176 QMenu *pMenuHelp = pActionsPool->action(UIActionIndex_Menu_Help)->menu();
177 prepareMenuHelp(pMenuHelp, pActionsPool);
178 preparedSubMenus << pMenuHelp;
179 }
180
181 /* Return a list of prepared submenus: */
182 return preparedSubMenus;
183}
184
185void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu, UIActionsPool *pActionsPool)
186{
187 /* Do not prepare if ready: */
188 if (!pMenu->isEmpty())
189 return;
190
191 /* Machine submenu: */
192 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TakeSnapshot));
193 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InformationDialog));
194 pMenu->addSeparator();
195 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_MouseIntegration));
196 pMenu->addSeparator();
197 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCAD));
198#ifdef Q_WS_X11
199 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCABS));
200#endif
201 pMenu->addSeparator();
202 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Pause));
203 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Reset));
204 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Shutdown));
205#ifndef Q_WS_MAC
206 pMenu->addSeparator();
207#endif /* !Q_WS_MAC */
208 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Close));
209}
210
211void UIMachineMenuBar::prepareMenuView(QMenu *pMenu, UIActionsPool *pActionsPool)
212{
213 /* Do not prepare if ready: */
214 if (!pMenu->isEmpty())
215 return;
216
217 /* View submenu: */
218 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Fullscreen));
219 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Seamless));
220 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Scale));
221 pMenu->addSeparator();
222 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_GuestAutoresize));
223 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_AdjustWindow));
224}
225
226void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu, UIActionsPool *pActionsPool)
227{
228 /* Do not prepare if ready: */
229 if (!pMenu->isEmpty())
230 return;
231
232 /* Devices submenu: */
233 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_OpticalDevices)->menu());
234 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_FloppyDevices)->menu());
235 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_USBDevices)->menu());
236 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_NetworkAdaptersDialog));
237 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_SharedFoldersDialog));
238 pMenu->addSeparator();
239 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_VRDEServer));
240 pMenu->addSeparator();
241 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InstallGuestTools));
242}
243
244#ifdef VBOX_WITH_DEBUGGER_GUI
245void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu, UIActionsPool *pActionsPool)
246{
247 /* Do not prepare if ready: */
248 if (!pMenu->isEmpty())
249 return;
250
251 /* Debug submenu: */
252 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Statistics));
253 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_CommandLine));
254 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Logging));
255}
256#endif /* VBOX_WITH_DEBUGGER_GUI */
257
258void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu, UIActionsPool *pActionsPool)
259{
260 /* Do not prepare if ready: */
261 if (!pMenu->isEmpty())
262 return;
263
264 /* Help submenu: */
265 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Help));
266 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Web));
267 pMenu->addSeparator();
268 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_ResetWarnings));
269 pMenu->addSeparator();
270
271#ifdef VBOX_WITH_REGISTRATION
272 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Register));
273#endif
274
275#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
276 if (m_fIsFirstTime)
277# endif
278 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Update));
279#ifndef Q_WS_MAC
280 pMenu->addSeparator();
281#endif /* !Q_WS_MAC */
282#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
283 if (m_fIsFirstTime)
284# endif
285 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_About));
286
287
288#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
289 /* Because this connections are done to VBoxGlobal, they are needed once only.
290 * Otherwise we will get the slots called more than once. */
291 if (m_fIsFirstTime)
292 {
293#endif
294 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
295 &vboxProblem(), SLOT(showHelpAboutDialog()));
296 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
297 &vboxGlobal(), SLOT(showUpdateDialog()));
298#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
299 }
300#endif
301
302 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
303 &vboxProblem(), SLOT(showHelpHelpDialog()));
304 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
305 &vboxProblem(), SLOT(showHelpWebDialog()));
306 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
307 &vboxProblem(), SLOT(resetSuppressedMessages()));
308#ifdef VBOX_WITH_REGISTRATION
309 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
310 &vboxGlobal(), SLOT(showRegistrationDialog()));
311 VBoxGlobal::connect(gEDataEvents, SIGNAL(sigCanShowRegistrationDlg(bool)),
312 pActionsPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
313#endif /* VBOX_WITH_REGISTRATION */
314
315 m_fIsFirstTime = false;
316}
317
318#include "UIMachineMenuBar.moc"
319
Note: See TracBrowser for help on using the repository browser.

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