VirtualBox

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

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

FE/Qt4: New running VM core: build fox for r58170.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 26891 2010-02-28 15:30:11Z 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#include <QMenuBar>
27#include <QTimer>
28#include <QContextMenuEvent>
29
30/* Local includes */
31#include "VBoxGlobal.h"
32
33#include "UISession.h"
34#include "UIActionsPool.h"
35#include "UIMachineLogic.h"
36#include "UIMachineView.h"
37#include "UIMachineWindowFullscreen.h"
38
39#ifdef Q_WS_MAC
40# ifdef QT_MAC_USE_COCOA
41# include <Carbon/Carbon.h>
42# endif /* QT_MAC_USE_COCOA */
43#endif /* Q_WS_MAC */
44
45UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic)
46 : QIWithRetranslateUI<QIMainDialog>(0)
47 , UIMachineWindow(pMachineLogic)
48{
49 /* "This" is machine window: */
50 m_pMachineWindow = this;
51
52 /* Prepare window icon: */
53 prepareWindowIcon();
54
55 /* Prepare console connections: */
56 prepareConsoleConnections();
57
58 /* Prepare menu: */
59 prepareMenu();
60
61 /* Prepare connections: */
62 prepareConnections();
63
64 /* Retranslate normal window finally: */
65 retranslateUi();
66
67 /* Prepare machine view container: */
68 prepareMachineViewContainer();
69
70 /* Prepare normal machine view: */
71 prepareMachineView();
72
73 /* Load normal window settings: */
74 loadWindowSettings();
75
76 /* Update all the elements: */
77 updateAppearanceOf(UIVisualElement_AllStuff);
78
79 /* Show window: */
80// show();
81}
82
83UIMachineWindowFullscreen::~UIMachineWindowFullscreen()
84{
85 /* Save normal window settings: */
86 saveWindowSettings();
87
88 /* Cleanup normal machine view: */
89 cleanupMachineView();
90}
91
92void UIMachineWindowFullscreen::sltMachineStateChanged()
93{
94 UIMachineWindow::sltMachineStateChanged();
95}
96
97void UIMachineWindowFullscreen::sltMediumChange(const CMediumAttachment &attachment)
98{
99 KDeviceType type = attachment.GetType();
100 if (type == KDeviceType_HardDisk)
101 updateAppearanceOf(UIVisualElement_HDStuff);
102 if (type == KDeviceType_DVD)
103 updateAppearanceOf(UIVisualElement_CDStuff);
104 if (type == KDeviceType_Floppy)
105 updateAppearanceOf(UIVisualElement_FDStuff);
106}
107
108void UIMachineWindowFullscreen::sltUSBControllerChange()
109{
110 updateAppearanceOf(UIVisualElement_USBStuff);
111}
112
113void UIMachineWindowFullscreen::sltUSBDeviceStateChange()
114{
115 updateAppearanceOf(UIVisualElement_USBStuff);
116}
117
118void UIMachineWindowFullscreen::sltNetworkAdapterChange()
119{
120 updateAppearanceOf(UIVisualElement_NetworkStuff);
121}
122
123void UIMachineWindowFullscreen::sltSharedFolderChange()
124{
125 updateAppearanceOf(UIVisualElement_SharedFolderStuff);
126}
127
128void UIMachineWindowFullscreen::sltTryClose()
129{
130 UIMachineWindow::sltTryClose();
131}
132
133void UIMachineWindowFullscreen::sltProcessGlobalSettingChange(const char * /* aPublicName */, const char * /* aName */)
134{
135}
136
137void UIMachineWindowFullscreen::retranslateUi()
138{
139 /* Translate parent class: */
140 UIMachineWindow::retranslateUi();
141
142#ifdef Q_WS_MAC
143 // TODO_NEW_CORE
144// m_pDockSettingsMenu->setTitle(tr("Dock Icon"));
145// m_pDockDisablePreview->setText(tr("Show Application Icon"));
146// m_pDockEnablePreviewMonitor->setText(tr("Show Monitor Preview"));
147#endif /* Q_WS_MAC */
148}
149
150void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
151{
152 /* Update parent-class window: */
153 UIMachineWindow::updateAppearanceOf(iElement);
154}
155
156bool UIMachineWindowFullscreen::event(QEvent *pEvent)
157{
158 return QIWithRetranslateUI<QIMainDialog>::event(pEvent);
159 switch (pEvent->type())
160 {
161 case QEvent::Resize:
162 {
163 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
164 if (!isMaximized())
165 {
166 m_normalGeometry.setSize(pResizeEvent->size());
167#ifdef VBOX_WITH_DEBUGGER_GUI
168 // TODO: Update debugger window size!
169 //dbgAdjustRelativePos();
170#endif
171 }
172 break;
173 }
174 case QEvent::Move:
175 {
176 if (!isMaximized())
177 {
178 m_normalGeometry.moveTo(geometry().x(), geometry().y());
179#ifdef VBOX_WITH_DEBUGGER_GUI
180 // TODO: Update debugger window position!
181 //dbgAdjustRelativePos();
182#endif
183 }
184 break;
185 }
186 default:
187 break;
188 }
189 return QIWithRetranslateUI<QIMainDialog>::event(pEvent);
190}
191
192#ifdef Q_WS_X11
193bool UIMachineWindowFullscreen::x11Event(XEvent *pEvent)
194{
195 /* Qt bug: when the console view grabs the keyboard, FocusIn, FocusOut,
196 * WindowActivate and WindowDeactivate Qt events are not properly sent
197 * on top level window (i.e. this) deactivation. The fix is to substiute
198 * the mode in FocusOut X11 event structure to NotifyNormal to cause
199 * Qt to process it as desired. */
200 if (pEvent->type == FocusOut)
201 {
202 if (pEvent->xfocus.mode == NotifyWhileGrabbed &&
203 (pEvent->xfocus.detail == NotifyAncestor ||
204 pEvent->xfocus.detail == NotifyInferior ||
205 pEvent->xfocus.detail == NotifyNonlinear))
206 {
207 pEvent->xfocus.mode = NotifyNormal;
208 }
209 }
210 return false;
211}
212#endif
213
214void UIMachineWindowFullscreen::closeEvent(QCloseEvent *pEvent)
215{
216 return UIMachineWindow::closeEvent(pEvent);
217}
218
219void UIMachineWindowFullscreen::prepareConsoleConnections()
220{
221 /* Base-class connections: */
222 UIMachineWindow::prepareConsoleConnections();
223
224 /* Medium change updater: */
225 connect(machineLogic()->uisession(), SIGNAL(sigMediumChange(const CMediumAttachment &)),
226 this, SLOT(sltMediumChange(const CMediumAttachment &)));
227
228 /* USB controller change updater: */
229 connect(machineLogic()->uisession(), SIGNAL(sigUSBControllerChange()),
230 this, SLOT(sltUSBControllerChange()));
231
232 /* USB device state-change updater: */
233 connect(machineLogic()->uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
234 this, SLOT(sltUSBDeviceStateChange()));
235
236 /* Network adapter change updater: */
237 connect(machineLogic()->uisession(), SIGNAL(sigNetworkAdapterChange(const CNetworkAdapter &)),
238 this, SLOT(sltNetworkAdapterChange()));
239
240 /* Shared folder change updater: */
241 connect(machineLogic()->uisession(), SIGNAL(sigSharedFolderChange()),
242 this, SLOT(sltSharedFolderChange()));
243}
244
245void UIMachineWindowFullscreen::prepareMenu()
246{
247 /* Machine submenu: */
248 QMenu *pMenuMachine = machineLogic()->actionsPool()->action(UIActionIndex_Menu_Machine)->menu();
249 prepareMenuMachine();
250 menuBar()->addMenu(pMenuMachine);
251
252 /* Devices submenu: */
253 QMenu *pMenuDevices = machineLogic()->actionsPool()->action(UIActionIndex_Menu_Devices)->menu();
254 prepareMenuDevices();
255 menuBar()->addMenu(pMenuDevices);
256
257#ifdef VBOX_WITH_DEBUGGER_GUI
258 if (vboxGlobal().isDebuggerEnabled())
259 {
260 QMenu *pMenuDebug = machineLogic()->actionsPool()->action(UIActionIndex_Menu_Debug)->menu();
261 prepareMenuDebug();
262 menuBar()->addMenu(pMenuDebug);
263 }
264#endif
265
266 /* Help submenu: */
267 QMenu *pMenuHelp = machineLogic()->actionsPool()->action(UIActionIndex_Menu_Help)->menu();
268 prepareMenuHelp();
269 menuBar()->addMenu(pMenuHelp);
270}
271
272void UIMachineWindowFullscreen::prepareConnections()
273{
274 /* Setup global settings change updater: */
275 connect(&vboxGlobal().settings(), SIGNAL(propertyChanged(const char *, const char *)),
276 this, SLOT(sltProcessGlobalSettingChange(const char *, const char *)));
277}
278
279void UIMachineWindowFullscreen::prepareMachineView()
280{
281 CMachine machine = session().GetMachine();
282
283#ifdef VBOX_WITH_VIDEOHWACCEL
284 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
285 bool bAccelerate2DVideo = machine.GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
286#endif
287
288 /* Set central widget: */
289 setCentralWidget(new QWidget(this));
290
291 /* Set central widget layout: */
292 centralWidget()->setLayout(m_pMachineViewContainer);
293
294 m_pMachineView = UIMachineView::create( this
295 , vboxGlobal().vmRenderMode()
296#ifdef VBOX_WITH_VIDEOHWACCEL
297 , bAccelerate2DVideo
298#endif
299 , machineLogic()->visualStateType());
300
301 /* Add machine view into layout: */
302 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
303}
304
305void UIMachineWindowFullscreen::loadWindowSettings()
306{
307 /* Load normal window settings: */
308 CMachine machine = session().GetMachine();
309
310 /* Toggle console to manual resize mode. */
311 m_pMachineView->setMachineWindowResizeIgnored(true);
312 m_pMachineView->setFrameBufferResizeIgnored(true);
313
314 /* The background has to go black */
315 QPalette palette(centralWidget()->palette());
316 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
317 centralWidget()->setPalette (palette);
318 centralWidget()->setAutoFillBackground (true);
319 setAutoFillBackground (true);
320
321 /* We have to show the window early, or the position will be wrong on the
322 Mac */
323 show();
324
325#ifdef Q_WS_MAC
326# ifndef QT_MAC_USE_COCOA
327 /* setWindowState removes the window group connection somehow. So save it
328 * temporary. */
329 WindowGroupRef g = GetWindowGroup(::darwinToNativeWindow(this));
330# endif /* !QT_MAC_USE_COCOA */
331 /* Here we are going really fullscreen */
332 setWindowState(windowState() ^ Qt::WindowFullScreen);
333 setPresentationModeEnabled(true);
334
335# ifndef QT_MAC_USE_COCOA
336 /* Reassign the correct window group. */
337 SetWindowGroup(::darwinToNativeWindow (this), g);
338# endif /* !QT_MAC_USE_COCOA */
339#else /* Q_WS_MAC */
340 setWindowState(windowState() ^ Qt::WindowFullScreen);
341#endif/* !Q_WS_MAC */
342
343 QRect r = geometry();
344 /* Load global settings: */
345 {
346// VBoxGlobalSettings settings = vboxGlobal().settings();
347// menuBar()->setHidden(settings.isFeatureActive("noMenuBar"));
348 }
349}
350
351void UIMachineWindowFullscreen::saveWindowSettings()
352{
353 CMachine machine = session().GetMachine();
354
355 /* Save extra-data settings: */
356 {
357 }
358
359#ifdef Q_WS_MAC
360 setPresentationModeEnabled(false);
361#endif/* Q_WS_MAC */
362}
363
364void UIMachineWindowFullscreen::cleanupMachineView()
365{
366 /* Do not cleanup machine view if it is not present: */
367 if (!machineView())
368 return;
369
370 UIMachineView::destroy(m_pMachineView);
371 m_pMachineView = 0;
372}
373
374#ifdef Q_WS_MAC
375# ifdef QT_MAC_USE_COCOA
376void UIMachineWindowFullscreen::setPresentationModeEnabled(bool fEnabled)
377{
378 if (fEnabled)
379 {
380 /* First check if we are on the primary screen, only than the presentation mode have to be changed. */
381 QDesktopWidget* pDesktop = QApplication::desktop();
382 if (pDesktop->screenNumber(this) == pDesktop->primaryScreen())
383 {
384 QString testStr = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_PresentationModeEnabled).toLower();
385 /* Default to false if it is an empty value */
386 if (testStr.isEmpty() || testStr == "false")
387 SetSystemUIMode(kUIModeAllHidden, 0);
388 else
389 SetSystemUIMode(kUIModeAllSuppressed, 0);
390 }
391 }
392 else
393 SetSystemUIMode(kUIModeNormal, 0);
394}
395# endif /* QT_MAC_USE_COCOA */
396#endif /* Q_WS_MAC */
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