VirtualBox

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

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

FE/Qt4: new core: remove old stuff

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 27436 2010-03-17 11:28:09Z 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
41UIMachineWindowFullscreen::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
97UIMachineWindowFullscreen::~UIMachineWindowFullscreen()
98{
99 /* Save window settings: */
100 saveWindowSettings();
101
102 /* Cleanup machine view: */
103 cleanupMachineView();
104
105 /* Cleanup menu: */
106 cleanupMenu();
107}
108
109void UIMachineWindowFullscreen::sltPlaceOnScreen()
110{
111 QRect r = QApplication::desktop()->screenGeometry(static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));
112 move(r.topLeft());
113 resize(r.size());
114 qApp->processEvents();
115}
116
117void UIMachineWindowFullscreen::sltMachineStateChanged()
118{
119 UIMachineWindow::sltMachineStateChanged();
120}
121
122void UIMachineWindowFullscreen::sltPopupMainMenu()
123{
124 /* Popup main menu if present: */
125 if (m_pMainMenu && !m_pMainMenu->isEmpty())
126 m_pMainMenu->popup(machineWindow()->geometry().center());
127}
128
129void UIMachineWindowFullscreen::sltTryClose()
130{
131 UIMachineWindow::sltTryClose();
132}
133
134void UIMachineWindowFullscreen::retranslateUi()
135{
136 /* Translate parent class: */
137 UIMachineWindow::retranslateUi();
138}
139
140#ifdef Q_WS_X11
141bool UIMachineWindowFullscreen::x11Event(XEvent *pEvent)
142{
143 /* Qt bug: when the console view grabs the keyboard, FocusIn, FocusOut,
144 * WindowActivate and WindowDeactivate Qt events are not properly sent
145 * on top level window (i.e. this) deactivation. The fix is to substiute
146 * the mode in FocusOut X11 event structure to NotifyNormal to cause
147 * Qt to process it as desired. */
148 if (pEvent->type == FocusOut)
149 {
150 if (pEvent->xfocus.mode == NotifyWhileGrabbed &&
151 (pEvent->xfocus.detail == NotifyAncestor ||
152 pEvent->xfocus.detail == NotifyInferior ||
153 pEvent->xfocus.detail == NotifyNonlinear))
154 {
155 pEvent->xfocus.mode = NotifyNormal;
156 }
157 }
158 return false;
159}
160#endif
161
162void UIMachineWindowFullscreen::closeEvent(QCloseEvent *pEvent)
163{
164 return UIMachineWindow::closeEvent(pEvent);
165}
166
167void UIMachineWindowFullscreen::prepareMenu()
168{
169 UIMainMenuType fMenus = UIMainMenuType_All;
170 /* Remove the view menu in the case there is one screen only. */
171 if (QApplication::desktop()->numScreens() == 1)
172 fMenus = UIMainMenuType(fMenus ^ UIMainMenuType_View);
173#ifdef Q_WS_MAC
174 setMenuBar(uisession()->newMenuBar(fMenus));
175#endif /* Q_WS_MAC */
176 m_pMainMenu = uisession()->newMenu(fMenus);
177}
178
179void UIMachineWindowFullscreen::prepareMiniToolBar()
180{
181 /* Get current machine: */
182 CMachine machine = session().GetConsole().GetMachine();
183 /* Check if mini tool-bar should present: */
184 bool fIsActive = machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no";
185 if (fIsActive)
186 {
187 /* Get the mini tool-bar alignment: */
188 bool fIsAtTop = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top";
189 /* Get the mini tool-bar auto-hide feature availability: */
190 bool fIsAutoHide = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off";
191 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(),
192 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
193 true, fIsAutoHide);
194 m_pMiniToolBar->updateDisplay(true, true);
195 QList<QMenu*> menus;
196 menus << uisession()->actionsPool()->action(UIActionIndex_Menu_Machine)->menu();
197 menus << uisession()->actionsPool()->action(UIActionIndex_Menu_Devices)->menu();
198 *m_pMiniToolBar << menus;
199 connect(m_pMiniToolBar, SIGNAL(exitAction()),
200 uisession()->actionsPool()->action(UIActionIndex_Toggle_Fullscreen), SLOT(trigger()));
201 connect(m_pMiniToolBar, SIGNAL(closeAction()),
202 uisession()->actionsPool()->action(UIActionIndex_Simple_Close), SLOT(trigger()));
203 }
204}
205
206void UIMachineWindowFullscreen::prepareMachineView()
207{
208#ifdef VBOX_WITH_VIDEOHWACCEL
209 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
210 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
211#endif
212
213 /* Set central widget: */
214 setCentralWidget(new QWidget);
215
216 /* Set central widget layout: */
217 centralWidget()->setLayout(m_pMachineViewContainer);
218
219 m_pMachineView = UIMachineView::create( this
220 , vboxGlobal().vmRenderMode()
221#ifdef VBOX_WITH_VIDEOHWACCEL
222 , bAccelerate2DVideo
223#endif
224 , machineLogic()->visualStateType()
225 , m_uScreenId);
226
227 /* Add machine view into layout: */
228 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
229
230 /* The background has to go black: */
231 QPalette palette(centralWidget()->palette());
232 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
233 centralWidget()->setPalette(palette);
234 centralWidget()->setAutoFillBackground(true);
235 setAutoFillBackground(true);
236}
237
238void UIMachineWindowFullscreen::saveWindowSettings()
239{
240 /* Get machine: */
241 CMachine machine = session().GetConsole().GetMachine();
242
243 /* Save extra-data settings: */
244 {
245 /* Save mini tool-bar settings: */
246 if (m_pMiniToolBar)
247 machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off");
248 }
249}
250
251void UIMachineWindowFullscreen::cleanupMachineView()
252{
253 /* Do not cleanup machine view if it is not present: */
254 if (!machineView())
255 return;
256
257 UIMachineView::destroy(m_pMachineView);
258 m_pMachineView = 0;
259}
260
261void UIMachineWindowFullscreen::cleanupMenu()
262{
263 delete m_pMainMenu;
264 m_pMainMenu = 0;
265}
266
267void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
268{
269 /* Base class update: */
270 UIMachineWindow::updateAppearanceOf(iElement);
271
272 /* If mini tool-bar is present: */
273 if (m_pMiniToolBar)
274 {
275 /* Get machine: */
276 CMachine machine = session().GetConsole().GetMachine();
277 /* Get snapshot(s): */
278 QString strSnapshotName;
279 if (machine.GetSnapshotCount() > 0)
280 {
281 CSnapshot snapshot = machine.GetCurrentSnapshot();
282 strSnapshotName = " (" + snapshot.GetName() + ")";
283 }
284 /* Update mini tool-bar text: */
285 m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName);
286 }
287}
288
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