VirtualBox

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

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

FE/Qt: Mac OS X: Hide mini-toolbar minimize button.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 49758 2013-12-03 15:07:30Z 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(sltHighlightFirstAction()));
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#ifndef RT_OS_DARWIN
119 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized()));
120#endif /* !RT_OS_DARWIN */
121 connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
122 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger()));
123 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
124 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger()));
125}
126
127void UIMachineWindowFullscreen::cleanupMiniToolbar()
128{
129 /* Make sure mini-toolbar was created: */
130 if (!m_pMiniToolBar)
131 return;
132
133 /* Save mini-toolbar settings: */
134 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->autoHide() ? QString() : "off");
135 /* Delete mini-toolbar: */
136 delete m_pMiniToolBar;
137 m_pMiniToolBar = 0;
138}
139
140void UIMachineWindowFullscreen::cleanupVisualState()
141{
142 /* Cleanup mini-toolbar: */
143 cleanupMiniToolbar();
144
145 /* Call to base-class: */
146 UIMachineWindow::cleanupVisualState();
147}
148
149void UIMachineWindowFullscreen::cleanupMenu()
150{
151 /* Cleanup menu: */
152 delete m_pMainMenu;
153 m_pMainMenu = 0;
154
155 /* Call to base-class: */
156 UIMachineWindow::cleanupMenu();
157}
158
159void UIMachineWindowFullscreen::placeOnScreen()
160{
161 /* Get corresponding screen: */
162 int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
163 /* Calculate working area: */
164 QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
165 /* Move to the appropriate position: */
166 move(workingArea.topLeft());
167 /* Resize to the appropriate size: */
168 resize(workingArea.size());
169 /* Adjust guest screen size if necessary: */
170 machineView()->maybeAdjustGuestScreenSize();
171 /* Move mini-toolbar into appropriate place: */
172 if (m_pMiniToolBar)
173 m_pMiniToolBar->adjustGeometry();
174 /* Process pending move & resize events: */
175 qApp->processEvents();
176}
177
178void UIMachineWindowFullscreen::showInNecessaryMode()
179{
180 /* Should we show window?: */
181 if (uisession()->isScreenVisible(m_uScreenId))
182 {
183 /* Do we have the seamless logic? */
184 if (UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic()))
185 {
186 /* Is this guest screen has own host screen? */
187 if (pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
188 {
189 /* Make sure the window is maximized and placed on valid screen: */
190 placeOnScreen();
191
192#ifdef Q_WS_WIN
193 /* On Windows we should activate main window first,
194 * because entering fullscreen there doesn't means window will be auto-activated,
195 * so no window-activation event will be received
196 * and no keyboard-hook created otherwise... */
197 if (m_uScreenId == 0)
198 setWindowState(windowState() | Qt::WindowActive);
199#endif /* Q_WS_WIN */
200
201 /* Show in fullscreen mode: */
202 showFullScreen();
203
204 /* Make sure the window is placed on valid screen again
205 * after window is shown & window's decorations applied.
206 * That is required (still?) due to X11 Window Geometry Rules. */
207 placeOnScreen();
208
209 /* Return early: */
210 return;
211 }
212 }
213 }
214 /* Hide in other cases: */
215 hide();
216}
217
218void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
219{
220 /* Call to base-class: */
221 UIMachineWindow::updateAppearanceOf(iElement);
222
223 /* Update mini-toolbar: */
224 if (iElement & UIVisualElement_MiniToolBar)
225 {
226 if (m_pMiniToolBar)
227 {
228 /* Get machine: */
229 const CMachine &m = machine();
230 /* Get snapshot(s): */
231 QString strSnapshotName;
232 if (m.GetSnapshotCount() > 0)
233 {
234 CSnapshot snapshot = m.GetCurrentSnapshot();
235 strSnapshotName = " (" + snapshot.GetName() + ")";
236 }
237 /* Update mini-toolbar text: */
238 m_pMiniToolBar->setText(m.GetName() + strSnapshotName);
239 }
240 }
241}
242
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette