VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp@ 104158

Last change on this file since 104158 was 103538, checked in by vboxsync, 11 months ago

FE/Qt: Moving out logging stuff from UIDefs.h to separate UILoggingDefs.h; This breaks dependency of UIDefs/UICommon headers from VBox/log.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: UIMachineViewFullscreen.cpp 103538 2024-02-22 17:06:26Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineViewFullscreen 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#include <QApplication>
30#include <QMainWindow>
31#include <QTimer>
32#ifdef VBOX_WS_MAC
33# include <QMenuBar>
34#endif
35
36/* GUI includes: */
37#include "UIActionPoolRuntime.h"
38#include "UIDesktopWidgetWatchdog.h"
39#include "UIExtraDataManager.h"
40#include "UIFrameBuffer.h"
41#include "UILoggingDefs.h"
42#include "UIMachine.h"
43#include "UIMachineLogicFullscreen.h"
44#include "UIMachineViewFullscreen.h"
45#include "UIMachineWindow.h"
46
47/* External includes: */
48#ifdef VBOX_WS_NIX
49# include <limits.h>
50#endif
51
52
53UIMachineViewFullscreen::UIMachineViewFullscreen(UIMachineWindow *pMachineWindow, ulong uScreenId)
54 : UIMachineView(pMachineWindow, uScreenId)
55 , m_fGuestAutoresizeEnabled(actionPool()->action(UIActionIndexRT_M_View_T_GuestAutoresize)->isChecked())
56{
57}
58
59void UIMachineViewFullscreen::sltAdditionsStateChanged()
60{
61 adjustGuestScreenSize();
62}
63
64bool UIMachineViewFullscreen::eventFilter(QObject *pWatched, QEvent *pEvent)
65{
66 if (pWatched != 0 && pWatched == machineWindow())
67 {
68 switch (pEvent->type())
69 {
70 case QEvent::Resize:
71 {
72 /* Send guest-resize hint only if top window resizing to required dimension: */
73 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
74 if (pResizeEvent->size() != calculateMaxGuestSize())
75 break;
76
77 /* Recalculate maximum guest size: */
78 setMaximumGuestSize();
79
80 break;
81 }
82 default:
83 break;
84 }
85 }
86
87 return UIMachineView::eventFilter(pWatched, pEvent);
88}
89
90void UIMachineViewFullscreen::prepareCommon()
91{
92 /* Base class common settings: */
93 UIMachineView::prepareCommon();
94
95 /* Setup size-policy: */
96 setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
97 /* Maximum size to sizehint: */
98 setMaximumSize(sizeHint());
99 /* Minimum size is ignored: */
100 setMinimumSize(0, 0);
101 /* No scrollbars: */
102 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
103 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
104}
105
106void UIMachineViewFullscreen::prepareFilters()
107{
108 /* Base class filters: */
109 UIMachineView::prepareFilters();
110}
111
112void UIMachineViewFullscreen::prepareConsoleConnections()
113{
114 /* Base class connections: */
115 UIMachineView::prepareConsoleConnections();
116
117 /* Guest additions state-change updater: */
118 connect(uimachine(), &UIMachine::sigAdditionsStateActualChange, this, &UIMachineViewFullscreen::sltAdditionsStateChanged);
119}
120
121void UIMachineViewFullscreen::setGuestAutoresizeEnabled(bool fEnabled)
122{
123 if (m_fGuestAutoresizeEnabled != fEnabled)
124 {
125 m_fGuestAutoresizeEnabled = fEnabled;
126
127 if (m_fGuestAutoresizeEnabled && uimachine()->isGuestSupportsGraphics())
128 sltPerformGuestResize();
129 }
130}
131
132void UIMachineViewFullscreen::adjustGuestScreenSize()
133{
134 /* Step 1: Is guest-screen visible? */
135 if (!uimachine()->isScreenVisible(screenId()))
136 {
137 LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
138 "Guest-screen #%d is not visible, adjustment is not required.\n",
139 screenId()));
140 return;
141 }
142 /* Step 2: Is guest-screen auto-resize enabled? */
143 if (!isGuestAutoresizeEnabled())
144 {
145 LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
146 "Guest-screen #%d auto-resize is disabled, adjustment is not required.\n",
147 screenId()));
148 return;
149 }
150
151 /* What are the desired and requested hints? */
152 const QSize sizeToApply = calculateMaxGuestSize();
153 const QSize desiredSizeHint = scaledBackward(sizeToApply);
154 const QSize requestedSizeHint = requestedGuestScreenSizeHint();
155
156 /* Step 3: Is the guest-screen of another size than necessary? */
157 if (desiredSizeHint == requestedSizeHint)
158 {
159 LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
160 "Desired hint %dx%d for guest-screen #%d is already in IDisplay, adjustment is not required.\n",
161 desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
162 return;
163 }
164
165 /* Final step: Adjust .. */
166 LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
167 "Desired hint %dx%d for guest-screen #%d differs from the one in IDisplay, adjustment is required.\n",
168 desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
169 sltPerformGuestResize(sizeToApply);
170 /* And remember the size to know what we are resizing out of when we exit: */
171 uimachine()->setLastFullScreenSize(screenId(), scaledForward(desiredSizeHint));
172}
173
174QRect UIMachineViewFullscreen::workingArea() const
175{
176 /* Get corresponding screen: */
177 int iScreen = static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(screenId());
178 /* Return available geometry for that screen: */
179 return gpDesktop->screenGeometry(iScreen);
180}
181
182QSize UIMachineViewFullscreen::calculateMaxGuestSize() const
183{
184 return workingArea().size();
185}
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