mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Track slider and seeking
This commit is contained in:
parent
28e9bf4ac5
commit
70613f5299
@ -9,6 +9,7 @@
|
||||
#include "enginebase.h"
|
||||
#include "lastfmservice.h"
|
||||
#include "osd.h"
|
||||
#include "trackslider.h"
|
||||
|
||||
#include "qxtglobalshortcut.h"
|
||||
|
||||
@ -32,6 +33,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
tray_icon_(new SystemTrayIcon(this)),
|
||||
osd_(new OSD(tray_icon_, this)),
|
||||
track_slider_(new TrackSlider(this)),
|
||||
radio_model_(new RadioModel(this)),
|
||||
playlist_(new Playlist(this)),
|
||||
player_(new Player(playlist_, radio_model_->GetLastFMService(), this)),
|
||||
@ -123,6 +125,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(ui_.playlist, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
||||
connect(ui_.playlist, SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
||||
|
||||
connect(track_slider_, SIGNAL(ValueChanged(int)), player_, SLOT(Seek(int)));
|
||||
|
||||
// Library connections
|
||||
connect(library_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
||||
connect(ui_.library_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(LibraryDoubleClick(QModelIndex)));
|
||||
@ -210,6 +214,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// Analyzer
|
||||
ui_.analyzer->set_engine(player_->GetEngine());
|
||||
|
||||
// Statusbar widgets
|
||||
ui_.statusBar->addPermanentWidget(track_slider_);
|
||||
|
||||
// Load theme
|
||||
QFile stylesheet(":mainwindow.css");
|
||||
if (!stylesheet.open(QIODevice::ReadOnly)) {
|
||||
@ -263,6 +270,7 @@ void MainWindow::MediaStopped() {
|
||||
ui_.action_love->setEnabled(false);
|
||||
|
||||
track_position_timer_->stop();
|
||||
track_slider_->SetStopped();
|
||||
}
|
||||
|
||||
void MainWindow::MediaPaused() {
|
||||
@ -291,6 +299,8 @@ void MainWindow::MediaPlaying() {
|
||||
ui_.action_ban->setEnabled(lastfm->IsScrobblingEnabled() && is_lastfm);
|
||||
ui_.action_love->setEnabled(lastfm->IsScrobblingEnabled());
|
||||
|
||||
track_slider_->SetCanSeek(!is_lastfm);
|
||||
|
||||
track_position_timer_->start();
|
||||
UpdateTrackPosition();
|
||||
}
|
||||
@ -392,6 +402,8 @@ void MainWindow::UpdateTrackPosition() {
|
||||
lastfm->Scrobble();
|
||||
playlist_->set_scrobbled(true);
|
||||
}
|
||||
|
||||
track_slider_->SetValue(position, playlist_->current_item()->Metadata().length());
|
||||
}
|
||||
|
||||
void MainWindow::Love() {
|
||||
|
@ -14,6 +14,7 @@ class RadioModel;
|
||||
class Song;
|
||||
class RadioItem;
|
||||
class OSD;
|
||||
class TrackSlider;
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
class SystemTrayIcon;
|
||||
@ -70,6 +71,7 @@ class MainWindow : public QMainWindow {
|
||||
Ui::MainWindow ui_;
|
||||
SystemTrayIcon* tray_icon_;
|
||||
OSD* osd_;
|
||||
TrackSlider* track_slider_;
|
||||
|
||||
RadioModel* radio_model_;
|
||||
Playlist* playlist_;
|
||||
|
@ -142,3 +142,7 @@ void Player::StreamReady(const QUrl& original_url, const QUrl& media_url) {
|
||||
|
||||
lastfm_->NowPlaying(item->Metadata());
|
||||
}
|
||||
|
||||
void Player::Seek(int seconds) {
|
||||
engine_->seek(seconds * 1000);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ class Player : public QObject {
|
||||
void Previous();
|
||||
void Stop();
|
||||
void SetVolume(int value);
|
||||
void Seek(int seconds);
|
||||
|
||||
void TrackEnded();
|
||||
void StreamReady(const QUrl& original_url, const QUrl& media_url);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "playlist.h"
|
||||
#include "playlistheader.h"
|
||||
#include "radioloadingindicator.h"
|
||||
#include "trackslider.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QHeaderView>
|
||||
@ -91,19 +92,10 @@ QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem
|
||||
QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) const {
|
||||
bool ok = false;
|
||||
int seconds = value.toInt(&ok);
|
||||
QString ret;
|
||||
|
||||
if (ok && seconds > 0) {
|
||||
int hours = seconds / (60*60);
|
||||
int minutes = (seconds / 60) % 60;
|
||||
seconds %= 60;
|
||||
|
||||
if (hours)
|
||||
ret.sprintf("%d:%02d:%02d", hours, minutes, seconds);
|
||||
else
|
||||
ret.sprintf("%d:%02d", minutes, seconds);
|
||||
}
|
||||
return ret;
|
||||
if (ok && seconds > 0)
|
||||
return TrackSlider::PrettyTime(seconds);
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
|
||||
|
10
src/src.pro
10
src/src.pro
@ -44,7 +44,8 @@ SOURCES += main.cpp \
|
||||
radioloadingindicator.cpp \
|
||||
radioview.cpp \
|
||||
lastfmstationdialog.cpp \
|
||||
osd.cpp
|
||||
osd.cpp \
|
||||
trackslider.cpp
|
||||
HEADERS += mainwindow.h \
|
||||
player.h \
|
||||
library.h \
|
||||
@ -89,13 +90,15 @@ HEADERS += mainwindow.h \
|
||||
radioview.h \
|
||||
lastfmstationdialog.h \
|
||||
../3rdparty/qxt/keymapper_x11.h \
|
||||
osd.h
|
||||
osd.h \
|
||||
trackslider.h
|
||||
FORMS += mainwindow.ui \
|
||||
libraryconfig.ui \
|
||||
fileview.ui \
|
||||
lastfmconfig.ui \
|
||||
radioloadingindicator.ui \
|
||||
lastfmstationdialog.ui
|
||||
lastfmstationdialog.ui \
|
||||
trackslider.ui
|
||||
RESOURCES += ../data/data.qrc
|
||||
OTHER_FILES += ../data/schema.sql \
|
||||
../data/mainwindow.css
|
||||
@ -120,7 +123,6 @@ win32 {
|
||||
unix:!macx:SOURCES += osd_x11.cpp
|
||||
macx:SOURCES += osd_mac.cpp
|
||||
|
||||
|
||||
# QXT
|
||||
INCLUDEPATH += ../3rdparty/qxt
|
||||
HEADERS += ../3rdparty/qxt/qxtglobalshortcut.h
|
||||
|
58
src/trackslider.cpp
Normal file
58
src/trackslider.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "trackslider.h"
|
||||
|
||||
TrackSlider::TrackSlider(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ui_.setupUi(this);
|
||||
|
||||
QFont font("Courier");
|
||||
ui_.elapsed->setFont(font);
|
||||
ui_.remaining->setFont(font);
|
||||
|
||||
connect(ui_.slider, SIGNAL(sliderMoved(int)), SIGNAL(ValueChanged(int)));
|
||||
}
|
||||
|
||||
QSize TrackSlider::sizeHint() const {
|
||||
int width = 500;
|
||||
width += ui_.elapsed->sizeHint().width();
|
||||
width += ui_.remaining->sizeHint().width();
|
||||
|
||||
int height = qMax(ui_.slider->sizeHint().height(), ui_.elapsed->sizeHint().height());
|
||||
|
||||
return QSize(width, height);
|
||||
}
|
||||
|
||||
void TrackSlider::SetValue(int elapsed, int total) {
|
||||
ui_.slider->setMaximum(total);
|
||||
ui_.slider->setValue(elapsed);
|
||||
|
||||
ui_.elapsed->setText(PrettyTime(elapsed));
|
||||
ui_.remaining->setText(PrettyTime(total - elapsed));
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
void TrackSlider::SetStopped() {
|
||||
setEnabled(false);
|
||||
ui_.elapsed->setText("0:00:00");
|
||||
ui_.remaining->setText("0:00:00");
|
||||
ui_.slider->setValue(0);
|
||||
}
|
||||
|
||||
QString TrackSlider::PrettyTime(int seconds) {
|
||||
int hours = seconds / (60*60);
|
||||
int minutes = (seconds / 60) % 60;
|
||||
seconds %= 60;
|
||||
|
||||
QString ret;
|
||||
if (hours)
|
||||
ret.sprintf("%d:%02d:%02d", hours, minutes, seconds);
|
||||
else
|
||||
ret.sprintf("%d:%02d", minutes, seconds);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TrackSlider::SetCanSeek(bool can_seek) {
|
||||
ui_.slider->setEnabled(can_seek);
|
||||
}
|
31
src/trackslider.h
Normal file
31
src/trackslider.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef TRACKSLIDER_H
|
||||
#define TRACKSLIDER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui_trackslider.h"
|
||||
|
||||
class TrackSlider : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TrackSlider(QWidget* parent = 0);
|
||||
|
||||
// QWidget
|
||||
QSize sizeHint() const;
|
||||
|
||||
static QString PrettyTime(int seconds);
|
||||
|
||||
public slots:
|
||||
void SetValue(int elapsed, int total);
|
||||
void SetStopped();
|
||||
void SetCanSeek(bool can_seek);
|
||||
|
||||
signals:
|
||||
void ValueChanged(int value);
|
||||
|
||||
private:
|
||||
Ui::TrackSlider ui_;
|
||||
};
|
||||
|
||||
#endif // TRACKSLIDER_H
|
48
src/trackslider.ui
Normal file
48
src/trackslider.ui
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TrackSlider</class>
|
||||
<widget class="QWidget" name="TrackSlider">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>517</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="elapsed">
|
||||
<property name="text">
|
||||
<string>0:00:00</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="slider">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="remaining">
|
||||
<property name="text">
|
||||
<string>0:00:00</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user