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