Commit cd98b8a7 authored by Scott Wheeler's avatar Scott Wheeler

Fixed up the status bar and did a couple of little cleanups.

svn path=/trunk/kdemultimedia/juk/; revision=191436
parent eb7bff72
......@@ -412,8 +412,16 @@ void JuK::pollPlay()
else
stopFile();
}
else if(!trackPositionDragging)
else if(!trackPositionDragging) {
sliderAction->getTrackPositionSlider()->setValue(player.position());
statusLabel->setItemTotalTime(player.totalTime());
statusLabel->setItemCurrentTime(player.currentTime());
}
// Ok, this is weird stuff, but it works pretty well. Ordinarily we don't
// need to check up on our playing time very often, but in the span of the
// last interval, we want to check a lot -- to figure out that we've hit the
// end of the song as soon as possible.
if(player.playing() && float(player.totalTime() - player.currentTime()) < pollInterval * 2)
playTimer->changeInterval(50);
......
......@@ -58,14 +58,14 @@ Player::~Player()
void Player::play(const QString &fileName, float volume)
{
currentFile=fileName;
currentFile = fileName;
play(volume);
}
void Player::play(float volume)
{
if(serverRunning()) {
if(media && media->state()==posPaused) {
if(media && media->state() == posPaused) {
media->play();
}
else {
......@@ -155,7 +155,7 @@ long Player::totalTime() const
long Player::currentTime() const
{
if(serverRunning() && media && media->state()==posPlaying)
if(serverRunning() && media && media->state() == posPlaying)
return(media->currentTime().seconds);
else
return(-1);
......@@ -163,13 +163,13 @@ long Player::currentTime() const
int Player::position() const
{
if(serverRunning() && media && media->state()==posPlaying) {
if(serverRunning() && media && media->state() == posPlaying) {
// long total=media->overallTime().ms;
// long current=media->currentTime().ms;
long total=media->overallTime().seconds * 1000 + media->overallTime().ms;
long current=media->currentTime().seconds * 1000 + media->currentTime().ms;
long total = media->overallTime().seconds * 1000 + media->overallTime().ms;
long current = media->currentTime().seconds * 1000 + media->currentTime().ms;
// add .5 to make rounding happen properly
return(int(double(current)*1000/total+.5));
return(int(double(current) * 1000 / total + .5));
}
else
return(-1);
......@@ -183,7 +183,7 @@ void Player::seek(long seekTime)
{
if(serverRunning() && media) {
poTime poSeekTime;
poSeekTime.seconds=seekTime;
poSeekTime.seconds = seekTime;
media->seek(poSeekTime);
}
}
......@@ -192,8 +192,8 @@ void Player::seekPosition(int position)
{
if(serverRunning() && media) {
poTime poSeekTime;
long total=media->overallTime().seconds;
poSeekTime.seconds=long(double(total)*position/1000+.5);
long total = media->overallTime().seconds;
poSeekTime.seconds = long(double(total) * position / 1000 + .5);
media->seek(poSeekTime);
}
}
......@@ -204,8 +204,8 @@ void Player::seekPosition(int position)
void Player::setupPlayer()
{
dispatcher=new Dispatcher;
server=new SimpleSoundServer(Reference("global:Arts_SimpleSoundServer"));
dispatcher = new Dispatcher;
server = new SimpleSoundServer(Reference("global:Arts_SimpleSoundServer"));
}
void Player::setupVolumeControl()
......
......@@ -15,10 +15,16 @@
* *
***************************************************************************/
#include <kpushbutton.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <qevent.h>
#include <qstylesheet.h>
#include <qlabel.h>
#include <qtooltip.h>
#include <qfontmetrics.h>
#include "statuslabel.h"
#include "playlistitem.h"
......@@ -30,10 +36,38 @@
// public methods
////////////////////////////////////////////////////////////////////////////////
StatusLabel::StatusLabel(QWidget *parent, const char *name) : QHBox(parent, name)
StatusLabel::StatusLabel(QWidget *parent, const char *name) : QHBox(parent, name), playingItem(0)
{
trackLabel = new QLabel(this, "trackLabel");
trackLabel->installEventFilter(this);
setSpacing(0);
QHBox *trackAndPlaylist = new QHBox(this);
trackAndPlaylist->setFrameStyle(Box | Sunken);
playlistLabel = new QLabel(trackAndPlaylist, "playlistLabel");
playlistLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
playlistLabel->setTextFormat(RichText);
playlistLabel->setAlignment(AlignLeft);
trackLabel = new QLabel(trackAndPlaylist, "trackLabel");
trackLabel->setAlignment(AlignRight);
trackLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
trackLabel->setTextFormat(RichText);
itemTimeLabel = new QLabel(this);
QFontMetrics fontMetrics(font());
itemTimeLabel->setAlignment(AlignCenter);
itemTimeLabel->setMinimumWidth(fontMetrics.boundingRect("000:00 / 000:00").width());
itemTimeLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
itemTimeLabel->setFrameStyle(Box | Sunken);
setItemTotalTime(0);
setItemCurrentTime(0);
QLabel *iconLabel = new QLabel(this);
iconLabel->setPixmap(SmallIcon("up"));
iconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
iconLabel->setFrameStyle(Box | Sunken);
QToolTip::add(iconLabel, i18n("Jump to the currently playing item"));
}
StatusLabel::~StatusLabel()
......@@ -51,37 +85,70 @@ void StatusLabel::setPlayingItem(PlaylistItem *item)
QString playlist = QStyleSheet::escape(p->playlistBoxItem()->text());
QString artist = QStyleSheet::escape(item->text(PlaylistItem::ArtistColumn));
QString track = QStyleSheet::escape(item->text(PlaylistItem::TrackColumn));
QString track = QStyleSheet::escape(item->text(PlaylistItem::TrackColumn));
QString label = playlist + " / " + artist + " - <i>" + track + "</i>";
playlistLabel->setText(playlist);
QString label = artist + " - " + track;
trackLabel->setText(label);
}
else
trackLabel->clear();
clear();
}
else
trackLabel->clear();
clear();
}
void StatusLabel::clear()
{
playlistLabel->clear();
trackLabel->clear();
playingItem = 0;
setItemTotalTime(0);
setItemCurrentTime(0);
}
void StatusLabel::setItemTotalTime(long time)
{
itemTotalMinutes = int(time / 60);
itemTotalSeconds = time % 60;
}
void StatusLabel::setItemCurrentTime(long time)
{
int minutes = int(time / 60);
int seconds = time % 60;
QString timeString = formatTime(minutes, seconds) + " / " + formatTime(itemTotalMinutes, itemTotalSeconds);
itemTimeLabel->setText(timeString);
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
bool StatusLabel::eventFilter(QObject *o, QEvent *e)
void StatusLabel::mousePressEvent(QMouseEvent *)
{
if(o && o == trackLabel &&
e && e->type() == QEvent::MouseButtonPress) {
PlaylistSplitter::setSelected(playingItem);
return(true);
}
jumpToPlayingItem();
}
return(false);
QString StatusLabel::formatTime(int minutes, int seconds)
{
QString m = QString::number(minutes);
if(m.length() == 1)
m = "0" + m;
QString s = QString::number(seconds);
if(s.length() == 1)
s = "0" + s;
return(m + ":" + s);
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void StatusLabel::jumpToPlayingItem() const
{
if(playingItem)
PlaylistSplitter::setSelected(playingItem);
}
#include "statuslabel.moc"
......@@ -18,9 +18,9 @@
#ifndef STATUSLABEL_H
#define STATUSLABEL_H
#include <qwidget.h>
#include <qhbox.h>
#include <qlabel.h>
class QLabel;
class PlaylistItem;
......@@ -35,11 +35,27 @@ public:
void setPlayingItem(PlaylistItem *item);
void clear();
/**
* This just sets internal variables that are used by setItemCurrentTime().
* Please call that method to display the time.
*/
void setItemTotalTime(long time);
void setItemCurrentTime(long time);
private:
virtual bool eventFilter(QObject *o, QEvent *e);
static QString formatTime(int minutes, int seconds);
virtual void mousePressEvent(QMouseEvent *);
QLabel *playlistLabel;
QLabel *trackLabel;
QLabel *itemTimeLabel;
PlaylistItem *playingItem;
int itemTotalMinutes;
int itemTotalSeconds;
private slots:
void jumpToPlayingItem() const;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment