VirtualBox

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

Last change on this file since 100347 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

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