From eb87952ce503498d158cb6a57fee015e4d9fd236 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 19 May 2012 02:05:31 +0200 Subject: [PATCH] * Fixed crash and show hover state for album items again. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 3 ++ .../playlist/AlbumItemDelegate.cpp | 38 ++++++++----------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index cb30086de..18384d59a 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -65,6 +65,9 @@ AlbumPlaylistInterface::siblingItem( int itemsAway ) if ( p >= m_queries.count() ) return Tomahawk::result_ptr(); + if ( !m_queries.at( p )->numResults() ) + return siblingItem( itemsAway + 1 ); + m_currentTrack = p; m_currentItem = m_queries.at( p )->results().first(); return m_currentItem; diff --git a/src/libtomahawk/playlist/AlbumItemDelegate.cpp b/src/libtomahawk/playlist/AlbumItemDelegate.cpp index 24d810b04..1812a4fa9 100644 --- a/src/libtomahawk/playlist/AlbumItemDelegate.cpp +++ b/src/libtomahawk/playlist/AlbumItemDelegate.cpp @@ -160,7 +160,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, painter->drawPixmap( r, cover.scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ); -/* if ( m_hoverIndex == index ) + if ( m_hoverIndex == index ) { painter->save(); @@ -168,15 +168,9 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, painter->setBrush( QColor( 33, 33, 33 ) ); painter->setOpacity( 0.5 ); painter->drawRect( r ); - painter->setOpacity( 1.0 ); - QPixmap playButton = QPixmap( RESPATH "images/play-rest.png" ); - int delta = ( r.width() - playButton.width() ) / 2; - m_playButtonRect = r.adjusted( delta, delta, -delta, -delta ); - painter->drawPixmap( m_playButtonRect, playButton ); - painter->restore(); - }*/ + } painter->save(); @@ -257,31 +251,31 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, void AlbumItemDelegate::onPlayClicked( const QPersistentModelIndex& index ) { - AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); - if ( item ) - { - 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() ); - } - QPoint pos = m_button[ index ]->pos(); foreach ( ImageButton* button, m_button ) button->deleteLater(); m_button.clear(); - _detail::Closure* closure = NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), - const_cast(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); - AnimatedSpinner* spinner = new AnimatedSpinner( m_view ); spinner->setAutoCenter( false ); spinner->fadeIn(); spinner->move( pos ); m_subWidgets[ index ] = spinner; + + AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); + if ( item ) + { + _detail::Closure* closure = NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), + const_cast(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); + + 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() ); + } }