VirtualBox

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

Last change on this file since 49177 was 49177, checked in by vboxsync, 11 years ago

FE/Qt: Runtime UI: Guest screen size adjustment mechanism.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 49177 2013-10-18 11:48:13Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UIMachineWindowFullscreen class implementation
6 */
7
8/*
9 * Copyright (C) 2010-2013 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/* Qt includes: */
21#include <QDesktopWidget>
22#include <QMenu>
23#include <QTimer>
24
25/* GUI includes: */
26#include "VBoxGlobal.h"
27#include "UISession.h"
28#include "UIActionPoolRuntime.h"
29#include "UIMachineLogicFullscreen.h"
30#include "UIMachineWindowFullscreen.h"
31#include "UIMachineView.h"
32#include "UIMachineDefs.h"
33#include "UIMiniToolBar.h"
34
35/* COM includes: */
36#include "CSnapshot.h"
37
38UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
39 : UIMachineWindow(pMachineLogic, uScreenId)
40 , m_pMainMenu(0)
41 , m_pMiniToolBar(0)
42{
43}
44
45void UIMachineWindowFullscreen::sltMachineStateChanged()
46{
47 /* Call to base-class: */
48 UIMachineWindow::sltMachineStateChanged();
49
50 /* Update mini-toolbar: */
51 updateAppearanceOf(UIVisualElement_MiniToolBar);
52}
53
54void UIMachineWindowFullscreen::sltPopupMainMenu()
55{
56 /* Popup main-menu if present: */
57 if (m_pMainMenu && !m_pMainMenu->isEmpty())
58 {
59 m_pMainMenu->popup(geometry().center());
60 QTimer::singleShot(0, m_pMainMenu, SLOT(sltSelectFirstAction()));
61 }
62}
63
64void UIMachineWindowFullscreen::prepareMenu()
65{
66 /* Call to base-class: */
67 UIMachineWindow::prepareMenu();
68
69 /* Prepare menu: */
70 CMachine machine = session().GetMachine();
71 RuntimeMenuType restrictedMenus = VBoxGlobal::restrictedRuntimeMenuTypes(machine);
72 RuntimeMenuType allowedMenus = static_cast<RuntimeMenuType>(RuntimeMenuType_All ^ restrictedMenus);
73 m_pMainMenu = uisession()->newMenu(allowedMenus);
74}
75
76void UIMachineWindowFullscreen::prepareVisualState()
77{
78 /* Call to base-class: */
79 UIMachineWindow::prepareVisualState();
80
81 /* The background has to go black: */
82 QPalette palette(centralWidget()->palette());
83 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
84 centralWidget()->setPalette(palette);
85 centralWidget()->setAutoFillBackground(true);
86 setAutoFillBackground(true);
87
88 /* Prepare mini-toolbar: */
89 prepareMiniToolbar();
90}
91
92void UIMachineWindowFullscreen::prepareMiniToolbar()
93{
94 /* Get machine: */
95 CMachine m = machine();
96
97 /* Make sure mini-toolbar is necessary: */
98 bool fIsActive = m.GetExtraData(GUI_ShowMiniToolBar) != "no";
99 if (!fIsActive)
100 return;
101
102 /* Get the mini-toolbar alignment: */
103 bool fIsAtTop = m.GetExtraData(GUI_MiniToolBarAlignment) == "top";
104 /* Get the mini-toolbar auto-hide feature availability: */
105 bool fIsAutoHide = m.GetExtraData(GUI_MiniToolBarAutoHide) != "off";
106 /* Create mini-toolbar: */
107 m_pMiniToolBar = new UIRuntimeMiniToolBar(this,
108 fIsAtTop ? Qt::AlignTop : Qt::AlignBottom,
109 IntegrationMode_Embedded,
110 fIsAutoHide);
111 QList<QMenu*> menus;
112 RuntimeMenuType restrictedMenus = VBoxGlobal::restrictedRuntimeMenuTypes(m);
113 RuntimeMenuType allowedMenus = static_cast<RuntimeMenuType>(RuntimeMenuType_All ^ restrictedMenus);
114 QList<QAction*> actions = uisession()->newMenu(allowedMenus)->actions();
115 for (int i=0; i < actions.size(); ++i)
116 menus << actions.at(i)->menu();
117 m_pMiniToolBar->addMenus(menus);
118 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized()));
119 connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
120 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger()));
121 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
122 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger()));
123}
124
125void UIMachineWindowFullscreen::cleanupMiniToolbar()
126{
127 /* Make sure mini-toolbar was created: */
128 if (!m_pMiniToolBar)
129 return;
130
131 /* Save mini-toolbar settings: */
132 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->autoHide() ? QString() : "off");
133 /* Delete mini-toolbar: */
134 delete m_pMiniToolBar;
135 m_pMiniToolBar = 0;
136}
137
138void UIMachineWindowFullscreen::cleanupVisualState()
139{
140 /* Cleanup mini-toolbar: */
141 cleanupMiniToolbar();
142
143 /* Call to base-class: */
144 UIMachineWindow::cleanupVisualState();
145}
146
147void UIMachineWindowFullscreen::cleanupMenu()
148{
149 /* Cleanup menu: */
150 delete m_pMainMenu;
151 m_pMainMenu = 0;
152
153 /* Call to base-class: */
154 UIMachineWindow::cleanupMenu();
155}
156
157void UIMachineWindowFullscreen::placeOnScreen()
158{
159 /* Get corresponding screen: */
160 int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
161 /* Calculate working area: */
162 QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
163 /* Move to the appropriate position: */
164 move(workingArea.topLeft());
165 /* Resize to the appropriate size: */
166 resize(workingArea.size());
167 /* Adjust guest screen size if necessary: */
168 machineView()->maybeAdjustGuestScreenSize();
169 /* Move mini-toolbar into appropriate place: */
170 if (m_pMiniToolBar)
171 m_pMiniToolBar->adjustGeometry();
172 /* Process pending move & resize events: */
173 qApp->processEvents();
174}
175
176void UIMachineWindowFullscreen::showInNecessaryMode()
177{
178 /* Should we show window?: */
179 if (uisession()->isScreenVisible(m_uScreenId))
180 {
181 /* Do we have the seamless logic? */
182 if (UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic()))
183 {
184 /* Is this guest screen has own host screen? */
185 if (pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
186 {
187 /* Make sure the window is maximized and placed on valid screen: */
188 placeOnScreen();
189
190#ifdef Q_WS_WIN
191 /* On Windows we should activate main window first,
192 * because entering fullscreen there doesn't means window will be auto-activated,
193 * so no window-activation event will be received
194 * and no keyboard-hook created otherwise... */
195 if (m_uScreenId == 0)
196 setWindowState(windowState() | Qt::WindowActive);
197#endif /* Q_WS_WIN */
198
199 /* Show in fullscreen mode: */
200 showFullScreen();
201
202 /* Make sure the window is placed on valid screen again
203 * after window is shown & window's decorations applied.
204 * That is required (still?) due to X11 Window Geometry Rules. */
205 placeOnScreen();
206
207 /* Return early: */
208 return;
209 }
210 }
211 }
212 /* Hide in other cases: */
213 hide();
214}
215
216void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
217{
218 /* Call to base-class: */
219 UIMachineWindow::updateAppearanceOf(iElement);
220
221 /* Update mini-toolbar: */
222 if (iElement & UIVisualElement_MiniToolBar)
223 {
224 if (m_pMiniToolBar)
225 {
226 /* Get machine: */
227 const CMachine &m = machine();
228 /* Get snapshot(s): */
229 QString strSnapshotName;
230 if (m.GetSnapshotCount() > 0)
231 {
232 CSnapshot snapshot = m.GetCurrentSnapshot();
233 strSnapshotName = " (" + snapshot.GetName() + ")";
234 }
235 /* Update mini-toolbar text: */
236 m_pMiniToolBar->setText(m.GetName() + strSnapshotName);
237 }
238 }
239}
240
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