mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Lazily load TrackView covers.
This commit is contained in:
parent
ccd3e19fac
commit
6409113c0e
@ -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() )
|
||||
{
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -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 );
|
||||
|
@ -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<Tomahawk::result_ptr> ) ),
|
||||
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<Tomahawk::result_ptr> ) ), 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() ) );
|
||||
}
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QtGui/QTreeView>
|
||||
#include <QtGui/QSortFilterProxyModel>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#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
|
||||
|
@ -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() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user