diff --git a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp index 760795143..65d0197db 100644 --- a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp @@ -27,6 +27,7 @@ #include "source.h" #include "sourcelist.h" +#include "playlistview.h" #include "trackmodel.h" #include "trackmodelitem.h" #include "trackproxymodel.h" @@ -35,6 +36,8 @@ #include "utils/tomahawkutilsgui.h" #include "utils/logger.h" +#include +#include using namespace Tomahawk; @@ -55,6 +58,11 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, TrackPr m_bottomOption = QTextOption( Qt::AlignBottom ); m_bottomOption.setWrapMode( QTextOption::NoWrap ); + + connect( m_model->sourceModel(), SIGNAL( modelReset() ), this, SLOT( modelChanged() ) ); + if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) ) + connect( plView, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) ); + } @@ -127,7 +135,7 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& if ( m_view->header()->visualIndex( index.column() ) > 0 ) return; - QPixmap pixmap, avatar; + QPixmap avatar; QString artist, track, upperText, lowerText; unsigned int duration = 0; @@ -204,11 +212,15 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& painter->setPen( opt.palette.text().color() ); QRect pixmapRect = r.adjusted( figureRect.width() + 6, 0, -option.rect.width() + figureRect.width() + option.rect.height() - 6 + r.left(), 0 ); - pixmap = item->query()->cover( pixmapRect.size(), false ); - if ( !pixmap ) + + if ( !m_pixmaps.contains( index ) ) { - pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() ); + m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), pixmapRect.size(), false ) ) ); + _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); + closure->setAutoDelete( false ); } + + const QPixmap pixmap = m_pixmaps[ index ]->currentPixmap(); painter->drawPixmap( pixmapRect, pixmap ); r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 ); @@ -232,3 +244,18 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& } painter->restore(); } + + +void +PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx ) +{ + emit updateRequest( idx ); +} + + +void +PlaylistChartItemDelegate::modelChanged() +{ + m_pixmaps.clear(); +} + diff --git a/src/libtomahawk/playlist/PlaylistChartItemDelegate.h b/src/libtomahawk/playlist/PlaylistChartItemDelegate.h index 1819be8a0..7735c9cda 100644 --- a/src/libtomahawk/playlist/PlaylistChartItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistChartItemDelegate.h @@ -24,6 +24,10 @@ #include "dllmacro.h" +namespace Tomahawk { +class PixmapDelegateFader; +} + class TrackModel; class TrackModelItem; class TrackProxyModel; @@ -36,11 +40,18 @@ Q_OBJECT public: PlaylistChartItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 ); +signals: + void updateRequest( const QModelIndex& idx ); + protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; +private slots: + void modelChanged(); + void doUpdateIndex( const QPersistentModelIndex& idx ); + private: void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const; @@ -51,6 +62,8 @@ private: TrackView* m_view; TrackProxyModel* m_model; + + mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; }; #endif // PLAYLISTCHARTITEMDELEGATE_H diff --git a/src/libtomahawk/playlist/playlistview.h b/src/libtomahawk/playlist/playlistview.h index a02f10100..1a94f6890 100644 --- a/src/libtomahawk/playlist/playlistview.h +++ b/src/libtomahawk/playlist/playlistview.h @@ -56,6 +56,7 @@ public: signals: void nameChanged( const QString& title ); void destroyed( QWidget* widget ); + void modelChanged(); protected: void keyPressEvent( QKeyEvent* event ); diff --git a/src/libtomahawk/query.cpp b/src/libtomahawk/query.cpp index 8676ebf02..ea7ae1dc4 100644 --- a/src/libtomahawk/query.cpp +++ b/src/libtomahawk/query.cpp @@ -594,7 +594,7 @@ Query::setLoved( bool loved ) DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( q, QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) ); Database::instance()->enqueue( QSharedPointer(cmd) ); - + emit socialActionsLoaded(); } } @@ -638,7 +638,7 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co else desc += ", "; } - + if ( sa.source->isLocal() ) { if ( loveCounter == 1 ) @@ -654,13 +654,13 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co { if ( loveCounter > 3 ) desc += " " + tr( "and" ) + " " + tr( "%n other(s)", "", loveCounter - 3 ) + ""; - + if ( mode == Short ) desc = "" + tr( "%1 people" ).arg( loveCounter ) + ""; desc += " " + tr( "loved this track" ); //FIXME: more action descs required } - + return desc; } @@ -674,7 +674,9 @@ Query::cover( const QSize& size, bool forceLoad ) const m_artistPtr = Artist::get( artist(), false ); m_albumPtr = Album::get( m_artistPtr, album(), false ); connect( m_artistPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection ); + connect( m_artistPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection ); connect( m_albumPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection ); + connect( m_albumPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection ); } m_albumPtr->cover( size, forceLoad ); @@ -685,7 +687,7 @@ Query::cover( const QSize& size, bool forceLoad ) const return m_artistPtr->cover( size ); } - + return QPixmap(); } #endif diff --git a/src/libtomahawk/query.h b/src/libtomahawk/query.h index 724e53529..f84d58d61 100644 --- a/src/libtomahawk/query.h +++ b/src/libtomahawk/query.h @@ -139,6 +139,8 @@ signals: void playableStateChanged( bool state ); void resolvingFinished( bool hasResults ); + void coverChanged(); + // emitted when social actions are loaded void socialActionsLoaded(); void updated(); @@ -156,7 +158,7 @@ public slots: // resolve if not solved() void onResolverAdded(); void onResolverRemoved(); - + private slots: void onResultStatusChanged(); void refreshResults(); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 3a262af74..f8d698822 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -83,7 +83,9 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->tracksViewLeft->overlay()->setEnabled( false ); ui->tracksViewLeft->setHeaderHidden( true ); ui->tracksViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - ui->tracksViewLeft->setItemDelegate( new PlaylistChartItemDelegate( ui->tracksViewLeft, ui->tracksViewLeft->proxyModel() ) ); + PlaylistChartItemDelegate* del = new PlaylistChartItemDelegate( ui->tracksViewLeft, ui->tracksViewLeft->proxyModel() ); + connect( del, SIGNAL( updateRequest( QModelIndex ) ), ui->tracksViewLeft, SLOT( update( QModelIndex ) ) ); + ui->tracksViewLeft->setItemDelegate( del ); ui->tracksViewLeft->setUniformRowHeights( false ); TreeProxyModel* artistsProxy = new TreeProxyModel( ui->artistsViewLeft ); diff --git a/src/sourcetree/items/sourceitem.cpp b/src/sourcetree/items/sourceitem.cpp index 528d1b55f..73c908543 100644 --- a/src/sourcetree/items/sourceitem.cpp +++ b/src/sourcetree/items/sourceitem.cpp @@ -127,7 +127,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw SLOT( onAutoPlaylistsAdded( QList ) ), Qt::QueuedConnection ); connect( source->collection().data(), SIGNAL( stationsAdded( QList ) ), SLOT( onStationsAdded( QList ) ), Qt::QueuedConnection ); - + if ( m_source->isLocal() ) QTimer::singleShot( 0, this, SLOT( requestExpanding() ) ); }