diff --git a/src/libtomahawk/playlist/GridItemDelegate.cpp b/src/libtomahawk/playlist/GridItemDelegate.cpp index cfc074d06..c95795eb3 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.cpp +++ b/src/libtomahawk/playlist/GridItemDelegate.cpp @@ -257,6 +257,10 @@ GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index ) m_spinner[ index ] = spinner; PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); + + NewClosure( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), + const_cast(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); + if ( item ) { if ( !item->query().isNull() ) @@ -455,9 +459,55 @@ GridItemDelegate::onPlaybackFinished() } +void +GridItemDelegate::onPlayPauseHover( const QPersistentModelIndex& index ) +{ + if( m_pauseButton.contains( index ) ) + { + updatePlayPauseButton( m_pauseButton[ index ] ); + } +} + + +void +GridItemDelegate::updatePlayPauseButton( ImageButton* button, bool setState ) +{ + if ( button ) + { + if ( button->property( "paused" ).toBool() ) + { + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); + } + else + { + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); + } + + if ( setState ) + button->setProperty( "paused", !button->property( "paused" ).toBool() ); + } +} + + +void +GridItemDelegate::onPlayPausedClicked() +{ + ImageButton* button = qobject_cast< ImageButton* >( QObject::sender() ); + updatePlayPauseButton( button, true ); +} + + void GridItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index ) { + if( m_spinner.contains( index ) ) + { + LoadingSpinner* spinner = static_cast(m_spinner[ index ]); + spinner->fadeOut(); + } + clearButtons(); createPauseButton( index ); @@ -504,9 +554,11 @@ GridItemDelegate::createPauseButton( const QPersistentModelIndex& index ) button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); + button->setProperty( "paused", false ); button->show(); connect( button, SIGNAL( clicked( bool ) ), AudioEngine::instance(), SLOT( playPause() ) ); + connect( button, SIGNAL( clicked( bool ) ), this, SLOT( onPlayPausedClicked() ) ); m_pauseButton[ index ] = button; } diff --git a/src/libtomahawk/playlist/GridItemDelegate.h b/src/libtomahawk/playlist/GridItemDelegate.h index 36dca3945..1666769e7 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.h +++ b/src/libtomahawk/playlist/GridItemDelegate.h @@ -68,6 +68,7 @@ private slots: void onViewChanged(); void onPlaybackStarted( const QPersistentModelIndex& index ); + void onPlaybackFinished(); void onPlayClicked( const QPersistentModelIndex& index ); @@ -75,6 +76,10 @@ private slots: void fadingFrameChanged( const QPersistentModelIndex& ); void fadingFrameFinished( const QPersistentModelIndex& ); + void updatePlayPauseButton(ImageButton* button , bool setState = false ); + void onPlayPauseHover( const QPersistentModelIndex& index ); + void onPlayPausedClicked(); + private: QTimeLine* createTimeline( QTimeLine::Direction direction ); void createPauseButton( const QPersistentModelIndex& index );