VirtualBox

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

Last change on this file since 84698 was 84698, checked in by vboxsync, 5 years ago

FE/Qt: bugref:9753: Missed couple of bits in r138467.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette