VirtualBox

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

Last change on this file since 82781 was 76606, checked in by vboxsync, 5 years ago

FE/Qt: Cleaning out old precompiled header experiment.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use