Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add fading for artist/albums in treeview as well

  • Loading branch information...
commit f1aa7b6d28e8e41676ff6ac2b7a3718235aaff92 1 parent 6c48be2
@lfranchi lfranchi authored
View
2  src/libtomahawk/playlist/albumitemdelegate.cpp
@@ -278,6 +278,8 @@ AlbumItemDelegate::modelChanged()
void
AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
{
+ if ( !idx.isValid() )
+ return;
emit updateIndex( idx );
}
View
4 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 );
}
View
37 src/libtomahawk/playlist/treeitemdelegate.cpp
@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
+ * Copyright 2012 Leo Franchi <lfranchi@kde.org>
*
* 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<TreeItemDelegate*>(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<TreeItemDelegate*>(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 );
+}
+
View
12 src/libtomahawk/playlist/treeitemdelegate.h
@@ -23,6 +23,10 @@
#include "dllmacro.h"
+namespace Tomahawk {
+class PixmapDelegateFader;
+}
+
class ArtistView;
class TreeProxyModel;
@@ -39,9 +43,17 @@ Q_OBJECT
// 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
Please sign in to comment.
Something went wrong with that request. Please try again.