VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilmContainer.cpp@ 104158

Last change on this file since 104158 was 103315, checked in by vboxsync, 10 months ago

FE/Qt: Machine settings / Display page / Recording tab and corresponding editors: Wiping out unwanted dependencies.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1/* $Id: UIFilmContainer.cpp 103315 2024-02-12 15:23:30Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFilmContainer class implementation.
4 */
5
6/*
7 * Copyright (C) 2013-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 <QCheckBox>
30#include <QHBoxLayout>
31#include <QPainter>
32#include <QScrollArea>
33#include <QVBoxLayout>
34#ifndef VBOX_WS_MAC
35# include <QStyle>
36#endif
37
38/* GUI includes: */
39#include "QIWithRetranslateUI.h"
40#include "UIFilmContainer.h"
41
42
43/** QWidget subclass providing GUI with UIFilmContainer item prototype.
44 * @todo Rename to something more suitable like UIScreenThumbnail. */
45class UIFilm : public QIWithRetranslateUI<QWidget>
46{
47 Q_OBJECT;
48
49public:
50
51 /** Constructs film widget passing @a pParent to the base-class.
52 * @param iScreenIndex Brings the guest-screen index this film referencing.
53 * @param fEnabled Brings whether the guest-screen mentioned above is enabled. */
54 UIFilm(int iScreenIndex, bool fEnabled, QWidget *pParent = 0);
55
56 /** Returns whether guest-screen is enabled. */
57 bool checked() const;
58
59protected:
60
61 /** Handles translation event. */
62 virtual void retranslateUi() RT_OVERRIDE;
63
64 /** Handles paint @a pEvent. */
65 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
66
67 /** Returns minimum size-hint. */
68 virtual QSize minimumSizeHint() const RT_OVERRIDE;
69
70private:
71
72 /** Prepares all. */
73 void prepare();
74 /** Prepares layout. */
75 void prepareLayout();
76 /** Prepares check-box. */
77 void prepareCheckBox();
78
79 /** Holds the guest-screen index. */
80 int m_iScreenIndex;
81 /** Holds whether guest-screen was enabled. */
82 bool m_fWasEnabled;
83
84 /** Holds the main-layout instance. */
85 QVBoxLayout *m_pMainLayout;
86 /** Holds the check-box instance. */
87 QCheckBox *m_pCheckBox;
88};
89
90
91/*********************************************************************************************************************************
92* Class UIFilm implementation. *
93*********************************************************************************************************************************/
94
95UIFilm::UIFilm(int iScreenIndex, bool fEnabled, QWidget *pParent /* = 0*/)
96 : QIWithRetranslateUI<QWidget>(pParent)
97 , m_iScreenIndex(iScreenIndex)
98 , m_fWasEnabled(fEnabled)
99 , m_pCheckBox(0)
100{
101 /* Prepare: */
102 prepare();
103}
104
105bool UIFilm::checked() const
106{
107 /* Is the check-box currently checked? */
108 return m_pCheckBox->isChecked();
109}
110
111void UIFilm::retranslateUi()
112{
113 /* Translate check-box: */
114 m_pCheckBox->setText(QApplication::translate("UIMachineSettingsDisplay", "Screen %1").arg(m_iScreenIndex + 1));
115 m_pCheckBox->setWhatsThis(QApplication::translate("UIMachineSettingsDisplay", "When checked, enables video recording for screen %1.").arg(m_iScreenIndex + 1));
116}
117
118void UIFilm::paintEvent(QPaintEvent *)
119{
120 /* Compose painting rectangle: */
121 const QRect rect(1, 1, width() - 2, height() - 2);
122
123 /* Create painter: */
124 QPainter painter(this);
125 painter.setRenderHint(QPainter::Antialiasing);
126
127 /* Configure painter clipping: */
128 QPainterPath path;
129 int iDiameter = 6;
130 QSizeF arcSize(2 * iDiameter, 2 * iDiameter);
131 path.moveTo(rect.x() + iDiameter, rect.y());
132 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, 0), 90, 90);
133 path.lineTo(path.currentPosition().x(), rect.height() - iDiameter);
134 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -iDiameter), 180, 90);
135 path.lineTo(rect.width() - iDiameter, path.currentPosition().y());
136 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, -2 * iDiameter), 270, 90);
137 path.lineTo(path.currentPosition().x(), rect.y() + iDiameter);
138 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * iDiameter, -iDiameter), 0, 90);
139 path.closeSubpath();
140
141 /* Get current background color: */
142 QColor currentColor(palette().color(backgroundRole()));
143
144 /* Fill with background: */
145 painter.setClipPath(path);
146 QColor newColor1 = currentColor;
147 QColor newColor2 = currentColor.darker(125);
148 QLinearGradient headerGradient(rect.topLeft(), rect.bottomRight());
149 headerGradient.setColorAt(0, newColor1);
150 headerGradient.setColorAt(1, newColor2);
151 painter.fillRect(rect, headerGradient);
152
153 /* Stroke with border: */
154 QColor strokeColor = currentColor.darker(150);
155 painter.setClipping(false);
156 painter.strokePath(path, strokeColor);
157}
158
159QSize UIFilm::minimumSizeHint() const
160{
161 /* Return 16:9 aspect-ratio msh: */
162 QSize msh = QWidget::minimumSizeHint();
163 return QSize(msh.width(), (msh.width() * 9) / 16);
164}
165
166void UIFilm::prepare()
167{
168 /* Prepare layout: */
169 prepareLayout();
170 /* Prepare check-box: */
171 prepareCheckBox();
172
173 /* Apply language settings: */
174 retranslateUi();
175}
176
177void UIFilm::prepareLayout()
178{
179 /* Create layout: */
180 m_pMainLayout = new QVBoxLayout(this);
181 if (m_pMainLayout)
182 {
183 /* Configure layout: */
184#ifdef VBOX_WS_MAC
185 m_pMainLayout->setContentsMargins(10, 10, 15, 10);
186#endif
187
188 /* Add strech: */
189 m_pMainLayout->addStretch();
190 }
191}
192
193void UIFilm::prepareCheckBox()
194{
195 /* Create check-box: */
196 m_pCheckBox = new QCheckBox;
197 if (m_pCheckBox)
198 {
199 /* Configure check-box: */
200 m_pCheckBox->setChecked(static_cast<bool>(m_fWasEnabled));
201 /* Configure font: */
202 QFont currentFont = m_pCheckBox->font();
203#ifdef VBOX_WS_MAC
204 currentFont.setPointSize(currentFont.pointSize() - 2);
205#else
206 currentFont.setPointSize(currentFont.pointSize() - 1);
207#endif
208 m_pCheckBox->setFont(currentFont);
209
210 /* Insert into layout: */
211 m_pMainLayout->insertWidget(0, m_pCheckBox);
212 }
213}
214
215
216/*********************************************************************************************************************************
217* Class UIFilmContainer implementation. *
218*********************************************************************************************************************************/
219
220UIFilmContainer::UIFilmContainer(QWidget *pParent /* = 0*/)
221 : QWidget(pParent)
222 , m_pMainLayout(0)
223 , m_pScroller(0)
224{
225 /* Prepare: */
226 prepare();
227}
228
229QVector<bool> UIFilmContainer::value() const
230{
231 /* Enumerate all the existing widgets: */
232 QVector<bool> value;
233 foreach (UIFilm *pWidget, m_widgets)
234 value << static_cast<bool>(pWidget->checked());
235
236 /* Return value: */
237 return value;
238}
239
240void UIFilmContainer::setValue(const QVector<bool> &value)
241{
242 /* Cleanup viewport/widget list: */
243 delete m_pScroller->takeWidget();
244 m_widgets.clear();
245
246 /* Create widget: */
247 QWidget *pWidget = new QWidget;
248 if (pWidget)
249 {
250 /* Create widget-layout: */
251 QHBoxLayout *pWidgetLayout = new QHBoxLayout(pWidget);
252 if (pWidgetLayout)
253 {
254 /* Configure widget-layout: */
255 pWidgetLayout->setContentsMargins(0, 0, 0, 0);
256#ifdef VBOX_WS_MAC
257 pWidgetLayout->setContentsMargins(5, 5, 5, 5);
258#else
259 pWidgetLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);
260#endif
261
262 /* Create new films according passed vector: */
263 for (int iScreenIndex = 0; iScreenIndex < value.size(); ++iScreenIndex)
264 {
265 /* Create new film: */
266 UIFilm *pFilm = new UIFilm(iScreenIndex, value[iScreenIndex]);
267 if (pFilm)
268 {
269 /* Add film into the widget list: */
270 m_widgets << pFilm;
271
272 /* Add into layout: */
273 pWidgetLayout->addWidget(pFilm);
274 }
275 }
276 }
277
278 /* Assign scroller with widget: */
279 m_pScroller->setWidget(pWidget);
280 /* Reconfigure scroller widget: */
281 m_pScroller->widget()->setAutoFillBackground(false);
282 /* And adjust that widget geometry: */
283 QSize msh = m_pScroller->widget()->minimumSizeHint();
284 int iMinimumHeight = msh.height();
285 m_pScroller->viewport()->setFixedHeight(iMinimumHeight);
286 }
287}
288
289void UIFilmContainer::prepare()
290{
291 /* Prepare layout: */
292 prepareLayout();
293 /* Prepare scroller: */
294 prepareScroller();
295
296 /* Append with 'default' value: */
297 setValue(QVector<bool>() << true);
298}
299
300void UIFilmContainer::prepareLayout()
301{
302 /* Create layout: */
303 m_pMainLayout = new QVBoxLayout(this);
304 if (m_pMainLayout)
305 {
306 /* Configure layout: */
307 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
308 m_pMainLayout->setSpacing(0);
309 }
310}
311
312void UIFilmContainer::prepareScroller()
313{
314 /* Create scroller: */
315 m_pScroller = new QScrollArea;
316 if (m_pScroller)
317 {
318 /* Configure scroller: */
319 m_pScroller->setFrameShape(QFrame::NoFrame);
320 m_pScroller->viewport()->setAutoFillBackground(false);
321 m_pScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
322 m_pScroller->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
323
324 /* Add into layout: */
325 m_pMainLayout->addWidget(m_pScroller);
326 }
327}
328
329
330#include "UIFilmContainer.moc"
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