VirtualBox

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

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

FE/Qt4: change the layout of the beta label and add it to the VM window

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 KB
Line 
1/* $Id: UIMachineMenuBar.cpp 35424 2011-01-07 13:05:41Z 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 preparedSubMenus << pMenuView;
147 }
148
149 /* Devices submenu: */
150 if (fOptions & UIMainMenuType_Devices)
151 {
152 QMenu *pMenuDevices = pActionsPool->action(UIActionIndex_Menu_Devices)->menu();
153 prepareMenuDevices(pMenuDevices, pActionsPool);
154 preparedSubMenus << pMenuDevices;
155 }
156
157#ifdef VBOX_WITH_DEBUGGER_GUI
158 /* Debug submenu: */
159 if (fOptions & UIMainMenuType_Debug)
160 {
161 CMachine machine; /** @todo we should try get the machine here. But we'll
162 * probably be fine with the cached values. */
163 if (vboxGlobal().isDebuggerEnabled(machine))
164 {
165 QMenu *pMenuDebug = pActionsPool->action(UIActionIndex_Menu_Debug)->menu();
166 prepareMenuDebug(pMenuDebug, pActionsPool);
167 preparedSubMenus << pMenuDebug;
168 }
169 }
170#endif
171
172 /* Help submenu: */
173 if (fOptions & UIMainMenuType_Help)
174 {
175 QMenu *pMenuHelp = pActionsPool->action(UIActionIndex_Menu_Help)->menu();
176 prepareMenuHelp(pMenuHelp, pActionsPool);
177 preparedSubMenus << pMenuHelp;
178 }
179
180 /* Return a list of prepared submenus: */
181 return preparedSubMenus;
182}
183
184void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu, UIActionsPool *pActionsPool)
185{
186 /* Do not prepare if ready: */
187 if (!pMenu->isEmpty())
188 return;
189
190 /* Machine submenu: */
191 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Fullscreen));
192 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Seamless));
193 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Scale));
194 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_GuestAutoresize));
195 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_AdjustWindow));
196 pMenu->addSeparator();
197 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_MouseIntegration));
198 pMenu->addSeparator();
199 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCAD));
200#ifdef Q_WS_X11
201 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCABS));
202#endif
203 pMenu->addSeparator();
204 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TakeSnapshot));
205 pMenu->addSeparator();
206 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InformationDialog));
207 pMenu->addSeparator();
208 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Pause));
209 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Reset));
210 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Shutdown));
211#ifndef Q_WS_MAC
212 pMenu->addSeparator();
213#endif /* !Q_WS_MAC */
214 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Close));
215}
216
217void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu, UIActionsPool *pActionsPool)
218{
219 /* Do not prepare if ready: */
220 if (!pMenu->isEmpty())
221 return;
222
223 /* Devices submenu: */
224 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_OpticalDevices)->menu());
225 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_FloppyDevices)->menu());
226 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_USBDevices)->menu());
227 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_NetworkAdaptersDialog));
228 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_SharedFoldersDialog));
229 pMenu->addSeparator();
230 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_VRDEServer));
231 pMenu->addSeparator();
232 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InstallGuestTools));
233}
234
235#ifdef VBOX_WITH_DEBUGGER_GUI
236void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu, UIActionsPool *pActionsPool)
237{
238 /* Do not prepare if ready: */
239 if (!pMenu->isEmpty())
240 return;
241
242 /* Debug submenu: */
243 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Statistics));
244 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_CommandLine));
245 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Logging));
246}
247#endif /* VBOX_WITH_DEBUGGER_GUI */
248
249void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu, UIActionsPool *pActionsPool)
250{
251 /* Do not prepare if ready: */
252 if (!pMenu->isEmpty())
253 return;
254
255 /* Help submenu: */
256 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Help));
257 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Web));
258 pMenu->addSeparator();
259 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_ResetWarnings));
260 pMenu->addSeparator();
261
262#ifdef VBOX_WITH_REGISTRATION
263 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Register));
264#endif
265
266#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
267 if (m_fIsFirstTime)
268# endif
269 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Update));
270#ifndef Q_WS_MAC
271 pMenu->addSeparator();
272#endif /* !Q_WS_MAC */
273#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
274 if (m_fIsFirstTime)
275# endif
276 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_About));
277
278
279#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
280 /* Because this connections are done to VBoxGlobal, they are needed once only.
281 * Otherwise we will get the slots called more than once. */
282 if (m_fIsFirstTime)
283 {
284#endif
285 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
286 &vboxProblem(), SLOT(showHelpAboutDialog()));
287 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
288 &vboxGlobal(), SLOT(showUpdateDialog()));
289#if defined(Q_WS_MAC) && (QT_VERSION < 0x040700)
290 }
291#endif
292
293 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
294 &vboxProblem(), SLOT(showHelpHelpDialog()));
295 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
296 &vboxProblem(), SLOT(showHelpWebDialog()));
297 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
298 &vboxProblem(), SLOT(resetSuppressedMessages()));
299#ifdef VBOX_WITH_REGISTRATION
300 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
301 &vboxGlobal(), SLOT(showRegistrationDialog()));
302 VBoxGlobal::connect(gEDataEvents, SIGNAL(sigCanShowRegistrationDlg(bool)),
303 pActionsPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
304#endif /* VBOX_WITH_REGISTRATION */
305
306 m_fIsFirstTime = false;
307}
308
309#include "UIMachineMenuBar.moc"
310
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use