2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21 #include "OverlayWidget.h"
24 #include <QGridLayout>
25 #include <QHBoxLayout>
29 OverlayWidget::OverlayWidget(QWidget *parent)
30 : QWidget(0, Qt::FramelessWindowHint)
36 m_playIcon = QIcon(":/images/button_play.png");
37 m_pauseIcon = QIcon(":/images/button_pause.png");
38 m_soundOnIcon = QIcon(":/images/button_sound_on.png");
39 m_soundOffIcon = QIcon(":/images/button_sound_off.png");
41 m_controlButton = new PlayerButton(this);
42 m_controlButton->setIcon(m_pauseIcon);
43 connect(m_controlButton, SIGNAL(clicked()), this, SLOT(onControlClicked()));
45 m_progressSlider = new QSlider(Qt::Horizontal, this);
46 connect(m_progressSlider, SIGNAL(sliderMoved(int)), this, SLOT(onSliderMoved(int)));
48 m_positionLabel = new QLabel(this);
49 m_positionLabel->setText(timeToString(0));
50 m_durationLabel = new QLabel(this);
52 m_soundButton = new PlayerButton(this);
53 m_soundButton->setIcon(m_soundOnIcon);
54 connect(m_soundButton, SIGNAL(clicked()), this, SLOT(onSoundClicked()));
56 m_closeButton = new PlayerButton(this);
57 m_closeButton->setIcon(QIcon(":/images/button_close.png"));
58 connect(m_closeButton, SIGNAL(clicked()), this, SLOT(onCloseClicked()));
60 m_volumeSlider = new QSlider(Qt::Vertical, this);
61 m_volumeSlider->setRange(0, 100);
62 connect(m_soundButton, SIGNAL(tapAndHold()), m_volumeSlider, SLOT(show()));
63 connect(m_volumeSlider, SIGNAL(sliderReleased()), this, SLOT(onVolumeSliderReleased()));
64 connect(m_volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(onVolumeSliderMoved(int)));
65 m_volumeSlider->hide();
67 m_playerLabel = new PlayerLabel(this);
68 m_playerLabel->hide();
70 QBoxLayout* m_controlLayout = new QHBoxLayout;
71 m_controlLayout->addWidget(m_controlButton);
72 m_controlLayout->addWidget(m_positionLabel);
73 m_controlLayout->addWidget(m_progressSlider);
74 m_controlLayout->addWidget(m_durationLabel);
76 QGridLayout* layout = new QGridLayout;
77 layout->addWidget(m_closeButton, 0, 0, 1, 2, Qt::AlignRight | Qt::AlignTop);
78 layout->addWidget(m_playerLabel, 1, 0, Qt::AlignCenter);
79 layout->addWidget(m_volumeSlider, 1, 1);
80 layout->addLayout(m_controlLayout, 2, 0, Qt::AlignBottom);
81 layout->addWidget(m_soundButton, 2, 1, Qt::AlignBottom);
84 m_hideWidgetTimer = new QTimer(this);
85 m_hideWidgetTimer->setSingleShot(true);
86 m_hideWidgetTimer->setInterval(3000);
87 connect(m_hideWidgetTimer, SIGNAL(timeout()), this, SLOT(onTimerTimeout()));
88 connect(m_progressSlider, SIGNAL(sliderPressed()), m_hideWidgetTimer, SLOT(stop()));
89 connect(m_progressSlider, SIGNAL(sliderReleased()), m_hideWidgetTimer, SLOT(start()));
90 connect(m_volumeSlider, SIGNAL(sliderPressed()), m_hideWidgetTimer, SLOT(stop()));
92 setAttribute(Qt::WA_TranslucentBackground);
95 OverlayWidget::~OverlayWidget()
99 void OverlayWidget::setDuration(int duration)
101 m_progressSlider->setMaximum(duration);
102 m_durationLabel->setText(timeToString(duration));
105 void OverlayWidget::setPosition(int position)
107 if (!m_progressSlider->isSliderDown()) {
108 m_progressSlider->setValue(position);
109 m_positionLabel->setText(timeToString(position));
113 void OverlayWidget::setVolume(int volume)
115 m_volumeSlider->setValue(volume);
118 void OverlayWidget::mousePressEvent(QMouseEvent *)
120 m_hideWidgetTimer->stop();
124 void OverlayWidget::onPlayerStopped()
126 m_controlButton->setIcon(m_playIcon);
129 void OverlayWidget::onPlayerError()
131 m_controlButton->setDisabled(true);
132 m_progressSlider->setDisabled(true);
133 m_playerLabel->onPlayerError();
137 void OverlayWidget::onEndOfMedia()
139 QWidget::showFullScreen();
142 void OverlayWidget::onBufferingMedia()
144 m_playerLabel->startBufferingAnimation();
147 void OverlayWidget::onBufferedMedia()
149 m_playerLabel->stopBufferingAnimation();
152 QString OverlayWidget::timeToString(int seconds)
154 QTime initTime(0, 0, 0);
155 QTime time = initTime.addSecs(seconds);
156 return time.hour() ? time.toString("h:mm:ss") : time.toString("mm:ss");
159 void OverlayWidget::applyStyleSheet()
161 QFile file(":/qss/OverlayWidget.qss");
162 file.open(QFile::ReadOnly);
163 setStyleSheet(QLatin1String(file.readAll()));
166 void OverlayWidget::onControlClicked()
168 m_isPaused = !m_isPaused;
170 m_controlButton->setIcon(m_playIcon);
171 m_hideWidgetTimer->stop();
173 m_controlButton->setIcon(m_pauseIcon);
174 m_hideWidgetTimer->start();
176 emit controlClicked(m_isPaused);
179 void OverlayWidget::onSliderMoved(int value)
181 emit sliderMoved(value);
184 void OverlayWidget::onSoundClicked()
186 if (m_volumeSlider->isVisible())
189 m_isMuted = !m_isMuted;
192 m_soundButton->setIcon(m_soundOffIcon);
194 m_soundButton->setIcon(m_soundOnIcon);
196 m_hideWidgetTimer->start();
197 emit muted(m_isMuted);
200 void OverlayWidget::onCloseClicked()
202 m_hideWidgetTimer->stop();
207 void OverlayWidget::onVolumeSliderReleased()
209 m_hideWidgetTimer->start();
210 emit volumeChanged(m_volumeSlider->value());
211 m_volumeSlider->hide();
214 void OverlayWidget::onVolumeSliderMoved(int value)
216 emit volumeChanged(value);
219 void OverlayWidget::onTimerTimeout()
225 void OverlayWidget::showFullScreen()
227 m_hideWidgetTimer->start();
228 QWidget::showFullScreen();