mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Lazily load TrackView covers.
This commit is contained in:
@@ -204,7 +204,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
if ( useAvatars )
|
if ( useAvatars )
|
||||||
pixmap = source->avatar( Source::FancyStyle, ir.size() );
|
pixmap = source->avatar( Source::FancyStyle, ir.size() );
|
||||||
else
|
else
|
||||||
pixmap = item->query()->cover( ir.size() );
|
pixmap = item->query()->cover( ir.size(), false );
|
||||||
|
|
||||||
if ( pixmap.isNull() )
|
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
|
void
|
||||||
TrackModel::setCurrentItem( const QModelIndex& index )
|
TrackModel::setCurrentItem( const QModelIndex& index )
|
||||||
{
|
{
|
||||||
|
@@ -98,6 +98,8 @@ public:
|
|||||||
/// Returns a flat list of all tracks in this model
|
/// Returns a flat list of all tracks in this model
|
||||||
QList< Tomahawk::query_ptr > queries() const;
|
QList< Tomahawk::query_ptr > queries() const;
|
||||||
|
|
||||||
|
void getCover( const QModelIndex& index );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||||
void shuffleModeChanged( bool enabled );
|
void shuffleModeChanged( bool enabled );
|
||||||
|
@@ -110,15 +110,9 @@ TrackModelItem::setupItem( const Tomahawk::query_ptr& query, TrackModelItem* par
|
|||||||
m_isPlaying = false;
|
m_isPlaying = false;
|
||||||
toberemoved = false;
|
toberemoved = false;
|
||||||
m_query = query;
|
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 ) ),
|
connect( query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), SIGNAL( dataChanged() ) );
|
||||||
SIGNAL( dataChanged() ) );
|
connect( query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ), SIGNAL( dataChanged() ) );
|
||||||
|
connect( query.data(), SIGNAL( resultsChanged() ), SIGNAL( dataChanged() ) );
|
||||||
connect( query.data(), SIGNAL( resultsChanged() ),
|
connect( query.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
||||||
SIGNAL( dataChanged() ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,8 @@
|
|||||||
#include "artist.h"
|
#include "artist.h"
|
||||||
#include "album.h"
|
#include "album.h"
|
||||||
|
|
||||||
|
#define SCROLL_TIMEOUT 280
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +83,11 @@ TrackView::TrackView( QWidget* parent )
|
|||||||
setFont( f );
|
setFont( f );
|
||||||
#endif
|
#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( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
|
||||||
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||||
connect( m_contextMenu, SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) );
|
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_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
|
||||||
|
|
||||||
connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) );
|
connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) );
|
||||||
|
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
|
||||||
|
|
||||||
setAcceptDrops( true );
|
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
|
void
|
||||||
TrackView::currentChanged( const QModelIndex& current, const QModelIndex& previous )
|
TrackView::currentChanged( const QModelIndex& current, const QModelIndex& previous )
|
||||||
{
|
{
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QTreeView>
|
#include <QtGui/QTreeView>
|
||||||
#include <QtGui/QSortFilterProxyModel>
|
#include <QtGui/QSortFilterProxyModel>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
#include "contextmenu.h"
|
#include "contextmenu.h"
|
||||||
#include "playlistitemdelegate.h"
|
#include "playlistitemdelegate.h"
|
||||||
@@ -70,6 +71,9 @@ public slots:
|
|||||||
void playItem();
|
void playItem();
|
||||||
void onMenuTriggered( int action );
|
void onMenuTriggered( int action );
|
||||||
|
|
||||||
|
void onViewChanged();
|
||||||
|
void onScrollTimeout();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemActivated( const QModelIndex& index );
|
void itemActivated( const QModelIndex& index );
|
||||||
|
|
||||||
@@ -118,6 +122,8 @@ private:
|
|||||||
QModelIndex m_hoveredIndex;
|
QModelIndex m_hoveredIndex;
|
||||||
QModelIndex m_contextMenuIndex;
|
QModelIndex m_contextMenuIndex;
|
||||||
Tomahawk::ContextMenu* m_contextMenu;
|
Tomahawk::ContextMenu* m_contextMenu;
|
||||||
|
|
||||||
|
QTimer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRACKVIEW_H
|
#endif // TRACKVIEW_H
|
||||||
|
@@ -588,9 +588,6 @@ Query::setLoved( bool loved )
|
|||||||
QPixmap
|
QPixmap
|
||||||
Query::cover( const QSize& size, bool forceLoad ) const
|
Query::cover( const QSize& size, bool forceLoad ) const
|
||||||
{
|
{
|
||||||
if ( !forceLoad )
|
|
||||||
return QPixmap();
|
|
||||||
|
|
||||||
if ( m_albumPtr.isNull() )
|
if ( m_albumPtr.isNull() )
|
||||||
{
|
{
|
||||||
m_artistPtr = Artist::get( artist(), false );
|
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 );
|
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->infoLoaded() )
|
||||||
{
|
{
|
||||||
if ( !m_albumPtr->cover( size ).isNull() )
|
if ( !m_albumPtr->cover( size ).isNull() )
|
||||||
|
Reference in New Issue
Block a user