Permalink
Browse files

Fade out spinner and update playstate on cover button

  • Loading branch information...
1 parent 5b4d68e commit 8e1bdf5f7b16b456f7b624b657b6bc5e06db1fa0 @hugolm84 hugolm84 committed Apr 2, 2013
Showing with 57 additions and 0 deletions.
  1. +52 −0 src/libtomahawk/playlist/GridItemDelegate.cpp
  2. +5 −0 src/libtomahawk/playlist/GridItemDelegate.h
@@ -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<GridItemDelegate*>(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<LoadingSpinner*>(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;
}
@@ -68,13 +68,18 @@ private slots:
void onViewChanged();
void onPlaybackStarted( const QPersistentModelIndex& index );
+
void onPlaybackFinished();
void onPlayClicked( const QPersistentModelIndex& index );
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 );

0 comments on commit 8e1bdf5

Please sign in to comment.