mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Add fading for artist/albums in treeview as well
This commit is contained in:
parent
6c48be2563
commit
f1aa7b6d28
@ -278,6 +278,8 @@ AlbumItemDelegate::modelChanged()
|
||||
void
|
||||
AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
||||
{
|
||||
if ( !idx.isValid() )
|
||||
return;
|
||||
emit updateIndex( idx );
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user