mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 15:01:11 +02:00
Initial work on the sleeker slider
This commit is contained in:
@@ -95,6 +95,11 @@ AudioControls::AudioControls( QWidget* parent )
|
|||||||
ui->volumeSlider->setRange( 0, 100 );
|
ui->volumeSlider->setRange( 0, 100 );
|
||||||
ui->volumeSlider->setValue( AudioEngine::instance()->volume() );
|
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->seekSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( seek( int ) ) );
|
||||||
connect( ui->volumeSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( setVolume( int ) ) );
|
connect( ui->volumeSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( setVolume( int ) ) );
|
||||||
connect( ui->prevButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( previous() ) );
|
connect( ui->prevButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( previous() ) );
|
||||||
@@ -179,7 +184,7 @@ AudioControls::onVolumeChanged( int volume )
|
|||||||
void
|
void
|
||||||
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
|
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
|
||||||
{
|
{
|
||||||
tDebug( LOGEXTRA ) << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
onPlaybackLoading( result );
|
onPlaybackLoading( result );
|
||||||
|
|
||||||
@@ -242,7 +247,7 @@ AudioControls::infoSystemFinished( QString target )
|
|||||||
void
|
void
|
||||||
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||||
{
|
{
|
||||||
tDebug( LOGEXTRA ) << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_currentTrack = result;
|
m_currentTrack = result;
|
||||||
|
|
||||||
@@ -254,8 +259,16 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
|||||||
ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
|
ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
|
||||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) );
|
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 );
|
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->seekSlider->setVisible( true );
|
||||||
|
|
||||||
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
|
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
|
||||||
@@ -293,20 +306,26 @@ AudioControls::socialActionsLoaded()
|
|||||||
void
|
void
|
||||||
AudioControls::onPlaybackPaused()
|
AudioControls::onPlaybackPaused()
|
||||||
{
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
|
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
|
||||||
|
m_sliderTimeLine.setPaused( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioControls::onPlaybackResumed()
|
AudioControls::onPlaybackResumed()
|
||||||
{
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
|
ui->stackedLayout->setCurrentWidget( ui->pauseButton );
|
||||||
ui->loveButton->setVisible( true );
|
ui->loveButton->setVisible( true );
|
||||||
|
ui->seekSlider->setNeedsUpdate( true );
|
||||||
|
m_sliderTimeLine.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioControls::onPlaybackStopped()
|
AudioControls::onPlaybackStopped()
|
||||||
{
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
m_currentTrack.clear();
|
m_currentTrack.clear();
|
||||||
|
|
||||||
ui->artistTrackLabel->setText( "" );
|
ui->artistTrackLabel->setText( "" );
|
||||||
@@ -316,6 +335,8 @@ AudioControls::onPlaybackStopped()
|
|||||||
ui->timeLeftLabel->setText( "" );
|
ui->timeLeftLabel->setText( "" );
|
||||||
ui->coverImage->setPixmap( QPixmap() );
|
ui->coverImage->setPixmap( QPixmap() );
|
||||||
ui->seekSlider->setVisible( false );
|
ui->seekSlider->setVisible( false );
|
||||||
|
m_sliderTimeLine.stop();
|
||||||
|
m_sliderTimeLine.setCurrentTime( 0 );
|
||||||
|
|
||||||
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
|
ui->stackedLayout->setCurrentWidget( ui->playPauseButton );
|
||||||
ui->loveButton->setEnabled( false );
|
ui->loveButton->setEnabled( false );
|
||||||
@@ -326,6 +347,7 @@ AudioControls::onPlaybackStopped()
|
|||||||
void
|
void
|
||||||
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
||||||
{
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
if ( m_currentTrack.isNull() )
|
if ( m_currentTrack.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -334,7 +356,15 @@ AudioControls::onPlaybackTimer( qint64 msElapsed )
|
|||||||
const int seconds = msElapsed / 1000;
|
const int seconds = msElapsed / 1000;
|
||||||
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
||||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - 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 );
|
ui->seekSlider->blockSignals( false );
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#define AUDIOCONTROLS_H
|
#define AUDIOCONTROLS_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "playlistinterface.h"
|
#include "playlistinterface.h"
|
||||||
@@ -79,6 +80,7 @@ private slots:
|
|||||||
void droppedTracks( QList<Tomahawk::query_ptr> );
|
void droppedTracks( QList<Tomahawk::query_ptr> );
|
||||||
|
|
||||||
void socialActionsLoaded();
|
void socialActionsLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AudioControls *ui;
|
Ui::AudioControls *ui;
|
||||||
|
|
||||||
@@ -87,6 +89,8 @@ private:
|
|||||||
Tomahawk::result_ptr m_currentTrack;
|
Tomahawk::result_ptr m_currentTrack;
|
||||||
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
|
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
|
||||||
bool m_shuffled;
|
bool m_shuffled;
|
||||||
|
|
||||||
|
QTimeLine m_sliderTimeLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AUDIOCONTROLS_H
|
#endif // AUDIOCONTROLS_H
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "SeekSlider.h"
|
#include "SeekSlider.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
@@ -26,6 +27,8 @@
|
|||||||
|
|
||||||
SeekSlider::SeekSlider( QWidget* parent )
|
SeekSlider::SeekSlider( QWidget* parent )
|
||||||
: QSlider( parent )
|
: QSlider( parent )
|
||||||
|
, m_timeLine( 0 )
|
||||||
|
, m_needsUpdate( false )
|
||||||
{
|
{
|
||||||
setFixedHeight( 20 );
|
setFixedHeight( 20 );
|
||||||
setStyleSheet( "QSlider::groove::horizontal {"
|
setStyleSheet( "QSlider::groove::horizontal {"
|
||||||
@@ -64,3 +67,24 @@ SeekSlider::mousePressEvent( QMouseEvent* event )
|
|||||||
else
|
else
|
||||||
QSlider::mousePressEvent( event );
|
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 );
|
||||||
|
}
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
class QTimeLine;
|
||||||
|
|
||||||
class DLLEXPORT SeekSlider : public QSlider
|
class DLLEXPORT SeekSlider : public QSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -31,8 +33,20 @@ public:
|
|||||||
SeekSlider( QWidget* parent = 0 );
|
SeekSlider( QWidget* parent = 0 );
|
||||||
~SeekSlider();
|
~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:
|
protected:
|
||||||
void mousePressEvent( QMouseEvent* event );
|
void mousePressEvent( QMouseEvent* event );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimeLine* m_timeLine;
|
||||||
|
bool m_needsUpdate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SEEKSLIDER_H
|
#endif // SEEKSLIDER_H
|
||||||
|
Reference in New Issue
Block a user