diff --git a/src/libtomahawk/playlist/playlistitemdelegate.cpp b/src/libtomahawk/playlist/playlistitemdelegate.cpp index d0520cc20..eb9016760 100644 --- a/src/libtomahawk/playlist/playlistitemdelegate.cpp +++ b/src/libtomahawk/playlist/playlistitemdelegate.cpp @@ -204,7 +204,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& if ( useAvatars ) pixmap = source->avatar( Source::FancyStyle, ir.size() ); else - pixmap = item->query()->cover( ir.size() ); + pixmap = item->query()->cover( ir.size(), false ); if ( pixmap.isNull() ) { diff --git a/src/libtomahawk/playlist/trackmodel.cpp b/src/libtomahawk/playlist/trackmodel.cpp index a9b2c8e9f..eae2fca8f 100644 --- a/src/libtomahawk/playlist/trackmodel.cpp +++ b/src/libtomahawk/playlist/trackmodel.cpp @@ -258,6 +258,14 @@ TrackModel::headerData( int section, Qt::Orientation orientation, int role ) con } +void +TrackModel::getCover( const QModelIndex& index ) +{ + TrackModelItem* item = itemFromIndex( index ); + item->query()->cover( QSize( 0, 0 ) ); +} + + void TrackModel::setCurrentItem( const QModelIndex& index ) { diff --git a/src/libtomahawk/playlist/trackmodel.h b/src/libtomahawk/playlist/trackmodel.h index 0de4ee1db..a368c508b 100644 --- a/src/libtomahawk/playlist/trackmodel.h +++ b/src/libtomahawk/playlist/trackmodel.h @@ -98,6 +98,8 @@ public: /// Returns a flat list of all tracks in this model QList< Tomahawk::query_ptr > queries() const; + void getCover( const QModelIndex& index ); + signals: void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/playlist/trackmodelitem.cpp b/src/libtomahawk/playlist/trackmodelitem.cpp index 82ae30551..b6e1ce452 100644 --- a/src/libtomahawk/playlist/trackmodelitem.cpp +++ b/src/libtomahawk/playlist/trackmodelitem.cpp @@ -110,15 +110,9 @@ TrackModelItem::setupItem( const Tomahawk::query_ptr& query, TrackModelItem* par m_isPlaying = false; toberemoved = false; m_query = query; - if ( !query->numResults() ) - { - connect( query.data(), SIGNAL( resultsAdded( QList ) ), - SIGNAL( dataChanged() ) ); - connect( query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ), - SIGNAL( dataChanged() ) ); - - connect( query.data(), SIGNAL( resultsChanged() ), - SIGNAL( dataChanged() ) ); - } + connect( query.data(), SIGNAL( resultsAdded( QList ) ), SIGNAL( dataChanged() ) ); + connect( query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ), SIGNAL( dataChanged() ) ); + connect( query.data(), SIGNAL( resultsChanged() ), SIGNAL( dataChanged() ) ); + connect( query.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) ); } diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 7111cd68c..5b9d0564d 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -36,6 +36,8 @@ #include "artist.h" #include "album.h" +#define SCROLL_TIMEOUT 280 + using namespace Tomahawk; @@ -81,6 +83,11 @@ TrackView::TrackView( QWidget* parent ) setFont( f ); #endif + m_timer.setInterval( SCROLL_TIMEOUT ); + connect( verticalScrollBar(), SIGNAL( rangeChanged( int, int ) ), SLOT( onViewChanged() ) ); + connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), SLOT( onViewChanged() ) ); + connect( &m_timer, SIGNAL( timeout() ), SLOT( onScrollTimeout() ) ); + connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) ); connect( m_contextMenu, SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) ); @@ -136,6 +143,7 @@ TrackView::setTrackModel( TrackModel* model ) connect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) ); connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); + connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); setAcceptDrops( true ); @@ -152,6 +160,44 @@ TrackView::setTrackModel( TrackModel* model ) } +void +TrackView::onViewChanged() +{ + if ( m_timer.isActive() ) + m_timer.stop(); + + m_timer.start(); +} + + +void +TrackView::onScrollTimeout() +{ + if ( m_timer.isActive() ) + m_timer.stop(); + + QModelIndex left = indexAt( viewport()->rect().topLeft() ); + while ( left.isValid() && left.parent().isValid() ) + left = left.parent(); + + QModelIndex right = indexAt( viewport()->rect().bottomLeft() ); + while ( right.isValid() && right.parent().isValid() ) + right = right.parent(); + + int max = m_proxyModel->playlistInterface()->trackCount(); + if ( right.isValid() ) + max = right.row(); + + if ( !max ) + return; + + for ( int i = left.row(); i <= max; i++ ) + { + m_model->getCover( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); + } +} + + void TrackView::currentChanged( const QModelIndex& current, const QModelIndex& previous ) { diff --git a/src/libtomahawk/playlist/trackview.h b/src/libtomahawk/playlist/trackview.h index 45bb1b23c..c6900d9f2 100644 --- a/src/libtomahawk/playlist/trackview.h +++ b/src/libtomahawk/playlist/trackview.h @@ -21,6 +21,7 @@ #include #include +#include #include "contextmenu.h" #include "playlistitemdelegate.h" @@ -70,6 +71,9 @@ public slots: void playItem(); void onMenuTriggered( int action ); + void onViewChanged(); + void onScrollTimeout(); + signals: void itemActivated( const QModelIndex& index ); @@ -118,6 +122,8 @@ private: QModelIndex m_hoveredIndex; QModelIndex m_contextMenuIndex; Tomahawk::ContextMenu* m_contextMenu; + + QTimer m_timer; }; #endif // TRACKVIEW_H diff --git a/src/libtomahawk/query.cpp b/src/libtomahawk/query.cpp index fb5285216..7f000aab2 100644 --- a/src/libtomahawk/query.cpp +++ b/src/libtomahawk/query.cpp @@ -588,9 +588,6 @@ Query::setLoved( bool loved ) QPixmap Query::cover( const QSize& size, bool forceLoad ) const { - if ( !forceLoad ) - return QPixmap(); - if ( m_albumPtr.isNull() ) { m_artistPtr = Artist::get( artist(), false ); @@ -599,7 +596,7 @@ Query::cover( const QSize& size, bool forceLoad ) const connect( m_albumPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection ); } - m_albumPtr->cover( size ); + m_albumPtr->cover( size, forceLoad ); if ( m_albumPtr->infoLoaded() ) { if ( !m_albumPtr->cover( size ).isNull() )