2011-05-22 Hui Huang <hui.2.huang@nokia.com>, Yi Shen <yi.4.shen@nokia.com>
[webkit:qtwebkit.git] / Source / WebKit / qt / symbian / platformplugin / PlayerLabel.cpp
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "PlayerLabel.h"
22
23 PlayerLabel::PlayerLabel(QWidget* parent)
24     : QLabel(parent)
25     , m_bufferingAnimationIterator(m_bufferingAnimation)
26     , m_animationTimer(this)
27 {
28     m_bufferingAnimation.append(QPixmap(":/images/loading_buffering_1.png").scaled(QSize(80, 80)));
29     m_bufferingAnimation.append(QPixmap(":/images/loading_buffering_2.png").scaled(QSize(80, 80)));
30     m_bufferingAnimation.append(QPixmap(":/images/loading_buffering_3.png").scaled(QSize(80, 80)));
31     m_bufferingAnimation.append(QPixmap(":/images/loading_buffering_4.png").scaled(QSize(80, 80)));
32     m_bufferingAnimationIterator = m_bufferingAnimation;
33     m_animationTimer.setSingleShot(false);
34     m_animationTimer.setInterval(200);
35     connect(&m_animationTimer, SIGNAL(timeout()), this, SLOT(onAnimationTimeout()));
36
37     m_cannotplay = QPixmap(":/images/button_cannotplay.png").scaled(QSize(80, 80));
38 }
39
40 void PlayerLabel::onPlayerError()
41 {
42     setPixmap(m_cannotplay);
43     show();
44 }
45
46 void PlayerLabel::startBufferingAnimation()
47 {
48     m_bufferingAnimationIterator.toFront();
49     setPixmap(m_bufferingAnimationIterator.next());
50     show();
51     m_animationTimer.start();
52 }
53
54 void PlayerLabel::stopBufferingAnimation()
55 {
56     hide();
57     m_animationTimer.stop();
58 }
59
60 void PlayerLabel::onAnimationTimeout()
61 {
62     if (!m_bufferingAnimationIterator.hasNext())
63         m_bufferingAnimationIterator.toFront();
64     setPixmap(m_bufferingAnimationIterator.next());
65 }