From 93b7fb3ce7ef5adbe81ea766a96313b51fac53bd Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 19 Aug 2014 08:24:47 +0200 Subject: [PATCH] * Update playback-bar below track when tracks is playing. --- src/libtomahawk/playlist/GridItemDelegate.cpp | 2 +- .../playlist/PlaylistItemDelegate.cpp | 34 +++++++++++++++++++ .../playlist/PlaylistItemDelegate.h | 4 +++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/GridItemDelegate.cpp b/src/libtomahawk/playlist/GridItemDelegate.cpp index 68b8e3251..5aed9893b 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.cpp +++ b/src/libtomahawk/playlist/GridItemDelegate.cpp @@ -256,7 +256,7 @@ GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index ) PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); - NewClosure( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), + NewClosure( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), const_cast(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); if ( item ) diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index 602cbd797..e580ba5e0 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -91,6 +91,9 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, PlayableProxyMode connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) ); connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) ); connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) ); + + connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted() ) ); + connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ) ); } @@ -648,6 +651,12 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem& if ( item->isPlaying() ) { + if ( m_nowPlaying != index ) + { + connect( AudioEngine::instance(), SIGNAL( timerMilliSeconds( qint64 ) ), SLOT( onAudioEngineTick( qint64 ) ), Qt::UniqueConnection ); + m_nowPlaying = QPersistentModelIndex( index ); + } + int h = extraRect.height() / 2; QRect playIconRect = extraRect.adjusted( extraRect.width() - h - 8, h / 2, -8, -h / 2 ); painter->drawPixmap( playIconRect, ImageRegistry::instance()->pixmap( RESPATH "images/play.svg", playIconRect.size() ) ); @@ -876,3 +885,28 @@ PlaylistItemDelegate::doUpdateIndex( const QPersistentModelIndex& index ) if ( index.isValid() ) emit updateIndex( index ); } + + +void +PlaylistItemDelegate::onAudioEngineTick( qint64 /* ms */ ) +{ + doUpdateIndex( m_nowPlaying ); +} + + +void +PlaylistItemDelegate::onPlaybackStarted() +{ + disconnect( AudioEngine::instance(), SIGNAL( timerMilliSeconds( qint64 ) ), this, SLOT( onAudioEngineTick( qint64 ) ) ); + doUpdateIndex( m_nowPlaying ); + m_nowPlaying = QModelIndex(); +} + + +void +PlaylistItemDelegate::onPlaybackStopped() +{ + disconnect( AudioEngine::instance(), SIGNAL( timerMilliSeconds( qint64 ) ), this, SLOT( onAudioEngineTick( qint64 ) ) ); + doUpdateIndex( m_nowPlaying ); + m_nowPlaying = QModelIndex(); +} diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.h b/src/libtomahawk/playlist/PlaylistItemDelegate.h index 23e76bfe2..f1b714e2a 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.h @@ -108,6 +108,9 @@ protected: protected slots: virtual void modelChanged(); + virtual void onAudioEngineTick( qint64 ms ); + virtual void onPlaybackStarted(); + virtual void onPlaybackStopped(); private: mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; @@ -117,6 +120,7 @@ private: mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects; QPersistentModelIndex m_hoveringOver; QPersistentModelIndex m_hoveringOverArtist; + mutable QPersistentModelIndex m_nowPlaying; TrackView* m_view; PlayableProxyModel* m_model;