summaryrefslogtreecommitdiffstats
path: root/src/plugins/symbian/videooutput/s60videowidget.cpp
blob: 3804204e2ce053e3f4fbf68f3904db00e2dd38bf (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "s60videowidget.h"
#include "s60videooutpututils.h"

#include <QtCore/QVariant>
#include <QtCore/QEvent>
#include <QtGui/QApplication>
#include <QtGui/QPainter>

#include <coemain.h>    // CCoeEnv
#include <coecntrl.h>   // CCoeControl
#include <w32std.h>

using namespace S60VideoOutputUtils;

const int NullOrdinalPosition = -1;

S60VideoWidget::S60VideoWidget(QWidget *parent)
:   QWidget(parent)
,   m_pixmap(NULL)
,   m_paintingEnabled(false)
,   m_topWinId(0)
,   m_ordinalPosition(NullOrdinalPosition)
{
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setPalette(QPalette(Qt::black));
    setAutoFillBackground(false);
    if (!parent)
        setProperty("_q_DummyWindowSurface", true);
    S60VideoOutputUtils::setIgnoreFocusChanged(this);
}

S60VideoWidget::~S60VideoWidget()
{

}

bool S60VideoWidget::event(QEvent *event)
{
    if (event->type() == QEvent::WinIdChange)
        updateOrdinalPosition();
    return QWidget::event(event);
}

void S60VideoWidget::paintEvent(QPaintEvent *event)
{
    if (m_paintingEnabled && m_pixmap) {
        QPainter painter(this);
        if (m_pixmap->size() != m_contentRect.size())
            qWarning("pixmap size does not match expected value");
        painter.drawPixmap(m_contentRect.topLeft(), *m_pixmap);
    }
}

void S60VideoWidget::setVisible(bool visible)
{
    queueReactivateWindow();
    QWidget::setVisible(visible);
}


WId S60VideoWidget::videoWinId() const
{
    WId wid = 0;
    if (internalWinId())
        wid = internalWinId();
    else if (parentWidget() && effectiveWinId())
        wid = effectiveWinId();
    return wid;
}

void S60VideoWidget::setPixmap(const QPixmap *pixmap)
{
    m_pixmap = pixmap;
    update();
}

void S60VideoWidget::setContentRect(const QRect &rect)
{
    if (m_contentRect != rect) {
        m_contentRect = rect;
        update();
    }
}

void S60VideoWidget::setWindowBackgroundColor()
{
    if (WId wid = internalWinId())
        static_cast<RWindow *>(wid->DrawableWindow())->SetBackgroundColor(TRgb(0, 0, 0, 255));
}

WId S60VideoWidget::topWinId() const
{
    return m_topWinId;
}

void S60VideoWidget::setTopWinId(WId id)
{
    m_topWinId = id;
    updateOrdinalPosition();
#ifdef VIDEOOUTPUT_GRAPHICS_SURFACES
    // This function may be called from a paint event, so defer any window
    // manipulation until painting is complete.
    QMetaObject::invokeMethod(this, "setWindowsNonFading", Qt::QueuedConnection);
#endif
}

void S60VideoWidget::setOrdinalPosition(int ordinalPosition)
{
    m_ordinalPosition = ordinalPosition;
    updateOrdinalPosition();
}

int S60VideoWidget::ordinalPosition() const
{
    return m_ordinalPosition;
}

void S60VideoWidget::updateOrdinalPosition()
{
    if ((m_ordinalPosition != NullOrdinalPosition) && m_topWinId) {
        if (WId wid = videoWinId()) {
            int topOrdinalPosition = m_topWinId->DrawableWindow()->OrdinalPosition();
            queueReactivateWindow();
            wid->DrawableWindow()->SetOrdinalPosition(m_ordinalPosition + topOrdinalPosition);
        }
    }
}

void S60VideoWidget::queueReactivateWindow()
{
    if (!parent()) {
        if (QWidget *activeWindow = QApplication::activeWindow())
            QMetaObject::invokeMethod(this, "reactivateWindow", Qt::QueuedConnection,
                                      Q_ARG(QWidget *, activeWindow));
    }
}

void S60VideoWidget::reactivateWindow(QWidget *widget)
{
    widget->activateWindow();
}

void S60VideoWidget::setWindowsNonFading()
{
    winId()->DrawableWindow()->SetNonFading(ETrue);
    if (m_topWinId)
        m_topWinId->DrawableWindow()->SetNonFading(ETrue);
}

void S60VideoWidget::beginNativePaintEvent(const QRect &rect)
{
    Q_UNUSED(rect)
    emit beginVideoWidgetNativePaint();
}

void S60VideoWidget::endNativePaintEvent(const QRect &rect)
{
    Q_UNUSED(rect)
    CCoeEnv::Static()->WsSession().Flush();
    emit endVideoWidgetNativePaint();
}

void S60VideoWidget::setPaintingEnabled(bool enabled)
{
    if (enabled) {
#ifndef VIDEOOUTPUT_GRAPHICS_SURFACES
        setAttribute(Qt::WA_OpaquePaintEvent, false);
        setAttribute(Qt::WA_NoSystemBackground, false);
        S60VideoOutputUtils::setReceiveNativePaintEvents(this, false);
        S60VideoOutputUtils::setNativePaintMode(this, Default);
#else
        S60VideoOutputUtils::setNativePaintMode(this, Default);
#endif // !VIDEOOUTPUT_GRAPHICS_SURFACES
    } else {
#ifndef VIDEOOUTPUT_GRAPHICS_SURFACES
        setAttribute(Qt::WA_OpaquePaintEvent, true);
        setAttribute(Qt::WA_NoSystemBackground, true);
        S60VideoOutputUtils::setReceiveNativePaintEvents(this, true);
        S60VideoOutputUtils::setNativePaintMode(this, ZeroFill);
#else
        S60VideoOutputUtils::setNativePaintMode(this, Disable);
#endif // !VIDEOOUTPUT_GRAPHICS_SURFACES
        winId(); // Create native window handle
    }
    m_paintingEnabled = enabled;
    setWindowBackgroundColor();
}

void S60VideoWidget::setFullScreen(bool enabled)
{
    if (enabled)
        showFullScreen();
    else
        showMaximized();
}