1 | /* $Id: UIMachineWindowFullscreen.cpp 41486 2012-05-29 15:50:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineWindowFullscreen class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010-2012 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 | /* Global 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 | /* Local includes: */
|
---|
29 | #include "VBoxMiniToolBar.h"
|
---|
30 | #include "UISession.h"
|
---|
31 | #include "UIActionPoolRuntime.h"
|
---|
32 | #include "UIMachineLogicFullscreen.h"
|
---|
33 | #include "UIMachineWindowFullscreen.h"
|
---|
34 |
|
---|
35 | UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
|
---|
36 | : UIMachineWindow(pMachineLogic, uScreenId)
|
---|
37 | , m_pMainMenu(0)
|
---|
38 | , m_pMiniToolBar(0)
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 | void UIMachineWindowFullscreen::sltMachineStateChanged()
|
---|
43 | {
|
---|
44 | /* Call to base-class: */
|
---|
45 | UIMachineWindow::sltMachineStateChanged();
|
---|
46 |
|
---|
47 | /* Update mini-toolbar: */
|
---|
48 | updateAppearanceOf(UIVisualElement_MiniToolBar);
|
---|
49 | }
|
---|
50 |
|
---|
51 | void UIMachineWindowFullscreen::sltPlaceOnScreen()
|
---|
52 | {
|
---|
53 | /* Get corresponding screen: */
|
---|
54 | int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
|
---|
55 | /* Calculate working area: */
|
---|
56 | QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
|
---|
57 | /* Move to the appropriate position: */
|
---|
58 | move(workingArea.topLeft());
|
---|
59 | /* Resize to the appropriate size: */
|
---|
60 | resize(workingArea.size());
|
---|
61 | /* Process pending move & resize events: */
|
---|
62 | qApp->processEvents();
|
---|
63 | }
|
---|
64 |
|
---|
65 | void UIMachineWindowFullscreen::sltPopupMainMenu()
|
---|
66 | {
|
---|
67 | /* Popup main-menu if present: */
|
---|
68 | if (m_pMainMenu && !m_pMainMenu->isEmpty())
|
---|
69 | {
|
---|
70 | m_pMainMenu->popup(geometry().center());
|
---|
71 | QTimer::singleShot(0, m_pMainMenu, SLOT(sltSelectFirstAction()));
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | void UIMachineWindowFullscreen::prepareMenu()
|
---|
76 | {
|
---|
77 | /* Call to base-class: */
|
---|
78 | UIMachineWindow::prepareMenu();
|
---|
79 |
|
---|
80 | /* Prepare menu: */
|
---|
81 | #ifdef Q_WS_MAC
|
---|
82 | setMenuBar(uisession()->newMenuBar());
|
---|
83 | #endif /* Q_WS_MAC */
|
---|
84 | m_pMainMenu = uisession()->newMenu();
|
---|
85 | }
|
---|
86 |
|
---|
87 | void UIMachineWindowFullscreen::prepareVisualState()
|
---|
88 | {
|
---|
89 | /* Call to base-class: */
|
---|
90 | UIMachineWindow::prepareVisualState();
|
---|
91 |
|
---|
92 | /* The background has to go black: */
|
---|
93 | QPalette palette(centralWidget()->palette());
|
---|
94 | palette.setColor(centralWidget()->backgroundRole(), Qt::black);
|
---|
95 | centralWidget()->setPalette(palette);
|
---|
96 | centralWidget()->setAutoFillBackground(true);
|
---|
97 | setAutoFillBackground(true);
|
---|
98 |
|
---|
99 | /* Prepare mini-toolbar: */
|
---|
100 | prepareMiniToolbar();
|
---|
101 | }
|
---|
102 |
|
---|
103 | void UIMachineWindowFullscreen::prepareMiniToolbar()
|
---|
104 | {
|
---|
105 | /* Get machine: */
|
---|
106 | CMachine m = machine();
|
---|
107 |
|
---|
108 | /* Make sure mini-toolbar is necessary: */
|
---|
109 | bool fIsActive = m.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no";
|
---|
110 | if (!fIsActive)
|
---|
111 | return;
|
---|
112 |
|
---|
113 | /* Get the mini-toolbar alignment: */
|
---|
114 | bool fIsAtTop = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top";
|
---|
115 | /* Get the mini-toolbar auto-hide feature availability: */
|
---|
116 | bool fIsAutoHide = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off";
|
---|
117 | m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(),
|
---|
118 | fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
|
---|
119 | true, fIsAutoHide);
|
---|
120 | m_pMiniToolBar->updateDisplay(true, true);
|
---|
121 | QList<QMenu*> menus;
|
---|
122 | QList<QAction*> actions = uisession()->newMenu()->actions();
|
---|
123 | for (int i=0; i < actions.size(); ++i)
|
---|
124 | menus << actions.at(i)->menu();
|
---|
125 | *m_pMiniToolBar << menus;
|
---|
126 | connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized()));
|
---|
127 | connect(m_pMiniToolBar, SIGNAL(exitAction()),
|
---|
128 | gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger()));
|
---|
129 | connect(m_pMiniToolBar, SIGNAL(closeAction()),
|
---|
130 | gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger()));
|
---|
131 | }
|
---|
132 |
|
---|
133 | void UIMachineWindowFullscreen::cleanupMiniToolbar()
|
---|
134 | {
|
---|
135 | /* Make sure mini-toolbar was created: */
|
---|
136 | if (!m_pMiniToolBar)
|
---|
137 | return;
|
---|
138 |
|
---|
139 | /* Save mini-toolbar settings: */
|
---|
140 | machine().SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off");
|
---|
141 | /* Delete mini-toolbar: */
|
---|
142 | delete m_pMiniToolBar;
|
---|
143 | m_pMiniToolBar = 0;
|
---|
144 | }
|
---|
145 |
|
---|
146 | void UIMachineWindowFullscreen::cleanupVisualState()
|
---|
147 | {
|
---|
148 | /* Cleanup mini-toolbar: */
|
---|
149 | cleanupMiniToolbar();
|
---|
150 |
|
---|
151 | /* Call to base-class: */
|
---|
152 | UIMachineWindow::cleanupVisualState();
|
---|
153 | }
|
---|
154 |
|
---|
155 | void UIMachineWindowFullscreen::cleanupMenu()
|
---|
156 | {
|
---|
157 | /* Cleanup menu: */
|
---|
158 | delete m_pMainMenu;
|
---|
159 | m_pMainMenu = 0;
|
---|
160 |
|
---|
161 | /* Call to base-class: */
|
---|
162 | UIMachineWindow::cleanupMenu();
|
---|
163 | }
|
---|
164 |
|
---|
165 | void UIMachineWindowFullscreen::showInNecessaryMode()
|
---|
166 | {
|
---|
167 | /* Show window if we have to: */
|
---|
168 | if (shouldWeShowWindow())
|
---|
169 | {
|
---|
170 | /* Make sure the window is placed on valid screen
|
---|
171 | * before we are show fullscreen window: */
|
---|
172 | sltPlaceOnScreen();
|
---|
173 |
|
---|
174 | /* Show window fullscreen: */
|
---|
175 | showFullScreen();
|
---|
176 |
|
---|
177 | /* Make sure the window is placed on valid screen again
|
---|
178 | * after window is shown & window's decorations applied.
|
---|
179 | * That is required due to X11 Window Geometry Rules. */
|
---|
180 | sltPlaceOnScreen();
|
---|
181 |
|
---|
182 | #ifdef Q_WS_MAC
|
---|
183 | /* Make sure it is really on the right place (especially on the Mac): */
|
---|
184 | QRect r = QApplication::desktop()->screenGeometry(qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));
|
---|
185 | move(r.topLeft());
|
---|
186 | #endif /* Q_WS_MAC */
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
|
---|
191 | {
|
---|
192 | /* Call to base-class: */
|
---|
193 | UIMachineWindow::updateAppearanceOf(iElement);
|
---|
194 |
|
---|
195 | /* Update mini-toolbar: */
|
---|
196 | if (iElement & UIVisualElement_MiniToolBar)
|
---|
197 | {
|
---|
198 | if (m_pMiniToolBar)
|
---|
199 | {
|
---|
200 | /* Get machine: */
|
---|
201 | const CMachine &m = machine();
|
---|
202 | /* Get snapshot(s): */
|
---|
203 | QString strSnapshotName;
|
---|
204 | if (m.GetSnapshotCount() > 0)
|
---|
205 | {
|
---|
206 | CSnapshot snapshot = m.GetCurrentSnapshot();
|
---|
207 | strSnapshotName = " (" + snapshot.GetName() + ")";
|
---|
208 | }
|
---|
209 | /* Update mini-toolbar text: */
|
---|
210 | m_pMiniToolBar->setDisplayText(m.GetName() + strSnapshotName);
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|