1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-24 06:33:04 +02:00

Initial work on the sleeker slider

This commit is contained in:
Jeff Mitchell
2011-08-28 04:16:18 -04:00
parent d2af8a8a39
commit e5f6f40289
4 changed files with 77 additions and 5 deletions

View File

@@ -90,11 +90,16 @@ AudioControls::AudioControls( QWidget* parent )
ui->ownerLabel->setForegroundRole( QPalette::Dark );
ui->metaDataArea->setStyleSheet( "QWidget#metaDataArea {\nborder-width: 4px;\nborder-image: url(" RESPATH "images/now-playing-panel.png) 4 4 4 4 stretch stretch; }" );
ui->seekSlider->setEnabled( true );
ui->volumeSlider->setRange( 0, 100 );
ui->volumeSlider->setValue( AudioEngine::instance()->volume() );
m_sliderTimeLine.setCurveShape( QTimeLine::LinearCurve );
ui->seekSlider->setTimeLine( &m_sliderTimeLine );
connect( &m_sliderTimeLine, SIGNAL( frameChanged( int ) ), ui->seekSlider, SLOT( setValue( int ) ) );
connect( ui->seekSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( seek( int ) ) );
connect( ui->volumeSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( setVolume( int ) ) );
connect( ui->prevButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( previous() ) );
@@ -179,7 +184,7 @@ AudioControls::onVolumeChanged( int volume )
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
tDebug( LOGEXTRA ) << Q_FUNC_INFO;
tDebug() << Q_FUNC_INFO;
onPlaybackLoading( result );
@@ -242,7 +247,7 @@ AudioControls::infoSystemFinished( QString target )
void
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
tDebug( LOGEXTRA ) << Q_FUNC_INFO;
tDebug() << Q_FUNC_INFO;
m_currentTrack = result;
@@ -254,8 +259,16 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) );
ui->seekSlider->setRange( 0, m_currentTrack->duration() * 1000 );
ui->seekSlider->setRange( 0, result->duration() * 1000 );
ui->seekSlider->setValue( 0 );
tLog() << Q_FUNC_INFO << " setting sliderTimeLine duration to " << (result->duration() * 1000);
tLog() << Q_FUNC_INFO << " setting sliderTimeLine frames to " << (result->duration() * 1000);
m_sliderTimeLine.setDuration( result->duration() * 1000 );
m_sliderTimeLine.setFrameRange( 0, result->duration() * 1000 );
m_sliderTimeLine.setCurrentTime( 0 );
ui->seekSlider->setVisible( true );
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
@@ -293,20 +306,26 @@ AudioControls::socialActionsLoaded()
void
AudioControls::onPlaybackPaused()
{
tDebug() << Q_FUNC_INFO;
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
m_sliderTimeLine.setPaused( true );
}
void
AudioControls::onPlaybackResumed()
{
tDebug() << Q_FUNC_INFO;
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
ui->loveButton->setVisible( true );
ui->seekSlider->setNeedsUpdate( true );
m_sliderTimeLine.resume();
}
void
AudioControls::onPlaybackStopped()
{
tDebug() << Q_FUNC_INFO;
m_currentTrack.clear();
ui->artistTrackLabel->setText( "" );
@@ -316,6 +335,8 @@ AudioControls::onPlaybackStopped()
ui->timeLeftLabel->setText( "" );
ui->coverImage->setPixmap( QPixmap() );
ui->seekSlider->setVisible( false );
m_sliderTimeLine.stop();
m_sliderTimeLine.setCurrentTime( 0 );
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
ui->loveButton->setEnabled( false );
@@ -326,6 +347,7 @@ AudioControls::onPlaybackStopped()
void
AudioControls::onPlaybackTimer( qint64 msElapsed )
{
tDebug() << Q_FUNC_INFO;
if ( m_currentTrack.isNull() )
return;
@@ -334,7 +356,15 @@ AudioControls::onPlaybackTimer( qint64 msElapsed )
const int seconds = msElapsed / 1000;
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) );
ui->seekSlider->setValue( msElapsed );
tLog() << Q_FUNC_INFO << " setting sliderTimeLine elapsed time to " << msElapsed;
if ( ui->seekSlider->needsUpdate() )
{
m_sliderTimeLine.setCurrentTime( msElapsed );
ui->seekSlider->setNeedsUpdate( false );
}
else if ( m_sliderTimeLine.state() == QTimeLine::NotRunning )
m_sliderTimeLine.start();
ui->seekSlider->blockSignals( false );
}

View File

@@ -20,6 +20,7 @@
#define AUDIOCONTROLS_H
#include <QWidget>
#include <QTimeLine>
#include "result.h"
#include "playlistinterface.h"
@@ -79,6 +80,7 @@ private slots:
void droppedTracks( QList<Tomahawk::query_ptr> );
void socialActionsLoaded();
private:
Ui::AudioControls *ui;
@@ -87,6 +89,8 @@ private:
Tomahawk::result_ptr m_currentTrack;
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
bool m_shuffled;
QTimeLine m_sliderTimeLine;
};
#endif // AUDIOCONTROLS_H

View File

@@ -19,6 +19,7 @@
#include "SeekSlider.h"
#include <QMouseEvent>
#include <QTimeLine>
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
@@ -26,6 +27,8 @@
SeekSlider::SeekSlider( QWidget* parent )
: QSlider( parent )
, m_timeLine( 0 )
, m_needsUpdate( false )
{
setFixedHeight( 20 );
setStyleSheet( "QSlider::groove::horizontal {"
@@ -64,3 +67,24 @@ SeekSlider::mousePressEvent( QMouseEvent* event )
else
QSlider::mousePressEvent( event );
}
void
SeekSlider::setValue( int value )
{
int newVal = value;
if ( value > maximum() )
newVal = maximum();
if ( value < minimum() )
newVal = minimum();
if ( !m_timeLine || sender() != m_timeLine )
{
QSlider::setValue( newVal );
return;
}
blockSignals( true );
QSlider::setValue( newVal );
blockSignals( false );
}

View File

@@ -23,6 +23,8 @@
#include "dllmacro.h"
class QTimeLine;
class DLLEXPORT SeekSlider : public QSlider
{
Q_OBJECT
@@ -31,8 +33,20 @@ public:
SeekSlider( QWidget* parent = 0 );
~SeekSlider();
void setTimeLine( QTimeLine* timeline ) { m_timeLine = timeline; }
void setNeedsUpdate( bool needsUpdate ) { m_needsUpdate = needsUpdate; }
bool needsUpdate() { return m_needsUpdate; }
public slots:
void setValue( int value );
protected:
void mousePressEvent( QMouseEvent* event );
private:
QTimeLine* m_timeLine;
bool m_needsUpdate;
};
#endif // SEEKSLIDER_H