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