VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPage.cpp

Last change on this file was 104313, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the settings related GUI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/* $Id: UISettingsPage.cpp 104313 2024-04-12 13:10:30Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISettingsPage class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QLabel>
31#include <QPainter>
32#include <QPainterPath>
33#include <QPaintEvent>
34#include <QStyle>
35#include <QVariant>
36#include <QVBoxLayout>
37
38/* GUI includes: */
39#include "UICommon.h"
40#include "UIConverter.h"
41#include "UISettingsPage.h"
42#include "UISettingsPageValidator.h"
43
44
45/*********************************************************************************************************************************
46* Class UISettingsPage implementation. *
47*********************************************************************************************************************************/
48
49UISettingsPage::UISettingsPage()
50 : m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
51 , m_cId(-1)
52 , m_pFirstWidget(0)
53 , m_pValidator(0)
54 , m_fIsValidatorBlocked(true)
55 , m_fProcessed(false)
56 , m_fFailed(false)
57{
58}
59
60void UISettingsPage::notifyOperationProgressError(const QString &strErrorInfo)
61{
62 QMetaObject::invokeMethod(this,
63 "sigOperationProgressError",
64 Qt::BlockingQueuedConnection,
65 Q_ARG(QString, strErrorInfo));
66}
67
68void UISettingsPage::setValidator(UISettingsPageValidator *pValidator)
69{
70 /* Make sure validator is not yet assigned: */
71 AssertMsg(!m_pValidator, ("Validator already assigned!\n"));
72 if (m_pValidator)
73 return;
74
75 /* Assign validator: */
76 m_pValidator = pValidator;
77}
78
79void UISettingsPage::setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel)
80{
81 m_enmConfigurationAccessLevel = enmConfigurationAccessLevel;
82 polishPage();
83}
84
85void UISettingsPage::revalidate()
86{
87 /* Invalidate validator if allowed: */
88 if (!m_fIsValidatorBlocked && m_pValidator)
89 m_pValidator->invalidate();
90}
91
92
93/*********************************************************************************************************************************
94* Class UISettingsPageGlobal implementation. *
95*********************************************************************************************************************************/
96
97UISettingsPageGlobal::UISettingsPageGlobal()
98{
99}
100
101GlobalSettingsPageType UISettingsPageGlobal::internalID() const
102{
103 return static_cast<GlobalSettingsPageType>(id());
104}
105
106QString UISettingsPageGlobal::internalName() const
107{
108 return gpConverter->toInternalString(internalID());
109}
110
111QPixmap UISettingsPageGlobal::warningPixmap() const
112{
113 return gpConverter->toWarningPixmap(internalID());
114}
115
116void UISettingsPageGlobal::fetchData(const QVariant &data)
117{
118 /* Fetch data to m_host & m_properties: */
119 m_host = data.value<UISettingsDataGlobal>().m_host;
120 m_properties = data.value<UISettingsDataGlobal>().m_properties;
121}
122
123void UISettingsPageGlobal::uploadData(QVariant &data) const
124{
125 /* Upload m_host & m_properties to data: */
126 data = QVariant::fromValue(UISettingsDataGlobal(m_host, m_properties));
127}
128
129
130/*********************************************************************************************************************************
131* Class UISettingsPageMachine implementation. *
132*********************************************************************************************************************************/
133
134UISettingsPageMachine::UISettingsPageMachine()
135{
136}
137
138MachineSettingsPageType UISettingsPageMachine::internalID() const
139{
140 return static_cast<MachineSettingsPageType>(id());
141}
142
143QString UISettingsPageMachine::internalName() const
144{
145 return gpConverter->toInternalString(internalID());
146}
147
148QPixmap UISettingsPageMachine::warningPixmap() const
149{
150 return gpConverter->toWarningPixmap(internalID());
151}
152
153void UISettingsPageMachine::fetchData(const QVariant &data)
154{
155 /* Fetch data to m_machine & m_console: */
156 m_machine = data.value<UISettingsDataMachine>().m_machine;
157 m_console = data.value<UISettingsDataMachine>().m_console;
158}
159
160void UISettingsPageMachine::uploadData(QVariant &data) const
161{
162 /* Upload m_machine & m_console to data: */
163 data = QVariant::fromValue(UISettingsDataMachine(m_machine, m_console));
164}
165
166
167/*********************************************************************************************************************************
168* Class UISettingsPageFrame implementation. *
169*********************************************************************************************************************************/
170
171UISettingsPageFrame::UISettingsPageFrame(UISettingsPage *pPage, QWidget *pParent /* = 0 */)
172 : UIEditor(pParent)
173 , m_pPage(pPage)
174 , m_pLabelName(0)
175 , m_pWidget(0)
176 , m_pLayout(0)
177{
178 prepare();
179}
180
181void UISettingsPageFrame::setName(const QString &strName)
182{
183 if (m_strName == strName)
184 return;
185
186 m_strName = strName;
187 if (m_pLabelName)
188 m_pLabelName->setText(m_strName);
189}
190
191void UISettingsPageFrame::sltRetranslateUI()
192{
193 // No NLS tags for now; We are receiving our name through the getter.
194}
195
196void UISettingsPageFrame::paintEvent(QPaintEvent *pPaintEvent)
197{
198 /* Prepare painter: */
199 QPainter painter(this);
200 painter.setRenderHint(QPainter::Antialiasing);
201 painter.setRenderHint(QPainter::TextAntialiasing);
202 /* Avoid painting more than necessary: */
203 painter.setClipRect(pPaintEvent->rect());
204
205 /* Prepare colors: */
206 const bool fActive = window() && window()->isActiveWindow();
207 QColor col1;
208 QColor col2;
209 if (uiCommon().isInDarkMode())
210 {
211 col1 = qApp->palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).lighter(130);
212 col2 = qApp->palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).lighter(150);
213 }
214 else
215 {
216 col1 = qApp->palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).darker(105);
217 col2 = qApp->palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).darker(120);
218 }
219
220 /* Prepare painter path: */
221 const QRect widgetRect = rect();
222 QPainterPath path;
223 int iRadius = 6;
224 QSizeF arcSize(2 * iRadius, 2 * iRadius);
225 path.moveTo(widgetRect.x() + iRadius, widgetRect.y());
226 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iRadius, 0), 90, 90);
227 path.lineTo(path.currentPosition().x(), widgetRect.height() - iRadius);
228 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -iRadius), 180, 90);
229 path.lineTo(widgetRect.width() - iRadius, path.currentPosition().y());
230 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iRadius, -2 * iRadius), 270, 90);
231 path.lineTo(path.currentPosition().x(), widgetRect.y() + iRadius);
232 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * iRadius, -iRadius), 0, 90);
233 path.closeSubpath();
234
235 /* Painting stuff: */
236 painter.fillPath(path, col1);
237 painter.strokePath(path, col2);
238}
239
240void UISettingsPageFrame::prepare()
241{
242 /* Keep minimum vertical size: */
243 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
244
245 /* Create main layout: */
246 QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
247 if (pLayoutMain)
248 {
249 /* Create name label: */
250 m_pLabelName = new QLabel(this);
251 if (m_pLabelName)
252 {
253 QFont fnt = m_pLabelName->font();
254 fnt.setBold(true);
255 m_pLabelName->setFont(fnt);
256 pLayoutMain->addWidget(m_pLabelName);
257 }
258
259 /* Create contents widget: */
260 m_pWidget = new QWidget(this);
261 if (m_pWidget)
262 {
263 m_pLayout = new QVBoxLayout(m_pWidget);
264 if (m_pLayout)
265 {
266 m_pLayout->setContentsMargins(0, 0, 0, 0);
267
268 m_pLayout->addWidget(m_pPage);
269 /// @todo what about removal handling?
270 addEditor(m_pPage);
271 }
272 pLayoutMain->addWidget(m_pWidget);
273 }
274 }
275}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use