diff --git a/src/libtomahawk/playlist/albumitemdelegate.cpp b/src/libtomahawk/playlist/albumitemdelegate.cpp index 8bf8c4d90..8ca9a28e9 100644 --- a/src/libtomahawk/playlist/albumitemdelegate.cpp +++ b/src/libtomahawk/playlist/albumitemdelegate.cpp @@ -278,6 +278,8 @@ AlbumItemDelegate::modelChanged() void AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx ) { + if ( !idx.isValid() ) + return; emit updateIndex( idx ); } diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index 9b74fa8a4..351c76d48 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -102,7 +102,9 @@ void ArtistView::setProxyModel( TreeProxyModel* model ) { m_proxyModel = model; - setItemDelegate( new TreeItemDelegate( this, m_proxyModel ) ); + TreeItemDelegate* del = new TreeItemDelegate( this, m_proxyModel ); + connect( del, SIGNAL( updateIndex( QModelIndex ) ), this, SLOT( update( QModelIndex ) ) ); + setItemDelegate( del ); QTreeView::setModel( m_proxyModel ); } diff --git a/src/libtomahawk/playlist/treeitemdelegate.cpp b/src/libtomahawk/playlist/treeitemdelegate.cpp index c5c6f2377..e1cfc133f 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.cpp +++ b/src/libtomahawk/playlist/treeitemdelegate.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2012 Leo Franchi * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,8 @@ #include "utils/tomahawkutilsgui.h" #include "utils/logger.h" +#include "utils/closure.h" +#include "utils/PixmapDelegateFader.h" #include "treemodelitem.h" #include "treeproxymodel.h" @@ -150,20 +153,24 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 ); // painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) ); - QPixmap cover; - if ( !item->album().isNull() ) + if ( !m_pixmaps.contains( index ) ) { - cover = item->album()->cover( r.size(), false ); - if ( cover.isNull() ) - cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, r.size() ); - } - else if ( !item->artist().isNull() ) - { - cover = item->artist()->cover( r.size(), false ); - if ( cover.isNull() ) - cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, r.size() ); + if ( !item->album().isNull() ) + { + m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size() ) ) ); + _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); + closure->setAutoDelete( false ); + } + else if ( !item->artist().isNull() ) + { + m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size() ) ) ); + _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); + closure->setAutoDelete( false ); + } } + const QPixmap cover = m_pixmaps[ index ]->currentPixmap(); + painter->drawPixmap( r, cover ); QTextOption to; @@ -175,3 +182,11 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, painter->restore(); } + + +void +TreeItemDelegate::doUpdateIndex( const QPersistentModelIndex& index ) +{ + emit updateIndex( index ); +} + diff --git a/src/libtomahawk/playlist/treeitemdelegate.h b/src/libtomahawk/playlist/treeitemdelegate.h index 2ed8b42d3..85a2924e2 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.h +++ b/src/libtomahawk/playlist/treeitemdelegate.h @@ -23,6 +23,10 @@ #include "dllmacro.h" +namespace Tomahawk { +class PixmapDelegateFader; +} + class ArtistView; class TreeProxyModel; @@ -39,9 +43,17 @@ protected: // QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; +signals: + void updateIndex( const QModelIndex& idx ); + +private slots: + void doUpdateIndex( const QPersistentModelIndex& index ); + private: ArtistView* m_view; TreeProxyModel* m_model; + + mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; }; #endif // TREEITEMDELEGATE_H