VirtualBox

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

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

FE/Qt: Runtime UI: Extra-data flag (GUI/RestrictedRuntimeMenus) to hide particular runtime UI menus.

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