1 | /* $Id: UIMachineWindowFullscreen.cpp 46244 2013-05-23 16:43:46Z 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 | #ifdef Q_WS_MAC
|
---|
25 | # include <QMenuBar>
|
---|
26 | #endif /* Q_WS_MAC */
|
---|
27 |
|
---|
28 | /* GUI includes: */
|
---|
29 | #include "UIDefs.h"
|
---|
30 | #include "UIMiniToolBar.h"
|
---|
31 | #include "UISession.h"
|
---|
32 | #include "UIActionPoolRuntime.h"
|
---|
33 | #include "UIMachineLogicFullscreen.h"
|
---|
34 | #include "UIMachineWindowFullscreen.h"
|
---|
35 |
|
---|
36 | /* COM includes: */
|
---|
37 | #include "CMachine.h"
|
---|
38 | #include "CSnapshot.h"
|
---|
39 |
|
---|
40 | UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
|
---|
41 | : UIMachineWindow(pMachineLogic, uScreenId)
|
---|
42 | , m_pMainMenu(0)
|
---|
43 | , m_pMiniToolBar(0)
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | void UIMachineWindowFullscreen::sltMachineStateChanged()
|
---|
48 | {
|
---|
49 | /* Call to base-class: */
|
---|
50 | UIMachineWindow::sltMachineStateChanged();
|
---|
51 |
|
---|
52 | /* Update mini-toolbar: */
|
---|
53 | updateAppearanceOf(UIVisualElement_MiniToolBar);
|
---|
54 | }
|
---|
55 |
|
---|
56 | void UIMachineWindowFullscreen::sltPopupMainMenu()
|
---|
57 | {
|
---|
58 | /* Popup main-menu if present: */
|
---|
59 | if (m_pMainMenu && !m_pMainMenu->isEmpty())
|
---|
60 | {
|
---|
61 | m_pMainMenu->popup(geometry().center());
|
---|
62 | QTimer::singleShot(0, m_pMainMenu, SLOT(sltSelectFirstAction()));
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | void UIMachineWindowFullscreen::prepareMenu()
|
---|
67 | {
|
---|
68 | /* Call to base-class: */
|
---|
69 | UIMachineWindow::prepareMenu();
|
---|
70 |
|
---|
71 | /* Prepare menu: */
|
---|
72 | m_pMainMenu = uisession()->newMenu();
|
---|
73 | }
|
---|
74 |
|
---|
75 | void UIMachineWindowFullscreen::prepareVisualState()
|
---|
76 | {
|
---|
77 | /* Call to base-class: */
|
---|
78 | UIMachineWindow::prepareVisualState();
|
---|
79 |
|
---|
80 | /* The background has to go black: */
|
---|
81 | QPalette palette(centralWidget()->palette());
|
---|
82 | palette.setColor(centralWidget()->backgroundRole(), Qt::black);
|
---|
83 | centralWidget()->setPalette(palette);
|
---|
84 | centralWidget()->setAutoFillBackground(true);
|
---|
85 | setAutoFillBackground(true);
|
---|
86 |
|
---|
87 | /* Prepare mini-toolbar: */
|
---|
88 | prepareMiniToolbar();
|
---|
89 | }
|
---|
90 |
|
---|
91 | void UIMachineWindowFullscreen::prepareMiniToolbar()
|
---|
92 | {
|
---|
93 | /* Get machine: */
|
---|
94 | CMachine m = machine();
|
---|
95 |
|
---|
96 | /* Make sure mini-toolbar is necessary: */
|
---|
97 | bool fIsActive = m.GetExtraData(GUI_ShowMiniToolBar) != "no";
|
---|
98 | if (!fIsActive)
|
---|
99 | return;
|
---|
100 |
|
---|
101 | /* Get the mini-toolbar alignment: */
|
---|
102 | bool fIsAtTop = m.GetExtraData(GUI_MiniToolBarAlignment) == "top";
|
---|
103 | /* Get the mini-toolbar auto-hide feature availability: */
|
---|
104 | bool fIsAutoHide = m.GetExtraData(GUI_MiniToolBarAutoHide) != "off";
|
---|
105 | /* Create mini-toolbar: */
|
---|
106 | m_pMiniToolBar = new UIRuntimeMiniToolBar(this,
|
---|
107 | fIsAtTop ? Qt::AlignTop : Qt::AlignBottom,
|
---|
108 | IntegrationMode_Embedded,
|
---|
109 | fIsAutoHide);
|
---|
110 | QList<QMenu*> menus;
|
---|
111 | QList<QAction*> actions = uisession()->newMenu()->actions();
|
---|
112 | for (int i=0; i < actions.size(); ++i)
|
---|
113 | menus << actions.at(i)->menu();
|
---|
114 | m_pMiniToolBar->addMenus(menus);
|
---|
115 | connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized()));
|
---|
116 | connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
|
---|
117 | gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger()));
|
---|
118 | connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
|
---|
119 | gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger()));
|
---|
120 | }
|
---|
121 |
|
---|
122 | void UIMachineWindowFullscreen::cleanupMiniToolbar()
|
---|
123 | {
|
---|
124 | /* Make sure mini-toolbar was created: */
|
---|
125 | if (!m_pMiniToolBar)
|
---|
126 | return;
|
---|
127 |
|
---|
128 | /* Save mini-toolbar settings: */
|
---|
129 | machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->autoHide() ? QString() : "off");
|
---|
130 | /* Delete mini-toolbar: */
|
---|
131 | delete m_pMiniToolBar;
|
---|
132 | m_pMiniToolBar = 0;
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UIMachineWindowFullscreen::cleanupVisualState()
|
---|
136 | {
|
---|
137 | /* Cleanup mini-toolbar: */
|
---|
138 | cleanupMiniToolbar();
|
---|
139 |
|
---|
140 | /* Call to base-class: */
|
---|
141 | UIMachineWindow::cleanupVisualState();
|
---|
142 | }
|
---|
143 |
|
---|
144 | void UIMachineWindowFullscreen::cleanupMenu()
|
---|
145 | {
|
---|
146 | /* Cleanup menu: */
|
---|
147 | delete m_pMainMenu;
|
---|
148 | m_pMainMenu = 0;
|
---|
149 |
|
---|
150 | /* Call to base-class: */
|
---|
151 | UIMachineWindow::cleanupMenu();
|
---|
152 | }
|
---|
153 |
|
---|
154 | void UIMachineWindowFullscreen::placeOnScreen()
|
---|
155 | {
|
---|
156 | /* Get corresponding screen: */
|
---|
157 | int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
|
---|
158 | /* Calculate working area: */
|
---|
159 | QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
|
---|
160 | /* Move to the appropriate position: */
|
---|
161 | move(workingArea.topLeft());
|
---|
162 | /* Resize to the appropriate size: */
|
---|
163 | resize(workingArea.size());
|
---|
164 | /* Move mini-toolbar into appropriate place: */
|
---|
165 | if (m_pMiniToolBar)
|
---|
166 | m_pMiniToolBar->adjustGeometry();
|
---|
167 | /* Process pending move & resize events: */
|
---|
168 | qApp->processEvents();
|
---|
169 | }
|
---|
170 |
|
---|
171 | void UIMachineWindowFullscreen::showInNecessaryMode()
|
---|
172 | {
|
---|
173 | /* Should we show window?: */
|
---|
174 | if (uisession()->isScreenVisible(m_uScreenId))
|
---|
175 | {
|
---|
176 | /* Do we have the seamless logic? */
|
---|
177 | if (UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic()))
|
---|
178 | {
|
---|
179 | /* Is this guest screen has own host screen? */
|
---|
180 | if (pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
|
---|
181 | {
|
---|
182 | /* Make sure the window is placed on valid screen
|
---|
183 | * before we are show fullscreen window: */
|
---|
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 window fullscreen: */
|
---|
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 due to X11 Window Geometry Rules. */
|
---|
201 | placeOnScreen();
|
---|
202 |
|
---|
203 | #ifdef Q_WS_MAC
|
---|
204 | /* Make sure it is really on the right place (especially on the Mac): */
|
---|
205 | QRect r = QApplication::desktop()->screenGeometry(qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));
|
---|
206 | move(r.topLeft());
|
---|
207 | #endif /* Q_WS_MAC */
|
---|
208 |
|
---|
209 | /* Return early: */
|
---|
210 | return;
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | /* Hide in other cases: */
|
---|
215 | hide();
|
---|
216 | }
|
---|
217 |
|
---|
218 | void 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 |
|
---|