VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 4 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: UIMachineLogicScale.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineLogicScale class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2024 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 "UIDesktopWidgetWatchdog.h"
36#include "UIMachine.h"
37#include "UIMachineLogicScale.h"
38#include "UIMachineWindow.h"
39#include "UIMessageCenter.h"
40#include "UIShortcutPool.h"
41#ifndef VBOX_WS_MAC
42# include "QIMenu.h"
43#else
44# include "VBoxUtils.h"
45#endif
46
47/* COM includes: */
48#include "CGraphicsAdapter.h"
49
50
51UIMachineLogicScale::UIMachineLogicScale(UIMachine *pMachine)
52 : UIMachineLogic(pMachine)
53#ifndef VBOX_WS_MAC
54 , m_pPopupMenu(0)
55#endif /* !VBOX_WS_MAC */
56{
57}
58
59bool UIMachineLogicScale::checkAvailability()
60{
61 /* Show the info message. */
62 const UIShortcut &shortcut =
63 gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
64 actionPool()->action(UIActionIndexRT_M_View_T_Scale)->shortcutExtraDataID());
65 const QString strHotKey = QString("Host+%1").arg(shortcut.primaryToPortableText());
66 if (!msgCenter().confirmGoingScale(strHotKey))
67 return false;
68
69 return true;
70}
71
72#ifndef VBOX_WS_MAC
73void UIMachineLogicScale::sltInvokePopupMenu()
74{
75 /* Popup main-menu if present: */
76 if (m_pPopupMenu && !m_pPopupMenu->isEmpty())
77 {
78 m_pPopupMenu->popup(activeMachineWindow()->geometry().center());
79 QTimer::singleShot(0, m_pPopupMenu, SLOT(sltHighlightFirstAction()));
80 }
81}
82#endif /* !VBOX_WS_MAC */
83
84void UIMachineLogicScale::sltHostScreenAvailableAreaChange()
85{
86#ifdef VBOX_WS_NIX
87 /* Prevent handling if fake screen detected: */
88 if (UIDesktopWidgetWatchdog::isFakeScreenDetected())
89 return;
90
91 /* Make sure all machine-window(s) have previous but normalized geometry: */
92 foreach (UIMachineWindow *pMachineWindow, machineWindows())
93 pMachineWindow->restoreCachedGeometry();
94#endif /* VBOX_WS_NIX */
95
96 /* Call to base-class: */
97 UIMachineLogic::sltHostScreenAvailableAreaChange();
98}
99
100void UIMachineLogicScale::prepareActionGroups()
101{
102 /* Call to base-class: */
103 UIMachineLogic::prepareActionGroups();
104
105 /* Restrict 'Adjust Window', 'Guest Autoresize', 'Status Bar', 'Resize' and 'Rescale' actions for 'View' menu: */
106 actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
107 (UIExtraDataMetaDefs::RuntimeMenuViewActionType)
108 (UIExtraDataMetaDefs::RuntimeMenuViewActionType_AdjustWindow |
109 UIExtraDataMetaDefs::RuntimeMenuViewActionType_GuestAutoresize |
110 UIExtraDataMetaDefs::RuntimeMenuViewActionType_MenuBar |
111 UIExtraDataMetaDefs::RuntimeMenuViewActionType_StatusBar |
112 UIExtraDataMetaDefs::RuntimeMenuViewActionType_Resize |
113 UIExtraDataMetaDefs::RuntimeMenuViewActionType_Rescale));
114
115 /* Take care of view-action toggle state: */
116 UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
117 if (!pActionScale->isChecked())
118 {
119 pActionScale->blockSignals(true);
120 pActionScale->setChecked(true);
121 pActionScale->blockSignals(false);
122 }
123}
124
125void UIMachineLogicScale::prepareActionConnections()
126{
127 /* Call to base-class: */
128 UIMachineLogic::prepareActionConnections();
129
130 /* Prepare 'View' actions connections: */
131 connect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), &QAction::triggered,
132 this, &UIMachineLogicScale::sltChangeVisualStateToNormal);
133 connect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), &QAction::triggered,
134 this, &UIMachineLogicScale::sltChangeVisualStateToFullscreen);
135 connect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), &QAction::triggered,
136 this, &UIMachineLogicScale::sltChangeVisualStateToSeamless);
137}
138
139void UIMachineLogicScale::prepareMachineWindows()
140{
141 /* Do not create machine-window(s) if they created already: */
142 if (isMachineWindowsCreated())
143 return;
144
145#ifdef VBOX_WS_MAC /// @todo Is that really need here?
146 /* We have to make sure that we are getting the front most process.
147 * This is necessary for Qt versions > 4.3.3: */
148 ::darwinSetFrontMostProcess();
149#endif /* VBOX_WS_MAC */
150
151 /* Acquire monitor count: */
152 ulong cMonitorCount = 0;
153 uimachine()->acquireMonitorCount(cMonitorCount);
154
155 /* Create machine window(s): */
156 for (ulong uScreenId = 0; uScreenId < cMonitorCount; ++ uScreenId)
157 addMachineWindow(UIMachineWindow::create(this, uScreenId));
158 /* Order machine window(s): */
159 for (ulong uScreenId = cMonitorCount; uScreenId > 0; -- uScreenId)
160 machineWindows()[uScreenId - 1]->raise();
161
162 /* Mark machine-window(s) created: */
163 setMachineWindowsCreated(true);
164}
165
166#ifndef VBOX_WS_MAC
167void UIMachineLogicScale::prepareMenu()
168{
169 /* Prepare popup-menu: */
170 m_pPopupMenu = new QIMenu;
171 AssertPtrReturnVoid(m_pPopupMenu);
172 {
173 /* Prepare popup-menu: */
174 foreach (QMenu *pMenu, actionPool()->menus())
175 m_pPopupMenu->addMenu(pMenu);
176 }
177}
178#endif /* !VBOX_WS_MAC */
179
180#ifndef VBOX_WS_MAC
181void UIMachineLogicScale::cleanupMenu()
182{
183 /* Cleanup popup-menu: */
184 delete m_pPopupMenu;
185 m_pPopupMenu = 0;
186}
187#endif /* !VBOX_WS_MAC */
188
189void UIMachineLogicScale::cleanupMachineWindows()
190{
191 /* Do not destroy machine-window(s) if they destroyed already: */
192 if (!isMachineWindowsCreated())
193 return;
194
195 /* Mark machine-window(s) destroyed: */
196 setMachineWindowsCreated(false);
197
198 /* Cleanup machine-window(s): */
199 foreach (UIMachineWindow *pMachineWindow, machineWindows())
200 UIMachineWindow::destroy(pMachineWindow);
201}
202
203void UIMachineLogicScale::cleanupActionConnections()
204{
205 /* "View" actions disconnections: */
206 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Scale), &QAction::triggered,
207 this, &UIMachineLogicScale::sltChangeVisualStateToNormal);
208 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), &QAction::triggered,
209 this, &UIMachineLogicScale::sltChangeVisualStateToFullscreen);
210 disconnect(actionPool()->action(UIActionIndexRT_M_View_T_Seamless), &QAction::triggered,
211 this, &UIMachineLogicScale::sltChangeVisualStateToSeamless);
212
213 /* Call to base-class: */
214 UIMachineLogic::cleanupActionConnections();
215
216}
217
218void UIMachineLogicScale::cleanupActionGroups()
219{
220 /* Take care of view-action toggle state: */
221 UIAction *pActionScale = actionPool()->action(UIActionIndexRT_M_View_T_Scale);
222 if (pActionScale->isChecked())
223 {
224 pActionScale->blockSignals(true);
225 pActionScale->setChecked(false);
226 pActionScale->blockSignals(false);
227 }
228
229 /* Allow 'Adjust Window', 'Guest Autoresize', 'Status Bar' and 'Resize' actions for 'View' menu: */
230 actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Logic,
231 UIExtraDataMetaDefs::RuntimeMenuViewActionType_Invalid);
232
233 /* Call to base-class: */
234 UIMachineLogic::cleanupActionGroups();
235}
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