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