1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
3
umplayer, Copyright (C) 2010 Ori Rejwan
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include "mediapanel.h"
23
#include <QFontMetrics>
24
#include <QTimerEvent>
25
#include <QGridLayout>
30
#include "qpropertysetter.h"
31
#include "widgetactions.h"
34
#include "actiontools.h"
37
MediaPanel::MediaPanel(QWidget *parent)
38
: QWidget(parent), duration(0)
41
setAttribute(Qt::WA_StyledBackground, true);
44
if (fontInfo().pixelSize() > 12) {
50
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
51
mediaLabel = new ScrollingLabel(this);
52
repeatButton = new MyButton(this);
53
shuffleButton = new MyButton(this);
54
seeker = new PanelSeeker;
55
seeker->setObjectName("panel-seeker");
56
seeker->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
57
#ifdef SEEKBAR_RESOLUTION
58
seeker->setRange(0, SEEKBAR_RESOLUTION);
60
seeker->installEventFilter(this);
61
mediaLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
62
mediaLabel->setObjectName("panel-main-label");
63
QGridLayout* layout = new QGridLayout;
64
elapsedLabel = new QLabel(this);
65
elapsedLabel->setObjectName("panel-elapsed-label");
66
elapsedLabel->setMargin(0);
67
elapsedLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
68
elapsedLabel->setIndent(3);
69
totalLabel = new QLabel(this);
70
totalLabel->setObjectName("panel-total-label");
71
totalLabel->setMargin(0);
72
totalLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
73
totalLabel->setIndent(3);
74
layout->addWidget( mediaLabel, 0, 0, 1, 2 );
75
layout->addWidget( repeatButton, 0, 2 );
76
layout->addWidget( shuffleButton, 0, 3 );
77
layout->addWidget(elapsedLabel, 1, 0, 1, 1);
78
layout->addWidget(seeker, 1, 1, 1, 1);
79
layout->addWidget(totalLabel, 1, 2, 1, 2);
80
layout->setSpacing(0);
81
layout->setContentsMargins(8,3,8, 3);
82
elapsedLabel->setText("00:00:00");
83
totalLabel->setText("00:00:00");
85
timer = new QTimer(this);
86
timer->setSingleShot(true);
87
timer->setInterval(2000);
88
connect(timer, SIGNAL(timeout()), this, SLOT(reverseStatus()));
89
connect(seeker, SIGNAL(valueChanged(int)), this, SIGNAL(seekerChanged(int)));
92
MediaPanel::~MediaPanel() {
95
void MediaPanel::paintEvent(QPaintEvent * e) {
97
p.drawPixmap(0,0,leftBackground.width(), 53, leftBackground);
98
p.drawPixmap(width() - rightBackground.width(), 0, rightBackground.width(), 53, rightBackground );
99
p.drawTiledPixmap(leftBackground.width(), 0, width() - leftBackground.width() - rightBackground.width(), 53, centerBackground );
102
void MediaPanel::setShuffleIcon( MyIcon icon ) {
103
shuffleButton->setMyIcon(icon);
104
shuffleButton->setFixedSize(icon.size(MyIcon::Normal, MyIcon::Off));
107
void MediaPanel::setRepeatIcon(MyIcon icon) {
108
repeatButton->setMyIcon(icon);
109
repeatButton->setFixedSize(icon.size(MyIcon::Normal, MyIcon::Off));
112
void MediaPanel::setActionCollection(QList<QAction *>actions) {
113
//ActionTools::findAction("aaa", actions);
114
SETACTIONTOBUTTON(shuffleButton, "pl_shuffle");
115
SETACTIONTOBUTTON(repeatButton, "pl_repeat");
117
retranslateStrings();
120
void MediaPanel::setMplayerState(int state) {
121
Core::State s = static_cast<Core::State>(state);
122
if (s == Core::Stopped) {
123
seeker->setEnabled(false);
126
if (s == Core::Paused || s == Core::Playing) {
127
seeker->setEnabled(true);
131
void MediaPanel::setDuration(int duration) {
132
this->duration = duration;
134
seeker->setState(PanelSeeker::Stopped, true);
137
seeker->setState(PanelSeeker::Stopped, false);
139
setTotalText(Helper::formatTime(duration));
140
setElapsedText(Helper::formatTime(0));
143
void MediaPanel::setMediaLabelText(QString text) {
144
mediaLabel->setText(text);
145
mediaLabel->update();
146
originalTitle = text;
149
void MediaPanel::setStatusText(QString text, int time) {
150
mediaLabel->setText(text);
151
mediaLabel->update();
158
void MediaPanel::reverseStatus() {
159
setMediaLabelText(originalTitle);
162
void MediaPanel::setBuffering(bool enable) {
164
seeker->setState(PanelSeeker::Buffering, true);
168
seeker->setState(PanelSeeker::Buffering, false);
172
void MediaPanel::setSeeker(int v) {
173
seeker->setSliderValue(v);
176
bool MediaPanel::eventFilter(QObject *o, QEvent *e) {
177
if (o == seeker && e->type() == QEvent::ToolTip) {
178
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e);
179
qreal value = seeker->valueForPos(helpEvent->pos().x())* duration/seeker->maximum();
180
if (value >=0 && value <= duration) {
181
QToolTip::showText(helpEvent->globalPos(),Helper::formatTime(value), seeker);
183
QToolTip::hideText();
189
// Language change stuff
190
void MediaPanel::changeEvent(QEvent *e) {
191
if (e->type() == QEvent::LanguageChange) {
192
retranslateStrings();
194
QWidget::changeEvent(e);
198
void MediaPanel::retranslateStrings() {
199
if (shuffleButton) shuffleButton->setToolTip(tr("Shuffle playlist"));
200
if (repeatButton) repeatButton->setToolTip(tr("Repeat playlist"));
203
void ScrollingLabel::paintEvent(QPaintEvent * e) {
206
p.setPen(palette().color(foregroundRole()));
207
p.setRenderHint(QPainter::TextAntialiasing, true);
208
QRect widgetRect = rect();
209
if (textRect.width() <= width()) {
210
p.drawText(widgetRect, Qt::AlignVCenter | Qt::AlignLeading, mText );
212
p.translate(-scrollPos, 0);
213
p.drawText(widgetRect.adjusted(0,0,scrollPos, 0), Qt::AlignVCenter | Qt::AlignLeading, mText);
214
p.translate(textRect.width() + gap, 0);
215
p.drawText(widgetRect.adjusted(0, 0, scrollPos - gap - textRect.width(), 0) , Qt::AlignVCenter | Qt::AlignLeading, mText);
220
void ScrollingLabel::setText(QString text) {
226
void ScrollingLabel::changeEvent(QEvent * e) {
227
if (e->type() == QEvent::FontChange) {
232
void ScrollingLabel::updateLabel() {
233
QFontMetrics fm(font());
234
QRect rect = fm.boundingRect(mText);
243
if (rect.width() > width()) {
244
timerId = startTimer(20);
248
void ScrollingLabel::timerEvent(QTimerEvent * t) {
250
scrollPos = scrollPos % (textRect.width() + gap);
255
ScrollingLabel::ScrollingLabel(QWidget* parent ) {
259
setAttribute(Qt::WA_StyledBackground, true);
263
void ScrollingLabel::resizeEvent(QResizeEvent *) {
267
QSize ScrollingLabel::sizeHint() const {
268
QFontMetrics fm(font());
269
return QSize(0, fm.height());
272
#include "moc_mediapanel.cpp"