VirtualBox

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

Last change on this file since 28457 was 28457, checked in by vboxsync, 15 years ago

FE/Qt: New running VM core menubar fixes: 1. Normal mode menubar now works properly under win host; 2. Fullscreen/Seamless modes menubar now highlights first menu item (as in old core).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: UIMachineMenuBar.cpp 28457 2010-04-19 12:36:06Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UIMachineMenuBar class implementation
6 */
7
8/*
9 * Copyright (C) 2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24/* Local includes */
25#include "UIMachineMenuBar.h"
26#include "UISession.h"
27#include "UIActionsPool.h"
28#include "VBoxGlobal.h"
29#include "VBoxProblemReporter.h"
30
31/* Global includes */
32#include <QMenuBar>
33
34/* Helper QMenu reimplementation which allows
35 * to highlight first menu item for popped up menu: */
36class UIMenu : public QMenu
37{
38 Q_OBJECT;
39
40public:
41
42 UIMenu() : QMenu(0) {}
43
44private slots:
45
46 void sltSelectFirstAction()
47 {
48#ifdef Q_WS_WIN
49 activateWindow();
50#endif
51 QMenu::focusNextChild();
52 }
53};
54
55UIMachineMenuBar::UIMachineMenuBar()
56 /* On the Mac we add some items only the first time, cause otherwise they
57 * will be merged more than once to the application menu by Qt. */
58 : m_fIsFirstTime(true)
59{
60}
61
62QMenu* UIMachineMenuBar::createMenu(UIActionsPool *pActionsPool, UIMainMenuType fOptions /* = UIMainMenuType_All */)
63{
64 /* Create empty menu: */
65 QMenu *pMenu = new UIMenu;
66
67 /* Fill menu with prepared items: */
68 foreach (QMenu *pSubMenu, prepareSubMenus(pActionsPool, fOptions))
69 pMenu->addMenu(pSubMenu);
70
71 /* Return filled menu: */
72 return pMenu;
73}
74
75QMenuBar* UIMachineMenuBar::createMenuBar(UIActionsPool *pActionsPool, UIMainMenuType fOptions /* = UIMainMenuType_All */)
76{
77 /* Create empty menubar: */
78 QMenuBar *pMenuBar = new QMenuBar;
79
80 /* Fill menubar with prepared items: */
81 foreach (QMenu *pSubMenu, prepareSubMenus(pActionsPool, fOptions))
82 pMenuBar->addMenu(pSubMenu);
83
84 /* Return filled menubar: */
85 return pMenuBar;
86}
87
88QList<QMenu*> UIMachineMenuBar::prepareSubMenus(UIActionsPool *pActionsPool, UIMainMenuType fOptions /* = UIMainMenuType_All */)
89{
90 /* Create empty submenu list: */
91 QList<QMenu*> preparedSubMenus;
92
93 /* Machine submenu: */
94 if (fOptions & UIMainMenuType_Machine)
95 {
96 QMenu *pMenuMachine = pActionsPool->action(UIActionIndex_Menu_Machine)->menu();
97 prepareMenuMachine(pMenuMachine, pActionsPool);
98 preparedSubMenus << pMenuMachine;
99 }
100
101 /* View submenu: */
102 if (fOptions & UIMainMenuType_View)
103 {
104 QMenu *pMenuView = pActionsPool->action(UIActionIndex_Menu_View)->menu();
105 preparedSubMenus << pMenuView;
106 }
107
108 /* Devices submenu: */
109 if (fOptions & UIMainMenuType_Devices)
110 {
111 QMenu *pMenuDevices = pActionsPool->action(UIActionIndex_Menu_Devices)->menu();
112 prepareMenuDevices(pMenuDevices, pActionsPool);
113 preparedSubMenus << pMenuDevices;
114 }
115
116#ifdef VBOX_WITH_DEBUGGER_GUI
117 /* Debug submenu: */
118 if ( fOptions & UIMainMenuType_Debug
119 && vboxGlobal().isDebuggerEnabled())
120 {
121 QMenu *pMenuDebug = pActionsPool->action(UIActionIndex_Menu_Debug)->menu();
122 prepareMenuDebug(pMenuDebug, pActionsPool);
123 preparedSubMenus << pMenuDebug;
124 }
125#endif
126
127 /* Help submenu: */
128 if (fOptions & UIMainMenuType_Help)
129 {
130 QMenu *pMenuHelp = pActionsPool->action(UIActionIndex_Menu_Help)->menu();
131 prepareMenuHelp(pMenuHelp, pActionsPool);
132 preparedSubMenus << pMenuHelp;
133 }
134
135 /* Return a list of prepared submenus: */
136 return preparedSubMenus;
137}
138
139void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu, UIActionsPool *pActionsPool)
140{
141 /* Do not prepare if ready: */
142 if (!pMenu->isEmpty())
143 return;
144
145 /* Machine submenu: */
146 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Fullscreen));
147 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Seamless));
148 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_GuestAutoresize));
149 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_AdjustWindow));
150 pMenu->addSeparator();
151 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_MouseIntegration));
152 pMenu->addSeparator();
153 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCAD));
154#ifdef Q_WS_X11
155 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCABS));
156#endif
157 pMenu->addSeparator();
158 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TakeSnapshot));
159 pMenu->addSeparator();
160 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InformationDialog));
161 pMenu->addSeparator();
162 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Pause));
163 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Reset));
164 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Shutdown));
165#ifndef Q_WS_MAC
166 pMenu->addSeparator();
167#else /* Q_WS_MAC */
168 if (m_fIsFirstTime)
169#endif /* !Q_WS_MAC */
170 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Close));
171}
172
173void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu, UIActionsPool *pActionsPool)
174{
175 /* Do not prepare if ready: */
176 if (!pMenu->isEmpty())
177 return;
178
179 /* Devices submenu: */
180 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_OpticalDevices)->menu());
181 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_FloppyDevices)->menu());
182 pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_USBDevices)->menu());
183 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_NetworkAdaptersDialog));
184 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_SharedFoldersDialog));
185 pMenu->addSeparator();
186 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_VRDP));
187 pMenu->addSeparator();
188 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InstallGuestTools));
189}
190
191#ifdef VBOX_WITH_DEBUGGER_GUI
192void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu, UIActionsPool *pActionsPool)
193{
194 /* Do not prepare if ready: */
195 if (!pMenu->isEmpty())
196 return;
197
198 /* Debug submenu: */
199 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Statistics));
200 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_CommandLine));
201 pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Logging));
202}
203#endif /* VBOX_WITH_DEBUGGER_GUI */
204
205void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu, UIActionsPool *pActionsPool)
206{
207 /* Do not prepare if ready: */
208 if (!pMenu->isEmpty())
209 return;
210
211 /* Help submenu: */
212 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Help));
213 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Web));
214 pMenu->addSeparator();
215 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_ResetWarnings));
216 pMenu->addSeparator();
217
218#ifdef VBOX_WITH_REGISTRATION
219 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Register));
220#endif
221
222#ifdef Q_WS_MAC
223 if (m_fIsFirstTime)
224#endif /* Q_WS_MAC */
225 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Update));
226
227#ifndef Q_WS_MAC
228 pMenu->addSeparator();
229#else /* Q_WS_MAC */
230 if (m_fIsFirstTime)
231#endif /* !Q_WS_MAC */
232 pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_About));
233
234 /* Because this connections are done to VBoxGlobal, they are needed once only.
235 * Otherwise we will get the slots called more than once. */
236 if (m_fIsFirstTime)
237 {
238 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
239 &vboxProblem(), SLOT(showHelpHelpDialog()));
240 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
241 &vboxProblem(), SLOT(showHelpWebDialog()));
242 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
243 &vboxProblem(), SLOT(resetSuppressedMessages()));
244#ifdef VBOX_WITH_REGISTRATION
245 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
246 &vboxGlobal(), SLOT(showRegistrationDialog()));
247#endif /* VBOX_WITH_REGISTRATION */
248 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
249 &vboxGlobal(), SLOT(showUpdateDialog()));
250 VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
251 &vboxProblem(), SLOT(showHelpAboutDialog()));
252
253#ifdef VBOX_WITH_REGISTRATION
254 VBoxGlobal::connect(&vboxGlobal(), SIGNAL (canShowRegDlg (bool)),
255 pActionsPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
256#endif /* VBOX_WITH_REGISTRATION */
257 VBoxGlobal::connect(&vboxGlobal(), SIGNAL (canShowUpdDlg (bool)),
258 pActionsPool->action(UIActionIndex_Simple_Update), SLOT(setEnabled(bool)));
259
260 m_fIsFirstTime = false;
261 }
262}
263
264#include "UIMachineMenuBar.moc"
265
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