VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp@ 98669

Last change on this file since 98669 was 98669, checked in by vboxsync, 2 years ago

FE/Qt: bugref:10322: Runtime UI: Reworking CMachine wrapper usage step-by-step; Monitor count stuff first of all.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: UIMachineLogicScale.cpp 98669 2023-02-21 11:15:34Z 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
52UIMachineLogicScale::UIMachineLogicScale(UIMachine *pMachine)
53 : UIMachineLogic(pMachine)
54#ifndef VBOX_WS_MAC
55 , m_pPopupMenu(0)
56#endif /* !VBOX_WS_MAC */
57{
58}
59
60bool 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
74void 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
85void 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
101void 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
126void 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
140void 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 /* Acquire monitor count: */
153 ulong cMonitorCount = 0;
154 uimachine()->acquireMonitorCount(cMonitorCount);
155
156 /* Create machine window(s): */
157 for (ulong uScreenId = 0; uScreenId < cMonitorCount; ++ uScreenId)
158 addMachineWindow(UIMachineWindow::create(this, uScreenId));
159 /* Order machine window(s): */
160 for (ulong uScreenId = cMonitorCount; uScreenId > 0; -- uScreenId)
161 machineWindows()[uScreenId - 1]->raise();
162
163 /* Listen for frame-buffer resize: */
164 foreach (UIMachineWindow *pMachineWindow, machineWindows())
165 connect(pMachineWindow, &UIMachineWindow::sigFrameBufferResize,
166 this, &UIMachineLogicScale::sigFrameBufferResize);
167 emit sigFrameBufferResize();
168
169 /* Mark machine-window(s) created: */
170 setMachineWindowsCreated(true);
171}
172
173#ifndef VBOX_WS_MAC
174void UIMachineLogicScale::prepareMenu()
175{
176 /* Prepare popup-menu: */
177 m_pPopupMenu = new QIMenu;
178 AssertPtrReturnVoid(m_pPopupMenu);
179 {
180 /* Prepare popup-menu: */
181 foreach (QMenu *pMenu, actionPool()->menus())
182 m_pPopupMenu->addMenu(pMenu);
183 }
184}
185#endif /* !VBOX_WS_MAC */
186
187#ifndef VBOX_WS_MAC
188void UIMachineLogicScale::cleanupMenu()
189{
190 /* Cleanup popup-menu: */
191 delete m_pPopupMenu;
192 m_pPopupMenu = 0;
193}
194#endif /* !VBOX_WS_MAC */
195
196void UIMachineLogicScale::cleanupMachineWindows()
197{
198 /* Do not destroy machine-window(s) if they destroyed already: */
199 if (!isMachineWindowsCreated())
200 return;
201
202 /* Mark machine-window(s) destroyed: */
203 setMachineWindowsCreated(false);
204
205 /* Cleanup machine-window(s): */
206 foreach (UIMachineWindow *pMachineWindow, machineWindows())
207 UIMachineWindow::destroy(pMachineWindow);
208}
209
210void UIMachineLogicScale::cleanupActionConnections()
211{
212 /* "View" actions disconnections: */
213 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), &QAction::triggered,
214 this, &UIMachineLogicScale::sltChangeVisualStateToNormal);
215 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), &QAction::triggered,
216 this, &UIMachineLogicScale::sltChangeVisualStateToFullscreen);
217 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), &QAction::triggered,
218 this, &UIMachineLogicScale::sltChangeVisualStateToSeamless);
219
220 /* Call to base-class: */
221 UIMachineLogic::cleanupActionConnections();
222
223}
224
225void UIMachineLogicScale::cleanupActionGroups()
226{
227 /* Take care of view-action toggle state: */
228 UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
229 if (pActionScale->isChecked())
230 {
231 pActionScale->blockSignals(true);
232 pActionScale->setChecked(false);
233 pActionScale->blockSignals(false);
234 }
235
236 /* Allow 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
237 actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
238 UIExtraDataMetaDefs::RuntimeMenuViewActionType_Invalid);
239
240 /* Call to base-class: */
241 UIMachineLogic::cleanupActionGroups();
242}
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