author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Mon, 19 Apr 2010 10:15:19 +0300 | |
branch | RCL_3 |
changeset 9 | b5b118452c7d |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "videowidget.h" |
|
43 |
||
44 |
#include "videowidgetsurface.h" |
|
45 |
||
46 |
#include <QtMultimedia> |
|
47 |
||
48 |
//! [0] |
|
49 |
VideoWidget::VideoWidget(QWidget *parent) |
|
50 |
: QWidget(parent) |
|
51 |
, surface(0) |
|
52 |
{ |
|
53 |
setAutoFillBackground(false); |
|
54 |
setAttribute(Qt::WA_NoSystemBackground, true); |
|
55 |
setAttribute(Qt::WA_PaintOnScreen, true); |
|
56 |
||
57 |
QPalette palette = this->palette(); |
|
58 |
palette.setColor(QPalette::Background, Qt::black); |
|
59 |
setPalette(palette); |
|
60 |
||
61 |
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
62 |
||
63 |
surface = new VideoWidgetSurface(this); |
|
64 |
} |
|
65 |
//! [0] |
|
66 |
||
67 |
//! [1] |
|
68 |
VideoWidget::~VideoWidget() |
|
69 |
{ |
|
70 |
delete surface; |
|
71 |
} |
|
72 |
//! [1] |
|
73 |
||
74 |
//! [2] |
|
75 |
QSize VideoWidget::sizeHint() const |
|
76 |
{ |
|
77 |
return surface->surfaceFormat().sizeHint(); |
|
78 |
} |
|
79 |
//! [2] |
|
80 |
||
81 |
||
82 |
//! [3] |
|
83 |
void VideoWidget::paintEvent(QPaintEvent *event) |
|
84 |
{ |
|
85 |
QPainter painter(this); |
|
86 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
if (surface->isActive()) { |
0 | 88 |
const QRect videoRect = surface->videoRect(); |
89 |
||
90 |
if (!videoRect.contains(event->rect())) { |
|
91 |
QRegion region = event->region(); |
|
92 |
region.subtract(videoRect); |
|
93 |
||
94 |
QBrush brush = palette().background(); |
|
95 |
||
96 |
foreach (const QRect &rect, region.rects()) |
|
97 |
painter.fillRect(rect, brush); |
|
98 |
} |
|
99 |
||
100 |
surface->paint(&painter); |
|
101 |
} else { |
|
102 |
painter.fillRect(event->rect(), palette().background()); |
|
103 |
} |
|
104 |
} |
|
105 |
//! [3] |
|
106 |
||
107 |
//! [4] |
|
108 |
void VideoWidget::resizeEvent(QResizeEvent *event) |
|
109 |
{ |
|
110 |
QWidget::resizeEvent(event); |
|
111 |
||
112 |
surface->updateVideoRect(); |
|
113 |
} |
|
114 |
//! [4] |