summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/videooutput.cpp
blob: ef5b1542e7af2a1663ab83695043071953ebd121 (plain)
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
/*  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 "utils.h"
#include "videooutput.h"
#include "videooutputobserver.h"

#include <QPaintEvent>
#include <QPainter>
#include <QMoveEvent>
#include <QResizeEvent>

QT_BEGIN_NAMESPACE

using namespace Phonon;
using namespace Phonon::MMF;

//-----------------------------------------------------------------------------
// Constructor / destructor
//-----------------------------------------------------------------------------

MMF::VideoOutput::VideoOutput(QWidget* parent)
        :   QWidget(parent)
        ,   m_observer(NULL)
{
    TRACE_CONTEXT(VideoOutput::VideoOutput, EVideoInternal);
    TRACE_ENTRY("parent 0x%08x", parent);

#ifndef PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET
    QPalette palette(Qt::black);
    //palette.setColor(QPalette::Window, Qt::transparent); 
    setPalette(palette);  
    
    // Widget redraws all of its pixels when it receives a paint event, so Qt
    // does not need to erase it before generating paint events.
    setAttribute(Qt::WA_OpaquePaintEvent, true);
    
    //setAttribute(Qt::WA_NoSystemBackground, true);
    //setAutoFillBackground(false);
#endif // PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET

#ifdef PHONON_MMF_DEBUG_VIDEO_OUTPUT
    dump();
#endif

    TRACE_EXIT_0();
}

#ifdef PHONON_MMF_DEBUG_VIDEO_OUTPUT
void VideoOutput::dump()
{
    TRACE_CONTEXT(VideoOutput::dump, EVideoInternal);
    TRACE_ENTRY_0();

    TRACE("dumpObjectInfo this 0x%08x", this);
    this->dumpObjectInfo();

    TRACE_0("Traversing up object tree ...");
    QObject* node = this;
    QObject* root = this;
    while (node) {
        QWidget* widget = qobject_cast<QWidget*>(node);
        const bool visible = widget ? widget->isVisible() : false;
        const QHBufC name(node->objectName());
        TRACE("node 0x%08x name %S widget 0x%08x visible %d", node, name.data(), widget, visible);

        root = node;
        node = node->parent();
    }

    TRACE("dumpObjectInfo root 0x%08x", root);
    root->dumpObjectInfo();
    TRACE_0("+ dumpObjectTree");
    root->dumpObjectTree();
    TRACE_0("- dumpObjectTree");

    TRACE("isVisible %d", isVisible());
    TRACE("pos %d %d", x(), y());
    TRACE("size %d %d", size().width(), size().height());
    TRACE("maxSize %d %d", maximumWidth(), maximumHeight());
    TRACE("sizeHint %d %d", sizeHint().width(), sizeHint().height());

    QWidget* parentWidget = qobject_cast<QWidget*>(parent());
    if (parentWidget) {
        TRACE("parent.isVisible %d", parentWidget->isVisible());
        TRACE("parent.pos %d %d", parentWidget->x(), parentWidget->y());
        TRACE("parent.size %d %d", parentWidget->size().width(), parentWidget->size().height());
        TRACE("parent.maxSize %d %d", parentWidget->maximumWidth(), parentWidget->maximumHeight());
        TRACE("parent.sizeHint %d %d", parentWidget->sizeHint().width(), parentWidget->sizeHint().height());
    }

    TRACE_EXIT_0();
}
#endif // PHONON_MMF_DEBUG_VIDEO_OUTPUT

MMF::VideoOutput::~VideoOutput()
{
    TRACE_CONTEXT(VideoOutput::~VideoOutput, EVideoInternal);
    TRACE_ENTRY_0();

    TRACE_EXIT_0();
}

void MMF::VideoOutput::setFrameSize(const QSize& frameSize)
{
#ifdef PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET
    Q_UNUSED(frameSize);
#else
    TRACE_CONTEXT(VideoOutput::setFrameSize, EVideoInternal);
    TRACE("oldSize %d %d newSize %d %d",
          m_frameSize.width(), m_frameSize.height(),
          frameSize.width(), frameSize.height());

    if (frameSize != m_frameSize) {
        m_frameSize = frameSize;
        updateGeometry();
    }
#endif // PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET
}

void MMF::VideoOutput::setObserver(VideoOutputObserver* observer)
{
    TRACE_CONTEXT(VideoOutput::setObserver, EVideoInternal);
    TRACE("observer 0x%08x", observer);

    m_observer = observer;
}


//-----------------------------------------------------------------------------
// QWidget
//-----------------------------------------------------------------------------

#ifndef PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET

QSize MMF::VideoOutput::sizeHint() const
{
    TRACE_CONTEXT(VideoOutput::sizeHint, EVideoApi);

    // TODO: replace this with a more sensible default
    QSize result(320, 240);

    if (!m_frameSize.isNull()) {
        result = m_frameSize;
    }
    
    TRACE("  result %d %d", result.width(), result.height());
    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().numRects());
    TRACE("type %d", event->type());

    QPainter painter;
    painter.begin(this);
    painter.setBrush(QColor(0, 0, 0, 255));   // opaque black
    painter.drawRects(event->region().rects());
    painter.end();
}

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());

    QWidget::resizeEvent(event);
    
    if (m_observer)
        m_observer->videoOutputRegionChanged();
}

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());

    QWidget::moveEvent(event);

    if (m_observer)
        m_observer->videoOutputRegionChanged();
}

#endif // PHONON_MMF_VIDEOOUTPUT_IS_QWIDGET


//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------


QT_END_NAMESPACE