mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 13:43:11 +02:00
Add fading for artist/albums in treeview as well
This commit is contained in:
@@ -278,6 +278,8 @@ AlbumItemDelegate::modelChanged()
|
|||||||
void
|
void
|
||||||
AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
||||||
{
|
{
|
||||||
|
if ( !idx.isValid() )
|
||||||
|
return;
|
||||||
emit updateIndex( idx );
|
emit updateIndex( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -102,7 +102,9 @@ void
|
|||||||
ArtistView::setProxyModel( TreeProxyModel* model )
|
ArtistView::setProxyModel( TreeProxyModel* model )
|
||||||
{
|
{
|
||||||
m_proxyModel = 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 );
|
QTreeView::setModel( m_proxyModel );
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,6 +29,8 @@
|
|||||||
|
|
||||||
#include "utils/tomahawkutilsgui.h"
|
#include "utils/tomahawkutilsgui.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include "utils/closure.h"
|
||||||
|
#include "utils/PixmapDelegateFader.h"
|
||||||
|
|
||||||
#include "treemodelitem.h"
|
#include "treemodelitem.h"
|
||||||
#include "treeproxymodel.h"
|
#include "treeproxymodel.h"
|
||||||
@@ -150,19 +153,23 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 );
|
QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 );
|
||||||
// painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) );
|
// painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) );
|
||||||
|
|
||||||
QPixmap cover;
|
if ( !m_pixmaps.contains( index ) )
|
||||||
|
{
|
||||||
if ( !item->album().isNull() )
|
if ( !item->album().isNull() )
|
||||||
{
|
{
|
||||||
cover = item->album()->cover( r.size(), false );
|
m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size() ) ) );
|
||||||
if ( cover.isNull() )
|
_detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<TreeItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
|
||||||
cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, r.size() );
|
closure->setAutoDelete( false );
|
||||||
}
|
}
|
||||||
else if ( !item->artist().isNull() )
|
else if ( !item->artist().isNull() )
|
||||||
{
|
{
|
||||||
cover = item->artist()->cover( r.size(), false );
|
m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size() ) ) );
|
||||||
if ( cover.isNull() )
|
_detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<TreeItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
|
||||||
cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, r.size() );
|
closure->setAutoDelete( false );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPixmap cover = m_pixmaps[ index ]->currentPixmap();
|
||||||
|
|
||||||
painter->drawPixmap( r, cover );
|
painter->drawPixmap( r, cover );
|
||||||
|
|
||||||
@@ -175,3 +182,11 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TreeItemDelegate::doUpdateIndex( const QPersistentModelIndex& index )
|
||||||
|
{
|
||||||
|
emit updateIndex( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,10 @@
|
|||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
class PixmapDelegateFader;
|
||||||
|
}
|
||||||
|
|
||||||
class ArtistView;
|
class ArtistView;
|
||||||
class TreeProxyModel;
|
class TreeProxyModel;
|
||||||
|
|
||||||
@@ -39,9 +43,17 @@ protected:
|
|||||||
|
|
||||||
// QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
// 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:
|
private:
|
||||||
ArtistView* m_view;
|
ArtistView* m_view;
|
||||||
TreeProxyModel* m_model;
|
TreeProxyModel* m_model;
|
||||||
|
|
||||||
|
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TREEITEMDELEGATE_H
|
#endif // TREEITEMDELEGATE_H
|
||||||
|
Reference in New Issue
Block a user