1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/* This file is part of the KDE project.
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ancestormovemonitor.h"
#include "utils.h"
#include "videooutput.h"
#ifndef QT_NO_DEBUG
#include "objectdump.h"
#endif
#include <QPaintEvent>
#include <QPainter>
#include <QMoveEvent>
#include <QResizeEvent>
#include <QtCore/private/qcore_symbian_p.h> // for qt_TRect2QRect
#include <QtGui/private/qwidget_p.h> // to access QWExtra
#include <coecntrl.h>
QT_BEGIN_NAMESPACE
using namespace Phonon;
using namespace Phonon::MMF;
/*! \class MMF::VideoOutput
\internal
*/
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
static const Phonon::VideoWidget::AspectRatio DefaultAspectRatio =
Phonon::VideoWidget::AspectRatioAuto;
static const Phonon::VideoWidget::ScaleMode DefaultScaleMode =
Phonon::VideoWidget::FitInView;
//-----------------------------------------------------------------------------
// Constructor / destructor
//-----------------------------------------------------------------------------
MMF::VideoOutput::VideoOutput
(AncestorMoveMonitor* ancestorMoveMonitor, QWidget* parent)
: QWidget(parent)
, m_ancestorMoveMonitor(ancestorMoveMonitor)
, m_aspectRatio(DefaultAspectRatio)
, m_scaleMode(DefaultScaleMode)
{
TRACE_CONTEXT(VideoOutput::VideoOutput, EVideoInternal);
TRACE_ENTRY("parent 0x%08x", parent);
setPalette(QPalette(Qt::black));
setAttribute(Qt::WA_OpaquePaintEvent, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setAutoFillBackground(false);
// Causes QSymbianControl::Draw not to BitBlt this widget's region of the
// backing store. Since the backing store is (by default) a 16MU bitmap,
// blitting it results in this widget's screen region in the final
// framebuffer having opaque alpha values. This in turn causes the video
// to be invisible when running on the target device.
qt_widget_private(this)->extraData()->disableBlit = true;
getVideoWindowRect();
registerForAncestorMoved();
dump();
TRACE_EXIT_0();
}
MMF::VideoOutput::~VideoOutput()
{
TRACE_CONTEXT(VideoOutput::~VideoOutput, EVideoInternal);
TRACE_ENTRY_0();
m_ancestorMoveMonitor->unRegisterTarget(this);
TRACE_EXIT_0();
}
void MMF::VideoOutput::setVideoSize(const QSize& frameSize)
{
TRACE_CONTEXT(VideoOutput::setVideoSize, EVideoInternal);
TRACE("oldSize %d %d newSize %d %d",
m_videoFrameSize.width(), m_videoFrameSize.height(),
frameSize.width(), frameSize.height());
if (frameSize != m_videoFrameSize) {
m_videoFrameSize = frameSize;
updateGeometry();
}
}
void MMF::VideoOutput::ancestorMoved()
{
TRACE_CONTEXT(VideoOutput::ancestorMoved, EVideoInternal);
TRACE_ENTRY_0();
RWindowBase *const window = videoWindow();
if(window) {
const TPoint newWindowPosSymbian = window->AbsPosition();
const QPoint newWindowPos(newWindowPosSymbian.iX, newWindowPosSymbian.iY);
if(newWindowPos != m_videoWindowRect.topLeft()) {
m_videoWindowRect.moveTo(newWindowPos);
emit videoWindowChanged();
}
}
TRACE_EXIT_0();
}
//-----------------------------------------------------------------------------
// QWidget
//-----------------------------------------------------------------------------
QSize MMF::VideoOutput::sizeHint() const
{
// TODO: replace this with a more sensible default
QSize result(320, 240);
if (!m_videoFrameSize.isNull())
result = m_videoFrameSize;
return result;
}
void MMF::VideoOutput::paintEvent(QPaintEvent* event)
{
TRACE_CONTEXT(VideoOutput::paintEvent, EVideoInternal);
TRACE("rect %d %d - %d %d",
event->rect().left(), event->rect().top(),
event->rect().right(), event->rect().bottom());
TRACE("regions %d", event->region().rectCount());
TRACE("type %d", event->type());
// Do nothing
}
void MMF::VideoOutput::resizeEvent(QResizeEvent* event)
{
TRACE_CONTEXT(VideoOutput::resizeEvent, EVideoInternal);
TRACE("%d %d -> %d %d",
event->oldSize().width(), event->oldSize().height(),
event->size().width(), event->size().height());
if(event->size() != event->oldSize()) {
m_videoWindowRect.setSize(event->size());
emit videoWindowChanged();
}
}
void MMF::VideoOutput::moveEvent(QMoveEvent* event)
{
TRACE_CONTEXT(VideoOutput::moveEvent, EVideoInternal);
TRACE("%d %d -> %d %d",
event->oldPos().x(), event->oldPos().y(),
event->pos().x(), event->pos().y());
if(event->pos() != event->oldPos()) {
m_videoWindowRect.moveTo(event->pos());
emit videoWindowChanged();
}
}
bool MMF::VideoOutput::event(QEvent* event)
{
TRACE_CONTEXT(VideoOutput::event, EVideoInternal);
if (event->type() == QEvent::WinIdChange) {
TRACE_0("WinIdChange");
getVideoWindowRect();
emit videoWindowChanged();
return true;
} else if (event->type() == QEvent::ParentChange) {
// Tell ancestor move monitor to update ancestor list for this widget
registerForAncestorMoved();
return true;
} else
return QWidget::event(event);
}
//-----------------------------------------------------------------------------
// Public functions
//-----------------------------------------------------------------------------
RWindowBase* MMF::VideoOutput::videoWindow()
{
CCoeControl *control = internalWinId();
if(!control)
control = effectiveWinId();
RWindowBase *window = 0;
if(control)
window = control->DrawableWindow();
return window;
}
const QRect& MMF::VideoOutput::videoWindowRect() const
{
return m_videoWindowRect;
}
Phonon::VideoWidget::AspectRatio MMF::VideoOutput::aspectRatio() const
{
return m_aspectRatio;
}
void MMF::VideoOutput::setAspectRatio
(Phonon::VideoWidget::AspectRatio aspectRatio)
{
if(m_aspectRatio != aspectRatio) {
m_aspectRatio = aspectRatio;
emit aspectRatioChanged();
}
}
Phonon::VideoWidget::ScaleMode MMF::VideoOutput::scaleMode() const
{
return m_scaleMode;
}
void MMF::VideoOutput::setScaleMode
(Phonon::VideoWidget::ScaleMode scaleMode)
{
if(m_scaleMode != scaleMode) {
m_scaleMode = scaleMode;
emit scaleModeChanged();
}
}
//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------
void MMF::VideoOutput::getVideoWindowRect()
{
RWindowBase *const window = videoWindow();
if(window)
m_videoWindowRect =
qt_TRect2QRect(TRect(window->AbsPosition(), window->Size()));
}
void MMF::VideoOutput::registerForAncestorMoved()
{
m_ancestorMoveMonitor->registerTarget(this);
}
void MMF::VideoOutput::dump() const
{
#ifndef QT_NO_DEBUG
TRACE_CONTEXT(VideoOutput::dump, EVideoInternal);
QScopedPointer<ObjectDump::QVisitor> visitor(new ObjectDump::QVisitor);
visitor->setPrefix("Phonon::MMF"); // to aid searchability of logs
ObjectDump::addDefaultAnnotators(*visitor);
TRACE("Dumping tree from leaf 0x%08x:", this);
ObjectDump::dumpTreeFromLeaf(*this, *visitor);
QScopedPointer<ObjectDump::QDumper> dumper(new ObjectDump::QDumper);
dumper->setPrefix("Phonon::MMF"); // to aid searchability of logs
ObjectDump::addDefaultAnnotators(*dumper);
TRACE_0("Dumping VideoOutput:");
dumper->dumpObject(*this);
#endif
}
QT_END_NAMESPACE
|