VirtualBox

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

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

FE/Qt: 5219: Minimize from fullscreen - Initial implementation, icon to be committed later.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 31866 2010-08-23 14:52:35Z 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 "UIActionsPool.h"
33#include "UIMachineLogicFullscreen.h"
34#include "UIMachineWindowFullscreen.h"
35#include "UIMachineView.h"
36
37UIMachineWindowFullscreen::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
96UIMachineWindowFullscreen::~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
114void 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
128void UIMachineWindowFullscreen::sltMachineStateChanged()
129{
130 UIMachineWindow::sltMachineStateChanged();
131}
132
133void 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
143void UIMachineWindowFullscreen::sltTryClose()
144{
145 UIMachineWindow::sltTryClose();
146}
147
148void UIMachineWindowFullscreen::retranslateUi()
149{
150 /* Translate parent class: */
151 UIMachineWindow::retranslateUi();
152}
153
154#ifdef Q_WS_X11
155bool UIMachineWindowFullscreen::x11Event(XEvent *pEvent)
156{
157 return UIMachineWindow::x11Event(pEvent);
158}
159#endif
160
161void UIMachineWindowFullscreen::closeEvent(QCloseEvent *pEvent)
162{
163 return UIMachineWindow::closeEvent(pEvent);
164}
165
166void UIMachineWindowFullscreen::prepareMenu()
167{
168 UIMainMenuType fMenus = UIMainMenuType_All;
169 /* Remove the view menu in the case there is one screen only. */
170 if (QApplication::desktop()->numScreens() == 1)
171 fMenus = UIMainMenuType(fMenus ^ UIMainMenuType_View);
172#ifdef Q_WS_MAC
173 setMenuBar(uisession()->newMenuBar(fMenus));
174#endif /* Q_WS_MAC */
175 m_pMainMenu = uisession()->newMenu(fMenus);
176}
177
178void UIMachineWindowFullscreen::prepareMiniToolBar()
179{
180 /* Get current machine: */
181 CMachine machine = session().GetConsole().GetMachine();
182 /* Check if mini tool-bar should present: */
183 bool fIsActive = machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no";
184 if (fIsActive)
185 {
186 /* Get the mini tool-bar alignment: */
187 bool fIsAtTop = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top";
188 /* Get the mini tool-bar auto-hide feature availability: */
189 bool fIsAutoHide = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off";
190 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(),
191 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
192 true, fIsAutoHide);
193 m_pMiniToolBar->updateDisplay(true, true);
194 QList<QMenu*> menus;
195 UIMainMenuType fMenu = UIMainMenuType(UIMainMenuType_Machine | UIMainMenuType_Devices);
196 if (QApplication::desktop()->numScreens() > 1)
197 fMenu = UIMainMenuType(fMenu | UIMainMenuType_View);
198 QList<QAction*> actions = uisession()->newMenu(fMenu)->actions();
199 for (int i=0; i < actions.size(); ++i)
200 menus << actions.at(i)->menu();
201 *m_pMiniToolBar << menus;
202 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized()));
203 connect(m_pMiniToolBar, SIGNAL(exitAction()),
204 uisession()->actionsPool()->action(UIActionIndex_Toggle_Fullscreen), SLOT(trigger()));
205 connect(m_pMiniToolBar, SIGNAL(closeAction()),
206 uisession()->actionsPool()->action(UIActionIndex_Simple_Close), SLOT(trigger()));
207 }
208}
209
210void UIMachineWindowFullscreen::prepareMachineView()
211{
212#ifdef VBOX_WITH_VIDEOHWACCEL
213 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
214 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
215#endif
216
217 /* Set central widget: */
218 setCentralWidget(new QWidget);
219
220 /* Set central widget layout: */
221 centralWidget()->setLayout(m_pMachineViewContainer);
222
223 m_pMachineView = UIMachineView::create( this
224 , m_uScreenId
225 , machineLogic()->visualStateType()
226#ifdef VBOX_WITH_VIDEOHWACCEL
227 , bAccelerate2DVideo
228#endif
229 );
230
231 /* Add machine view into layout: */
232 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
233
234 /* The background has to go black: */
235 QPalette palette(centralWidget()->palette());
236 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
237 centralWidget()->setPalette(palette);
238 centralWidget()->setAutoFillBackground(true);
239 setAutoFillBackground(true);
240}
241
242void UIMachineWindowFullscreen::saveWindowSettings()
243{
244 /* Get machine: */
245 CMachine machine = session().GetConsole().GetMachine();
246
247 /* Save extra-data settings: */
248 {
249 /* Save mini tool-bar settings: */
250 if (m_pMiniToolBar)
251 machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off");
252 }
253}
254
255void UIMachineWindowFullscreen::cleanupMachineView()
256{
257 /* Do not cleanup machine view if it is not present: */
258 if (!machineView())
259 return;
260
261 UIMachineView::destroy(m_pMachineView);
262 m_pMachineView = 0;
263}
264
265void UIMachineWindowFullscreen::cleanupMiniToolBar()
266{
267 if (m_pMiniToolBar)
268 {
269 delete m_pMiniToolBar;
270 m_pMiniToolBar = 0;
271 }
272}
273
274void UIMachineWindowFullscreen::cleanupMenu()
275{
276 delete m_pMainMenu;
277 m_pMainMenu = 0;
278}
279
280void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
281{
282 /* Base class update: */
283 UIMachineWindow::updateAppearanceOf(iElement);
284
285 /* If mini tool-bar is present: */
286 if (m_pMiniToolBar)
287 {
288 /* Get machine: */
289 CMachine machine = session().GetConsole().GetMachine();
290 /* Get snapshot(s): */
291 QString strSnapshotName;
292 if (machine.GetSnapshotCount() > 0)
293 {
294 CSnapshot snapshot = machine.GetCurrentSnapshot();
295 strSnapshotName = " (" + snapshot.GetName() + ")";
296 }
297 /* Update mini tool-bar text: */
298 m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName);
299 }
300}
301
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use