1 | /* $Id: UIMachineLogicScale.cpp 63054 2016-08-05 15:37:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineLogicScale class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # ifndef VBOX_WS_MAC
|
---|
24 | # include <QTimer>
|
---|
25 | # endif /* !VBOX_WS_MAC */
|
---|
26 |
|
---|
27 | /* GUI includes: */
|
---|
28 | # include "VBoxGlobal.h"
|
---|
29 | # include "UIDesktopWidgetWatchdog.h"
|
---|
30 | # include "UIMessageCenter.h"
|
---|
31 | # include "UISession.h"
|
---|
32 | # include "UIActionPoolRuntime.h"
|
---|
33 | # include "UIMachineLogicScale.h"
|
---|
34 | # include "UIMachineWindow.h"
|
---|
35 | # include "UIShortcutPool.h"
|
---|
36 | # ifndef VBOX_WS_MAC
|
---|
37 | # include "QIMenu.h"
|
---|
38 | # else /* VBOX_WS_MAC */
|
---|
39 | # include "VBoxUtils.h"
|
---|
40 | # endif /* VBOX_WS_MAC */
|
---|
41 |
|
---|
42 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
43 |
|
---|
44 |
|
---|
45 | UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession)
|
---|
46 | : UIMachineLogic(pParent, pSession, UIVisualStateType_Scale)
|
---|
47 | #ifndef VBOX_WS_MAC
|
---|
48 | , m_pPopupMenu(0)
|
---|
49 | #endif /* !VBOX_WS_MAC */
|
---|
50 | {
|
---|
51 | }
|
---|
52 |
|
---|
53 | bool UIMachineLogicScale::checkAvailability()
|
---|
54 | {
|
---|
55 | /* Show the info message. */
|
---|
56 | const UIShortcut &shortcut =
|
---|
57 | gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
|
---|
58 | actionPool()->action(UIActionIndexRT_M_View_T_Scale)->shortcutExtraDataID());
|
---|
59 | const QString strHotKey = QString("Host+%1").arg(shortcut.toString());
|
---|
60 | if (!msgCenter().confirmGoingScale(strHotKey))
|
---|
61 | return false;
|
---|
62 |
|
---|
63 | return true;
|
---|
64 | }
|
---|
65 |
|
---|
66 | #ifndef VBOX_WS_MAC
|
---|
67 | void UIMachineLogicScale::sltInvokePopupMenu()
|
---|
68 | {
|
---|
69 | /* Popup main-menu if present: */
|
---|
70 | if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
|
---|
71 | {
|
---|
72 | m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
|
---|
73 | QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
|
---|
74 | }
|
---|
75 | }
|
---|
76 | #endif /* !VBOX_WS_MAC */
|
---|
77 |
|
---|
78 | void UIMachineLogicScale::sltHostScreenAvailableAreaChange()
|
---|
79 | {
|
---|
80 | #if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
|
---|
81 | /* Prevent handling if fake screen detected: */
|
---|
82 | if (gpDesktop->isFakeScreenDetected())
|
---|
83 | return;
|
---|
84 |
|
---|
85 | /* Make sure all machine-window(s) have previous but normalized geometry: */
|
---|
86 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
87 | pMachineWindow->restoreCachedGeometry();
|
---|
88 | #endif /* VBOX_WS_X11 && QT_VERSION >= 0x050000 */
|
---|
89 |
|
---|
90 | /* Call to base-class: */
|
---|
91 | UIMachineLogic::sltHostScreenAvailableAreaChange();
|
---|
92 | }
|
---|
93 |
|
---|
94 | void UIMachineLogicScale::prepareActionGroups()
|
---|
95 | {
|
---|
96 | /* Call to base-class: */
|
---|
97 | UIMachineLogic::prepareActionGroups();
|
---|
98 |
|
---|
99 | /* Restrict 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
|
---|
100 | actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
|
---|
101 | (UIExtraDataMetaDefs::RuntimeMenuViewActionType)
|
---|
102 | (UIExtraDataMetaDefs::RuntimeMenuViewActionType_AdjustWindow |
|
---|
103 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_GuestAutoresize |
|
---|
104 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_MenuBar |
|
---|
105 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_StatusBar |
|
---|
106 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_Resize |
|
---|
107 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_ScaleFactor));
|
---|
108 |
|
---|
109 | /* Take care of view-action toggle state: */
|
---|
110 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
111 | if (!pActionScale->isChecked())
|
---|
112 | {
|
---|
113 | pActionScale->blockSignals(true);
|
---|
114 | pActionScale->setChecked(true);
|
---|
115 | pActionScale->blockSignals(false);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | void UIMachineLogicScale::prepareActionConnections()
|
---|
120 | {
|
---|
121 | /* Call to base-class: */
|
---|
122 | UIMachineLogic::prepareActionConnections();
|
---|
123 |
|
---|
124 | /* Prepare 'View' actions connections: */
|
---|
125 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
126 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
127 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
128 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
129 | connect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
130 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
131 | }
|
---|
132 |
|
---|
133 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
134 | {
|
---|
135 | /* Do not create machine-window(s) if they created already: */
|
---|
136 | if (isMachineWindowsCreated())
|
---|
137 | return;
|
---|
138 |
|
---|
139 | #ifdef VBOX_WS_MAC // TODO: Is that really need here?
|
---|
140 | /* We have to make sure that we are getting the front most process.
|
---|
141 | * This is necessary for Qt versions > 4.3.3: */
|
---|
142 | ::darwinSetFrontMostProcess();
|
---|
143 | #endif /* VBOX_WS_MAC */
|
---|
144 |
|
---|
145 | /* Get monitors count: */
|
---|
146 | ulong uMonitorCount = machine().GetMonitorCount();
|
---|
147 | /* Create machine window(s): */
|
---|
148 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
149 | addMachineWindow(UIMachineWindow::create(this, uScreenId));
|
---|
150 | /* Order machine window(s): */
|
---|
151 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
152 | machineWindows()[uScreenId - 1]->raise();
|
---|
153 |
|
---|
154 | /* Listen for frame-buffer resize: */
|
---|
155 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
156 | connect(pMachineWindow, SIGNAL(sigFrameBufferResize()),
|
---|
157 | this, SIGNAL(sigFrameBufferResize()));
|
---|
158 | emit sigFrameBufferResize();
|
---|
159 |
|
---|
160 | /* Mark machine-window(s) created: */
|
---|
161 | setMachineWindowsCreated(true);
|
---|
162 | }
|
---|
163 |
|
---|
164 | #ifndef VBOX_WS_MAC
|
---|
165 | void UIMachineLogicScale::prepareMenu()
|
---|
166 | {
|
---|
167 | /* Prepare popup-menu: */
|
---|
168 | m_pPopupMenu = new QIMenu;
|
---|
169 | AssertPtrReturnVoid(m_pPopupMenu);
|
---|
170 | {
|
---|
171 | /* Prepare popup-menu: */
|
---|
172 | foreach (QMenu *pMenu, actionPool()->menus())
|
---|
173 | m_pPopupMenu->addMenu(pMenu);
|
---|
174 | }
|
---|
175 | }
|
---|
176 | #endif /* !VBOX_WS_MAC */
|
---|
177 |
|
---|
178 | #ifndef VBOX_WS_MAC
|
---|
179 | void UIMachineLogicScale::cleanupMenu()
|
---|
180 | {
|
---|
181 | /* Cleanup popup-menu: */
|
---|
182 | delete m_pPopupMenu;
|
---|
183 | m_pPopupMenu = 0;
|
---|
184 | }
|
---|
185 | #endif /* !VBOX_WS_MAC */
|
---|
186 |
|
---|
187 | void UIMachineLogicScale::cleanupMachineWindows()
|
---|
188 | {
|
---|
189 | /* Do not destroy machine-window(s) if they destroyed already: */
|
---|
190 | if (!isMachineWindowsCreated())
|
---|
191 | return;
|
---|
192 |
|
---|
193 | /* Mark machine-window(s) destroyed: */
|
---|
194 | setMachineWindowsCreated(false);
|
---|
195 |
|
---|
196 | /* Cleanup machine-window(s): */
|
---|
197 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
198 | UIMachineWindow::destroy(pMachineWindow);
|
---|
199 | }
|
---|
200 |
|
---|
201 | void UIMachineLogicScale::cleanupActionConnections()
|
---|
202 | {
|
---|
203 | /* "View" actions disconnections: */
|
---|
204 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), SIGNAL(triggered(bool)),
|
---|
205 | this, SLOT(sltChangeVisualStateToNormal()));
|
---|
206 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SIGNAL(triggered(bool)),
|
---|
207 | this, SLOT(sltChangeVisualStateToFullscreen()));
|
---|
208 | disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), SIGNAL(triggered(bool)),
|
---|
209 | this, SLOT(sltChangeVisualStateToSeamless()));
|
---|
210 |
|
---|
211 | /* Call to base-class: */
|
---|
212 | UIMachineLogic::cleanupActionConnections();
|
---|
213 |
|
---|
214 | }
|
---|
215 |
|
---|
216 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
217 | {
|
---|
218 | /* Take care of view-action toggle state: */
|
---|
219 | UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
|
---|
220 | if (pActionScale->isChecked())
|
---|
221 | {
|
---|
222 | pActionScale->blockSignals(true);
|
---|
223 | pActionScale->setChecked(false);
|
---|
224 | pActionScale->blockSignals(false);
|
---|
225 | }
|
---|
226 |
|
---|
227 | /* Allow 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
|
---|
228 | actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
|
---|
229 | UIExtraDataMetaDefs::RuntimeMenuViewActionType_Invalid);
|
---|
230 |
|
---|
231 | /* Call to base-class: */
|
---|
232 | UIMachineLogic::cleanupActionGroups();
|
---|
233 | }
|
---|
234 |
|
---|