mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
* Update GridItemDelegate's buttons when current index has changed.
This commit is contained in:
@@ -58,6 +58,8 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode
|
||||
|
||||
connect( proxy, SIGNAL( rowsAboutToBeInserted( QModelIndex, int, int ) ), SLOT( modelChanged() ) );
|
||||
connect( proxy, SIGNAL( rowsAboutToBeRemoved( QModelIndex, int, int ) ), SLOT( modelChanged() ) );
|
||||
connect( proxy->playlistInterface().data(), SIGNAL( currentIndexChanged() ), SLOT( onCurrentIndexChanged() ), Qt::UniqueConnection );
|
||||
|
||||
connect( m_view, SIGNAL( scrolledContents( int, int ) ), SLOT( onViewChanged() ) );
|
||||
connect( m_view, SIGNAL( resized() ), SLOT( onViewChanged() ) );
|
||||
}
|
||||
@@ -239,9 +241,7 @@ void
|
||||
GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index )
|
||||
{
|
||||
QPoint pos = m_playButton[ index ]->pos();
|
||||
foreach ( ImageButton* button, m_playButton )
|
||||
button->deleteLater();
|
||||
m_playButton.clear();
|
||||
clearButtons();
|
||||
|
||||
AnimatedSpinner* spinner = new AnimatedSpinner( m_view );
|
||||
spinner->setAutoCenter( false );
|
||||
@@ -255,23 +255,8 @@ GridItemDelegate::onPlayClicked( const QPersistentModelIndex& index )
|
||||
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() );
|
||||
AudioEngine::instance()->playItem( m_model->playlistInterface(), item->query() );
|
||||
else if ( !item->album().isNull() )
|
||||
AudioEngine::instance()->playItem( item->album() );
|
||||
else if ( !item->artist().isNull() )
|
||||
@@ -418,18 +403,12 @@ GridItemDelegate::modelChanged()
|
||||
m_hoveringOver = QPersistentModelIndex();
|
||||
m_hoverIndex = QPersistentModelIndex();
|
||||
|
||||
foreach ( ImageButton* button, m_playButton )
|
||||
button->deleteLater();
|
||||
m_playButton.clear();
|
||||
foreach ( ImageButton* button, m_pauseButton )
|
||||
button->deleteLater();
|
||||
m_pauseButton.clear();
|
||||
foreach ( QWidget* widget, m_spinner )
|
||||
widget->deleteLater();
|
||||
m_spinner.clear();
|
||||
clearButtons();
|
||||
|
||||
if ( GridView* view = qobject_cast< GridView* >( m_view ) )
|
||||
m_model = view->proxyModel();
|
||||
|
||||
connect( m_model->playlistInterface().data(), SIGNAL( currentIndexChanged() ), SLOT( onCurrentIndexChanged() ), Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
|
||||
@@ -466,78 +445,58 @@ GridItemDelegate::onViewChanged()
|
||||
void
|
||||
GridItemDelegate::onPlaybackFinished()
|
||||
{
|
||||
foreach ( ImageButton* button, m_pauseButton )
|
||||
button->deleteLater();
|
||||
m_pauseButton.clear();
|
||||
clearButtons();
|
||||
|
||||
emit stoppedPlaying( QModelIndex() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GridItemDelegate::onPlaylistChanged( const QPersistentModelIndex& index )
|
||||
GridItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
||||
{
|
||||
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||
if ( item )
|
||||
{
|
||||
bool finished = false;
|
||||
clearButtons();
|
||||
createPauseButton( index );
|
||||
|
||||
if ( !item->query().isNull() )
|
||||
{
|
||||
if ( !item->query()->numResults() || AudioEngine::instance()->currentTrack() != item->query()->results().first() )
|
||||
finished = true;
|
||||
}
|
||||
else if ( !item->album().isNull() )
|
||||
{
|
||||
if ( AudioEngine::instance()->currentTrackPlaylist() != item->album()->playlistInterface( Tomahawk::Mixed ) )
|
||||
finished = true;
|
||||
}
|
||||
else if ( !item->artist().isNull() )
|
||||
{
|
||||
if ( AudioEngine::instance()->currentTrackPlaylist() != item->artist()->playlistInterface( Tomahawk::Mixed ) )
|
||||
finished = true;
|
||||
}
|
||||
|
||||
if ( finished )
|
||||
{
|
||||
foreach ( _detail::Closure* closure, m_closures.values( index ) )
|
||||
closure->deleteLater();
|
||||
|
||||
if ( m_pauseButton.contains( index ) )
|
||||
{
|
||||
m_pauseButton[ index ]->deleteLater();
|
||||
m_pauseButton.remove( index );
|
||||
}
|
||||
if ( m_spinner.contains( index ) )
|
||||
{
|
||||
m_spinner[ index ]->deleteLater();
|
||||
m_spinner.remove( index );
|
||||
}
|
||||
|
||||
emit stoppedPlaying( index );
|
||||
}
|
||||
}
|
||||
emit startedPlaying( index );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GridItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
||||
GridItemDelegate::clearButtons()
|
||||
{
|
||||
if ( !m_spinner.contains( index ) )
|
||||
return;
|
||||
|
||||
QPoint pos = m_spinner[ index ]->pos();
|
||||
foreach ( QWidget* widget, m_spinner.values() )
|
||||
{
|
||||
delete widget;
|
||||
}
|
||||
foreach ( ImageButton* button, m_playButton )
|
||||
button->deleteLater();
|
||||
m_playButton.clear();
|
||||
foreach ( ImageButton* button, m_pauseButton )
|
||||
button->deleteLater();
|
||||
m_pauseButton.clear();
|
||||
foreach ( QWidget* widget, m_spinner )
|
||||
widget->deleteLater();
|
||||
m_spinner.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GridItemDelegate::onCurrentIndexChanged()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_model-> currentIndex();
|
||||
if ( m_model->currentIndex().isValid() )
|
||||
{
|
||||
onPlaybackStarted( m_model->currentIndex() );
|
||||
}
|
||||
else
|
||||
onPlaybackFinished();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GridItemDelegate::createPauseButton( const QPersistentModelIndex& index )
|
||||
{
|
||||
ImageButton* button = new ImageButton( m_view );
|
||||
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 );
|
||||
button->setFixedSize( 48, 48 );
|
||||
button->move( pos );
|
||||
button->move( m_view->visualRect( index ).center() - QPoint( 23, 23 ) );
|
||||
button->setContentsMargins( 0, 0, 0, 0 );
|
||||
button->setFocusPolicy( Qt::NoFocus );
|
||||
button->installEventFilter( this );
|
||||
@@ -546,8 +505,6 @@ GridItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
||||
connect( button, SIGNAL( clicked( bool ) ), AudioEngine::instance(), SLOT( playPause() ) );
|
||||
|
||||
m_pauseButton[ index ] = button;
|
||||
|
||||
emit startedPlaying( index );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -64,19 +64,21 @@ signals:
|
||||
private slots:
|
||||
void modelChanged();
|
||||
void doUpdateIndex( const QPersistentModelIndex& idx );
|
||||
void onCurrentIndexChanged();
|
||||
|
||||
void onViewChanged();
|
||||
void onPlaybackStarted( const QPersistentModelIndex& index );
|
||||
void onPlaybackFinished();
|
||||
|
||||
void onPlayClicked( const QPersistentModelIndex& index );
|
||||
void onPlaylistChanged( const QPersistentModelIndex& index );
|
||||
|
||||
void fadingFrameChanged( const QPersistentModelIndex& );
|
||||
void fadingFrameFinished( const QPersistentModelIndex& );
|
||||
|
||||
private:
|
||||
QTimeLine* createTimeline( QTimeLine::Direction direction );
|
||||
void createPauseButton( const QPersistentModelIndex& index );
|
||||
void clearButtons();
|
||||
|
||||
QAbstractItemView* m_view;
|
||||
PlayableProxyModel* m_model;
|
||||
@@ -94,7 +96,6 @@ private:
|
||||
mutable QHash< QPersistentModelIndex, ImageButton* > m_playButton;
|
||||
mutable QHash< QPersistentModelIndex, ImageButton* > m_pauseButton;
|
||||
mutable QHash< QPersistentModelIndex, QTimeLine* > m_hoverFaders;
|
||||
mutable QHash< QPersistentModelIndex, _detail::Closure* > m_closures;
|
||||
};
|
||||
|
||||
#endif // GRIDITEMDELEGATE_H
|
||||
|
Reference in New Issue
Block a user