VirtualBox

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

Last change on this file since 44954 was 44954, checked in by vboxsync, 12 years ago

FE/Qt: Runtime UI: Mac OS multi-screen menu-bar support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 44954 2013-03-07 13:34:21Z 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 "VBoxMiniToolBar.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
40UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
41 : UIMachineWindow(pMachineLogic, uScreenId)
42 , m_pMainMenu(0)
43 , m_pMiniToolBar(0)
44{
45}
46
47void UIMachineWindowFullscreen::sltMachineStateChanged()
48{
49 /* Call to base-class: */
50 UIMachineWindow::sltMachineStateChanged();
51
52 /* Update mini-toolbar: */
53 updateAppearanceOf(UIVisualElement_MiniToolBar);
54}
55
56void 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
66void UIMachineWindowFullscreen::prepareMenu()
67{
68 /* Call to base-class: */
69 UIMachineWindow::prepareMenu();
70
71 /* Prepare menu: */
72 m_pMainMenu = uisession()->newMenu();
73}
74
75void 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
91void 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 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(),
106 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
107 true, fIsAutoHide);
108 m_pMiniToolBar->updateDisplay(true, true);
109 QList<QMenu*> menus;
110 QList<QAction*> actions = uisession()->newMenu()->actions();
111 for (int i=0; i < actions.size(); ++i)
112 menus << actions.at(i)->menu();
113 *m_pMiniToolBar << menus;
114 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized()));
115 connect(m_pMiniToolBar, SIGNAL(exitAction()),
116 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger()));
117 connect(m_pMiniToolBar, SIGNAL(closeAction()),
118 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger()));
119}
120
121void UIMachineWindowFullscreen::cleanupMiniToolbar()
122{
123 /* Make sure mini-toolbar was created: */
124 if (!m_pMiniToolBar)
125 return;
126
127 /* Save mini-toolbar settings: */
128 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off");
129 /* Delete mini-toolbar: */
130 delete m_pMiniToolBar;
131 m_pMiniToolBar = 0;
132}
133
134void UIMachineWindowFullscreen::cleanupVisualState()
135{
136 /* Cleanup mini-toolbar: */
137 cleanupMiniToolbar();
138
139 /* Call to base-class: */
140 UIMachineWindow::cleanupVisualState();
141}
142
143void UIMachineWindowFullscreen::cleanupMenu()
144{
145 /* Cleanup menu: */
146 delete m_pMainMenu;
147 m_pMainMenu = 0;
148
149 /* Call to base-class: */
150 UIMachineWindow::cleanupMenu();
151}
152
153void UIMachineWindowFullscreen::placeOnScreen()
154{
155 /* Get corresponding screen: */
156 int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
157 /* Calculate working area: */
158 QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
159 /* Move to the appropriate position: */
160 move(workingArea.topLeft());
161 /* Resize to the appropriate size: */
162 resize(workingArea.size());
163 /* Process pending move & resize events: */
164 qApp->processEvents();
165}
166
167void UIMachineWindowFullscreen::showInNecessaryMode()
168{
169 /* Should we show window?: */
170 if (uisession()->isScreenVisible(m_uScreenId))
171 {
172 /* Do we have the seamless logic? */
173 if (UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic()))
174 {
175 /* Is this guest screen has own host screen? */
176 if (pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
177 {
178 /* Make sure the window is placed on valid screen
179 * before we are show fullscreen window: */
180 placeOnScreen();
181
182#ifdef Q_WS_WIN
183 /* On Windows we should activate main window first,
184 * because entering fullscreen there doesn't means window will be auto-activated,
185 * so no window-activation event will be received
186 * and no keyboard-hook created otherwise... */
187 if (m_uScreenId == 0)
188 setWindowState(windowState() | Qt::WindowActive);
189#endif /* Q_WS_WIN */
190
191 /* Show window fullscreen: */
192 showFullScreen();
193
194 /* Make sure the window is placed on valid screen again
195 * after window is shown & window's decorations applied.
196 * That is required due to X11 Window Geometry Rules. */
197 placeOnScreen();
198
199#ifdef Q_WS_MAC
200 /* Make sure it is really on the right place (especially on the Mac): */
201 QRect r = QApplication::desktop()->screenGeometry(qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));
202 move(r.topLeft());
203#endif /* Q_WS_MAC */
204
205 /* Return early: */
206 return;
207 }
208 }
209 }
210 /* Hide in other cases: */
211 hide();
212}
213
214void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
215{
216 /* Call to base-class: */
217 UIMachineWindow::updateAppearanceOf(iElement);
218
219 /* Update mini-toolbar: */
220 if (iElement & UIVisualElement_MiniToolBar)
221 {
222 if (m_pMiniToolBar)
223 {
224 /* Get machine: */
225 const CMachine &m = machine();
226 /* Get snapshot(s): */
227 QString strSnapshotName;
228 if (m.GetSnapshotCount() > 0)
229 {
230 CSnapshot snapshot = m.GetCurrentSnapshot();
231 strSnapshotName = " (" + snapshot.GetName() + ")";
232 }
233 /* Update mini-toolbar text: */
234 m_pMiniToolBar->setDisplayText(m.GetName() + strSnapshotName);
235 }
236 }
237}
238
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