VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsDisplay.cpp@ 104158

Last change on this file since 104158 was 101717, checked in by vboxsync, 16 months ago

FE/Qt: bugref:10513: UIEditor and sub-classes: Simplify filterOut stuff; No need to pass everything through whole the hierarchy, enough to handle optional method only.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1/* $Id: UIGlobalSettingsDisplay.cpp 101717 2023-11-02 12:22:25Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGlobalSettingsDisplay class implementation.
4 */
5
6/*
7 * Copyright (C) 2012-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 <QVBoxLayout>
30
31/* GUI includes: */
32#include "UIDesktopWidgetWatchdog.h"
33#include "UIExtraDataManager.h"
34#include "UIFontScaleEditor.h"
35#include "UIDisplayFeaturesEditor.h"
36#include "UIGlobalSettingsDisplay.h"
37#include "UIMaximumGuestScreenSizeEditor.h"
38#include "UIScaleFactorEditor.h"
39
40
41/** Global settings: Display page data structure. */
42struct UIDataSettingsGlobalDisplay
43{
44 /** Constructs data. */
45 UIDataSettingsGlobalDisplay()
46 : m_fActivateHoveredMachineWindow(false)
47 , m_fDisableHostScreenSaver(false)
48 {}
49
50 /** Returns whether the @a other passed data is equal to this one. */
51 bool equal(const UIDataSettingsGlobalDisplay &other) const
52 {
53 return true
54 && (m_guiMaximumGuestScreenSizeValue == other.m_guiMaximumGuestScreenSizeValue)
55 && (m_scaleFactors == other.m_scaleFactors)
56 && (m_iFontScalingFactor == other.m_iFontScalingFactor)
57 && (m_fActivateHoveredMachineWindow == other.m_fActivateHoveredMachineWindow)
58 && (m_fDisableHostScreenSaver == other.m_fDisableHostScreenSaver)
59 ;
60 }
61
62 /** Returns whether the @a other passed data is equal to this one. */
63 bool operator==(const UIDataSettingsGlobalDisplay &other) const { return equal(other); }
64 /** Returns whether the @a other passed data is different from this one. */
65 bool operator!=(const UIDataSettingsGlobalDisplay &other) const { return !equal(other); }
66
67 /** Holds the maximum guest-screen size value. */
68 UIMaximumGuestScreenSizeValue m_guiMaximumGuestScreenSizeValue;
69 /** Holds the guest screen scale-factor. */
70 QList<double> m_scaleFactors;
71 /** Holds the font scaling factor. */
72 int m_iFontScalingFactor;
73 /** Holds whether we should automatically activate machine window under the mouse cursor. */
74 bool m_fActivateHoveredMachineWindow;
75 /** Holds whether we should disable host sceen saver on a vm is running. */
76 bool m_fDisableHostScreenSaver;
77};
78
79
80/*********************************************************************************************************************************
81* Class UIGlobalSettingsDisplay implementation. *
82*********************************************************************************************************************************/
83
84UIGlobalSettingsDisplay::UIGlobalSettingsDisplay()
85 : m_pCache(0)
86 , m_pEditorMaximumGuestScreenSize(0)
87 , m_pEditorScaleFactor(0)
88 , m_pFontScaleEditor(0)
89 , m_pEditorDisplayFeatures(0)
90{
91 prepare();
92}
93
94UIGlobalSettingsDisplay::~UIGlobalSettingsDisplay()
95{
96 cleanup();
97}
98
99bool UIGlobalSettingsDisplay::changed() const
100{
101 return m_pCache ? m_pCache->wasChanged() : false;
102}
103
104void UIGlobalSettingsDisplay::loadToCacheFrom(QVariant &data)
105{
106 /* Sanity check: */
107 if (!m_pCache)
108 return;
109
110 /* Fetch data to properties: */
111 UISettingsPageGlobal::fetchData(data);
112
113 /* Clear cache initially: */
114 m_pCache->clear();
115
116 /* Cache old data: */
117 UIDataSettingsGlobalDisplay oldData;
118 oldData.m_guiMaximumGuestScreenSizeValue = UIMaximumGuestScreenSizeValue(gEDataManager->maxGuestResolutionPolicy(),
119 gEDataManager->maxGuestResolutionForPolicyFixed());
120 oldData.m_scaleFactors = gEDataManager->scaleFactors(UIExtraDataManager::GlobalID);
121 oldData.m_iFontScalingFactor = gEDataManager->fontScaleFactor();
122 oldData.m_fActivateHoveredMachineWindow = gEDataManager->activateHoveredMachineWindow();
123#if defined(VBOX_WS_WIN) || defined(VBOX_WS_NIX)
124 oldData.m_fDisableHostScreenSaver = gEDataManager->disableHostScreenSaver();
125#endif
126 m_pCache->cacheInitialData(oldData);
127
128 /* Upload properties to data: */
129 UISettingsPageGlobal::uploadData(data);
130}
131
132void UIGlobalSettingsDisplay::getFromCache()
133{
134 /* Sanity check: */
135 if (!m_pCache)
136 return;
137
138 /* Load old data from cache: */
139 const UIDataSettingsGlobalDisplay &oldData = m_pCache->base();
140 if (m_pEditorMaximumGuestScreenSize)
141 m_pEditorMaximumGuestScreenSize->setValue(oldData.m_guiMaximumGuestScreenSizeValue);
142 if (m_pEditorScaleFactor)
143 {
144 m_pEditorScaleFactor->setScaleFactors(oldData.m_scaleFactors);
145 m_pEditorScaleFactor->setMonitorCount(UIDesktopWidgetWatchdog::screenCount());
146 }
147 if (m_pFontScaleEditor)
148 m_pFontScaleEditor->setFontScaleFactor(oldData.m_iFontScalingFactor);
149 if (m_pEditorDisplayFeatures)
150 {
151 m_pEditorDisplayFeatures->setActivateOnMouseHover(oldData.m_fActivateHoveredMachineWindow);
152 m_pEditorDisplayFeatures->setDisableHostScreenSaver(oldData.m_fDisableHostScreenSaver);
153 }
154}
155
156void UIGlobalSettingsDisplay::putToCache()
157{
158 /* Sanity check: */
159 if (!m_pCache)
160 return;
161
162 /* Prepare new data: */
163 UIDataSettingsGlobalDisplay newData = m_pCache->base();
164
165 /* Cache new data: */
166 if (m_pEditorMaximumGuestScreenSize)
167 newData.m_guiMaximumGuestScreenSizeValue = m_pEditorMaximumGuestScreenSize->value();
168 if (m_pEditorScaleFactor)
169 newData.m_scaleFactors = m_pEditorScaleFactor->scaleFactors();
170 if (m_pFontScaleEditor)
171 newData.m_iFontScalingFactor = m_pFontScaleEditor->fontScaleFactor();
172 if (m_pEditorDisplayFeatures)
173 {
174 newData.m_fActivateHoveredMachineWindow = m_pEditorDisplayFeatures->activateOnMouseHover();
175 newData.m_fDisableHostScreenSaver = m_pEditorDisplayFeatures->disableHostScreenSaver();
176 }
177 m_pCache->cacheCurrentData(newData);
178}
179
180void UIGlobalSettingsDisplay::saveFromCacheTo(QVariant &data)
181{
182 /* Fetch data to properties: */
183 UISettingsPageGlobal::fetchData(data);
184
185 /* Update data and failing state: */
186 setFailed(!saveData());
187
188 /* Upload properties to data: */
189 UISettingsPageGlobal::uploadData(data);
190}
191
192void UIGlobalSettingsDisplay::retranslateUi()
193{
194 updateMinimumLayoutHint();
195}
196
197void UIGlobalSettingsDisplay::handleFilterChange()
198{
199 updateMinimumLayoutHint();
200}
201
202void UIGlobalSettingsDisplay::prepare()
203{
204 /* Prepare cache: */
205 m_pCache = new UISettingsCacheGlobalDisplay;
206 AssertPtrReturnVoid(m_pCache);
207
208 /* Prepare everything: */
209 prepareWidgets();
210
211 /* Apply language settings: */
212 retranslateUi();
213}
214
215void UIGlobalSettingsDisplay::prepareWidgets()
216{
217 /* Prepare main layout: */
218 QVBoxLayout *pLayout = new QVBoxLayout(this);
219 if (pLayout)
220 {
221 /* Prepare 'maximum guest screen size' editor: */
222 m_pEditorMaximumGuestScreenSize = new UIMaximumGuestScreenSizeEditor(this);
223 if (m_pEditorMaximumGuestScreenSize)
224 {
225 addEditor(m_pEditorMaximumGuestScreenSize);
226 pLayout->addWidget(m_pEditorMaximumGuestScreenSize);
227 }
228
229 /* Prepare 'scale-factor' editor: */
230 m_pEditorScaleFactor = new UIScaleFactorEditor(this);
231 if (m_pEditorScaleFactor)
232 {
233 addEditor(m_pEditorScaleFactor);
234 pLayout->addWidget(m_pEditorScaleFactor);
235 }
236
237 /* Prepare 'font scale' editor: */
238 m_pFontScaleEditor = new UIFontScaleEditor(this);
239 if (m_pFontScaleEditor)
240 {
241 addEditor(m_pFontScaleEditor);
242 pLayout->addWidget(m_pFontScaleEditor);
243 }
244
245 /* Prepare 'display features' editor: */
246 m_pEditorDisplayFeatures = new UIDisplayFeaturesEditor(this);
247 if (m_pEditorDisplayFeatures)
248 {
249 addEditor(m_pEditorDisplayFeatures);
250 pLayout->addWidget(m_pEditorDisplayFeatures);
251 }
252
253 /* Add stretch to the end: */
254 pLayout->addStretch();
255 }
256}
257
258void UIGlobalSettingsDisplay::cleanup()
259{
260 /* Cleanup cache: */
261 delete m_pCache;
262 m_pCache = 0;
263}
264
265bool UIGlobalSettingsDisplay::saveData()
266{
267 /* Sanity check: */
268 if (!m_pCache)
269 return false;
270
271 /* Prepare result: */
272 bool fSuccess = true;
273 /* Save display settings from cache: */
274 if ( fSuccess
275 && m_pCache->wasChanged())
276 {
277 /* Get old data from cache: */
278 const UIDataSettingsGlobalDisplay &oldData = m_pCache->base();
279 /* Get new data from cache: */
280 const UIDataSettingsGlobalDisplay &newData = m_pCache->data();
281
282 /* Save maximum guest screen size and policy: */
283 if ( fSuccess
284 && newData.m_guiMaximumGuestScreenSizeValue != oldData.m_guiMaximumGuestScreenSizeValue)
285 /* fSuccess = */ gEDataManager->setMaxGuestScreenResolution(newData.m_guiMaximumGuestScreenSizeValue.m_enmPolicy,
286 newData.m_guiMaximumGuestScreenSizeValue.m_size);
287 /* Save guest-screen scale-factor: */
288 if ( fSuccess
289 && newData.m_scaleFactors != oldData.m_scaleFactors)
290 /* fSuccess = */ gEDataManager->setScaleFactors(newData.m_scaleFactors, UIExtraDataManager::GlobalID);
291 /* Save font scale factor: */
292 if ( fSuccess
293 && newData.m_iFontScalingFactor != oldData.m_iFontScalingFactor)
294 /* fSuccess = */ gEDataManager->setFontScaleFactor(newData.m_iFontScalingFactor);
295 /* Save whether hovered machine-window should be activated automatically: */
296 if ( fSuccess
297 && newData.m_fActivateHoveredMachineWindow != oldData.m_fActivateHoveredMachineWindow)
298 /* fSuccess = */ gEDataManager->setActivateHoveredMachineWindow(newData.m_fActivateHoveredMachineWindow);
299#if defined(VBOX_WS_WIN) || defined(VBOX_WS_NIX)
300 /* Save whether the host screen saver is to be disable when a vm is running: */
301 if ( fSuccess
302 && newData.m_fDisableHostScreenSaver != oldData.m_fDisableHostScreenSaver)
303 /* fSuccess = */ gEDataManager->setDisableHostScreenSaver(newData.m_fDisableHostScreenSaver);
304#endif /* VBOX_WS_WIN || VBOX_WS_NIX */
305 }
306 /* Return result: */
307 return fSuccess;
308}
309
310void UIGlobalSettingsDisplay::updateMinimumLayoutHint()
311{
312 /* These editors have own labels, but we want them to be properly layouted according to each other: */
313 int iMinimumLayoutHint = 0;
314 if (m_pEditorMaximumGuestScreenSize && !m_pEditorMaximumGuestScreenSize->isHidden())
315 iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorMaximumGuestScreenSize->minimumLabelHorizontalHint());
316 if (m_pEditorScaleFactor && !m_pEditorScaleFactor->isHidden())
317 iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorScaleFactor->minimumLabelHorizontalHint());
318 if (m_pFontScaleEditor && !m_pFontScaleEditor->isHidden())
319 iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pFontScaleEditor->minimumLabelHorizontalHint());
320 if (m_pEditorDisplayFeatures && !m_pEditorDisplayFeatures->isHidden())
321 iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorDisplayFeatures->minimumLabelHorizontalHint());
322 if (m_pEditorMaximumGuestScreenSize)
323 m_pEditorMaximumGuestScreenSize->setMinimumLayoutIndent(iMinimumLayoutHint);
324 if (m_pEditorScaleFactor)
325 m_pEditorScaleFactor->setMinimumLayoutIndent(iMinimumLayoutHint);
326 if (m_pFontScaleEditor)
327 m_pFontScaleEditor->setMinimumLayoutIndent(iMinimumLayoutHint);
328 if (m_pEditorDisplayFeatures)
329 m_pEditorDisplayFeatures->setMinimumLayoutIndent(iMinimumLayoutHint);
330}
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