1 | /* $Id: UIMachineWindowFullscreen.cpp 27662 2010-03-24 11:11:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineWindowFullscreen 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 | /* Global includes */
|
---|
25 | #include <QDesktopWidget>
|
---|
26 | #ifdef Q_WS_MAC
|
---|
27 | # include <QMenuBar>
|
---|
28 | #endif /* Q_WS_MAC */
|
---|
29 |
|
---|
30 | /* Local includes */
|
---|
31 | #include "VBoxGlobal.h"
|
---|
32 | #include "VBoxMiniToolBar.h"
|
---|
33 |
|
---|
34 | #include "UIActionsPool.h"
|
---|
35 | #include "UIMachineLogic.h"
|
---|
36 | #include "UIMachineLogicFullscreen.h"
|
---|
37 | #include "UIMachineView.h"
|
---|
38 | #include "UIMachineWindowFullscreen.h"
|
---|
39 | #include "UISession.h"
|
---|
40 |
|
---|
41 | UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
|
---|
42 | : QIWithRetranslateUI2<QMainWindow>(0, Qt::FramelessWindowHint)
|
---|
43 | , UIMachineWindow(pMachineLogic, uScreenId)
|
---|
44 | , m_pMainMenu(0)
|
---|
45 | , m_pMiniToolBar(0)
|
---|
46 | {
|
---|
47 | /* "This" is machine window: */
|
---|
48 | m_pMachineWindow = this;
|
---|
49 |
|
---|
50 | /* Set the main window in VBoxGlobal: */
|
---|
51 | if (uScreenId == 0)
|
---|
52 | vboxGlobal().setMainWindow(this);
|
---|
53 |
|
---|
54 | /* Prepare fullscreen window icon: */
|
---|
55 | prepareWindowIcon();
|
---|
56 |
|
---|
57 | /* Prepare console connections: */
|
---|
58 | prepareConsoleConnections();
|
---|
59 |
|
---|
60 | /* Prepare fullscreen menu: */
|
---|
61 | prepareMenu();
|
---|
62 |
|
---|
63 | /* Prepare machine view container: */
|
---|
64 | prepareMachineViewContainer();
|
---|
65 |
|
---|
66 | /* Prepare fullscreen machine view: */
|
---|
67 | prepareMachineView();
|
---|
68 |
|
---|
69 | /* Prepare mini tool-bar: */
|
---|
70 | prepareMiniToolBar();
|
---|
71 |
|
---|
72 | /* Retranslate fullscreen window finally: */
|
---|
73 | retranslateUi();
|
---|
74 |
|
---|
75 | /* Update all the elements: */
|
---|
76 | updateAppearanceOf(UIVisualElement_AllStuff);
|
---|
77 |
|
---|
78 | /* Make sure the window is placed on valid screen
|
---|
79 | * before we are show fullscreen window: */
|
---|
80 | sltPlaceOnScreen();
|
---|
81 |
|
---|
82 | /* Show fullscreen window: */
|
---|
83 | showFullScreen();
|
---|
84 |
|
---|
85 | /* Make sure the window is placed on valid screen again
|
---|
86 | * after window is shown & window's decorations applied.
|
---|
87 | * That is required due to X11 Window Geometry Rules. */
|
---|
88 | sltPlaceOnScreen();
|
---|
89 |
|
---|
90 | #ifdef Q_WS_MAC
|
---|
91 | /* Make sure it is really on the right place (especially on the Mac) */
|
---|
92 | QRect r = QApplication::desktop()->screenGeometry(static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));
|
---|
93 | move(r.topLeft());
|
---|
94 | #endif /* Q_WS_MAC */
|
---|
95 | }
|
---|
96 |
|
---|
97 | UIMachineWindowFullscreen::~UIMachineWindowFullscreen()
|
---|
98 | {
|
---|
99 | /* Save window settings: */
|
---|
100 | saveWindowSettings();
|
---|
101 |
|
---|
102 | /* Cleanup machine view: */
|
---|
103 | cleanupMachineView();
|
---|
104 |
|
---|
105 | /* Cleanup menu: */
|
---|
106 | cleanupMenu();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void UIMachineWindowFullscreen::sltPlaceOnScreen()
|
---|
110 | {
|
---|
111 | /* Get corresponding screen: */
|
---|
112 | int iScreen = static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
|
---|
113 | /* Calculate working area: */
|
---|
114 | QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
|
---|
115 | /* Move to the appropriate position: */
|
---|
116 | move(workingArea.topLeft());
|
---|
117 | /* Resize to the appropriate size: */
|
---|
118 | resize(workingArea.size());
|
---|
119 | /* Process pending move & resize events: */
|
---|
120 | qApp->processEvents();
|
---|
121 | }
|
---|
122 |
|
---|
123 | void UIMachineWindowFullscreen::sltMachineStateChanged()
|
---|
124 | {
|
---|
125 | UIMachineWindow::sltMachineStateChanged();
|
---|
126 | }
|
---|
127 |
|
---|
128 | void UIMachineWindowFullscreen::sltPopupMainMenu()
|
---|
129 | {
|
---|
130 | /* Popup main menu if present: */
|
---|
131 | if (m_pMainMenu && !m_pMainMenu->isEmpty())
|
---|
132 | m_pMainMenu->popup(machineWindow()->geometry().center());
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UIMachineWindowFullscreen::sltTryClose()
|
---|
136 | {
|
---|
137 | UIMachineWindow::sltTryClose();
|
---|
138 | }
|
---|
139 |
|
---|
140 | void UIMachineWindowFullscreen::retranslateUi()
|
---|
141 | {
|
---|
142 | /* Translate parent class: */
|
---|
143 | UIMachineWindow::retranslateUi();
|
---|
144 | }
|
---|
145 |
|
---|
146 | #ifdef Q_WS_X11
|
---|
147 | bool UIMachineWindowFullscreen::x11Event(XEvent *pEvent)
|
---|
148 | {
|
---|
149 | /* Qt bug: when the console view grabs the keyboard, FocusIn, FocusOut,
|
---|
150 | * WindowActivate and WindowDeactivate Qt events are not properly sent
|
---|
151 | * on top level window (i.e. this) deactivation. The fix is to substiute
|
---|
152 | * the mode in FocusOut X11 event structure to NotifyNormal to cause
|
---|
153 | * Qt to process it as desired. */
|
---|
154 | if (pEvent->type == FocusOut)
|
---|
155 | {
|
---|
156 | if (pEvent->xfocus.mode == NotifyWhileGrabbed &&
|
---|
157 | (pEvent->xfocus.detail == NotifyAncestor ||
|
---|
158 | pEvent->xfocus.detail == NotifyInferior ||
|
---|
159 | pEvent->xfocus.detail == NotifyNonlinear))
|
---|
160 | {
|
---|
161 | pEvent->xfocus.mode = NotifyNormal;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | return false;
|
---|
165 | }
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | void UIMachineWindowFullscreen::closeEvent(QCloseEvent *pEvent)
|
---|
169 | {
|
---|
170 | return UIMachineWindow::closeEvent(pEvent);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void UIMachineWindowFullscreen::prepareMenu()
|
---|
174 | {
|
---|
175 | UIMainMenuType fMenus = UIMainMenuType_All;
|
---|
176 | /* Remove the view menu in the case there is one screen only. */
|
---|
177 | if (QApplication::desktop()->numScreens() == 1)
|
---|
178 | fMenus = UIMainMenuType(fMenus ^ UIMainMenuType_View);
|
---|
179 | #ifdef Q_WS_MAC
|
---|
180 | setMenuBar(uisession()->newMenuBar(fMenus));
|
---|
181 | #endif /* Q_WS_MAC */
|
---|
182 | m_pMainMenu = uisession()->newMenu(fMenus);
|
---|
183 | }
|
---|
184 |
|
---|
185 | void UIMachineWindowFullscreen::prepareMiniToolBar()
|
---|
186 | {
|
---|
187 | /* Get current machine: */
|
---|
188 | CMachine machine = session().GetConsole().GetMachine();
|
---|
189 | /* Check if mini tool-bar should present: */
|
---|
190 | bool fIsActive = machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no";
|
---|
191 | if (fIsActive)
|
---|
192 | {
|
---|
193 | /* Get the mini tool-bar alignment: */
|
---|
194 | bool fIsAtTop = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top";
|
---|
195 | /* Get the mini tool-bar auto-hide feature availability: */
|
---|
196 | bool fIsAutoHide = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off";
|
---|
197 | m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(),
|
---|
198 | fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
|
---|
199 | true, fIsAutoHide);
|
---|
200 | m_pMiniToolBar->updateDisplay(true, true);
|
---|
201 | QList<QMenu*> menus;
|
---|
202 | menus << uisession()->actionsPool()->action(UIActionIndex_Menu_Machine)->menu();
|
---|
203 | menus << uisession()->actionsPool()->action(UIActionIndex_Menu_Devices)->menu();
|
---|
204 | *m_pMiniToolBar << menus;
|
---|
205 | connect(m_pMiniToolBar, SIGNAL(exitAction()),
|
---|
206 | uisession()->actionsPool()->action(UIActionIndex_Toggle_Fullscreen), SLOT(trigger()));
|
---|
207 | connect(m_pMiniToolBar, SIGNAL(closeAction()),
|
---|
208 | uisession()->actionsPool()->action(UIActionIndex_Simple_Close), SLOT(trigger()));
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | void UIMachineWindowFullscreen::prepareMachineView()
|
---|
213 | {
|
---|
214 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
215 | /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
|
---|
216 | bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
|
---|
217 | #endif
|
---|
218 |
|
---|
219 | /* Set central widget: */
|
---|
220 | setCentralWidget(new QWidget);
|
---|
221 |
|
---|
222 | /* Set central widget layout: */
|
---|
223 | centralWidget()->setLayout(m_pMachineViewContainer);
|
---|
224 |
|
---|
225 | m_pMachineView = UIMachineView::create( this
|
---|
226 | , vboxGlobal().vmRenderMode()
|
---|
227 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
228 | , bAccelerate2DVideo
|
---|
229 | #endif
|
---|
230 | , machineLogic()->visualStateType()
|
---|
231 | , m_uScreenId);
|
---|
232 |
|
---|
233 | /* Add machine view into layout: */
|
---|
234 | m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
|
---|
235 |
|
---|
236 | /* The background has to go black: */
|
---|
237 | QPalette palette(centralWidget()->palette());
|
---|
238 | palette.setColor(centralWidget()->backgroundRole(), Qt::black);
|
---|
239 | centralWidget()->setPalette(palette);
|
---|
240 | centralWidget()->setAutoFillBackground(true);
|
---|
241 | setAutoFillBackground(true);
|
---|
242 | }
|
---|
243 |
|
---|
244 | void UIMachineWindowFullscreen::saveWindowSettings()
|
---|
245 | {
|
---|
246 | /* Get machine: */
|
---|
247 | CMachine machine = session().GetConsole().GetMachine();
|
---|
248 |
|
---|
249 | /* Save extra-data settings: */
|
---|
250 | {
|
---|
251 | /* Save mini tool-bar settings: */
|
---|
252 | if (m_pMiniToolBar)
|
---|
253 | machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off");
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 | void UIMachineWindowFullscreen::cleanupMachineView()
|
---|
258 | {
|
---|
259 | /* Do not cleanup machine view if it is not present: */
|
---|
260 | if (!machineView())
|
---|
261 | return;
|
---|
262 |
|
---|
263 | UIMachineView::destroy(m_pMachineView);
|
---|
264 | m_pMachineView = 0;
|
---|
265 | }
|
---|
266 |
|
---|
267 | void UIMachineWindowFullscreen::cleanupMenu()
|
---|
268 | {
|
---|
269 | delete m_pMainMenu;
|
---|
270 | m_pMainMenu = 0;
|
---|
271 | }
|
---|
272 |
|
---|
273 | void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
|
---|
274 | {
|
---|
275 | /* Base class update: */
|
---|
276 | UIMachineWindow::updateAppearanceOf(iElement);
|
---|
277 |
|
---|
278 | /* If mini tool-bar is present: */
|
---|
279 | if (m_pMiniToolBar)
|
---|
280 | {
|
---|
281 | /* Get machine: */
|
---|
282 | CMachine machine = session().GetConsole().GetMachine();
|
---|
283 | /* Get snapshot(s): */
|
---|
284 | QString strSnapshotName;
|
---|
285 | if (machine.GetSnapshotCount() > 0)
|
---|
286 | {
|
---|
287 | CSnapshot snapshot = machine.GetCurrentSnapshot();
|
---|
288 | strSnapshotName = " (" + snapshot.GetName() + ")";
|
---|
289 | }
|
---|
290 | /* Update mini tool-bar text: */
|
---|
291 | m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName);
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|