void GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index ) { QPoint pos = m_playButton[ index ]->pos(); clearButtons(); AnimatedSpinner* spinner = new AnimatedSpinner( m_view ); spinner->setAutoCenter( false ); spinner->fadeIn(); spinner->move( pos ); spinner->setFocusPolicy( Qt::NoFocus ); spinner->installEventFilter( this ); 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() ) AudioEngine::instance()->playItem( m_model->playlistInterface(), item->query() ); else if ( !item->album().isNull() ) AudioEngine::instance()->playItem( item->album() ); else if ( !item->artist().isNull() ) AudioEngine::instance()->playItem( item->artist() ); } }
void GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index ) { QPoint pos = m_playButton[ index ]->pos(); foreach ( ImageButton* button, m_playButton ) button->deleteLater(); m_playButton.clear(); AnimatedSpinner* spinner = new AnimatedSpinner( m_view ); spinner->setAutoCenter( false ); spinner->fadeIn(); spinner->move( pos ); spinner->setFocusPolicy( Qt::NoFocus ); spinner->installEventFilter( this ); m_spinner[ index ] = spinner; PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( item ) { NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), const_cast<GridItemDelegate*>(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); m_closures.remove( index ); m_closures.insertMulti( index, NewClosure( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), const_cast<GridItemDelegate*>(this), SLOT( onPlaylistChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ) ); m_closures.insertMulti( index, NewClosure( AudioEngine::instance(), SIGNAL( stopped() ), const_cast<GridItemDelegate*>(this), SLOT( onPlaylistChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ) ); foreach ( _detail::Closure* closure, m_closures.values( index ) ) closure->setAutoDelete( false ); connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackFinished() ) ); if ( !item->query().isNull() ) AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), item->query() ); else if ( !item->album().isNull() ) AudioEngine::instance()->playItem( item->album() ); else if ( !item->artist().isNull() ) AudioEngine::instance()->playItem( item->artist() ); } }