From 344416ec80558bfcb24cbcc0650fecbb19da830f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Thu, 28 Jan 2010 16:11:56 +0100 Subject: [PATCH] QT4 Icon view: cache album art pixmap The QPixmapCache default size is 10240kB on desktops, this leaves room for 640 pictures 64x64 in rgba Improves scrolling with a lot of items. Also use art url from the first children with art for nodes without art TODO: cache the full rendering (text + art), QPixmap is a QPaintDevice subclass --- .../gui/qt4/components/playlist/icon_view.cpp | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp index dadd7d777c..613f2e6c84 100644 --- a/modules/gui/qt4/components/playlist/icon_view.cpp +++ b/modules/gui/qt4/components/playlist/icon_view.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "assert.h" @@ -39,6 +40,22 @@ #define ITEMS_SPACING 10 #define ART_RADIUS 5 +static QPixmap find_art_pixmap( const QString& url ) +{ + QPixmap pix; + + if( QPixmapCache::find( url, pix ) ) /* great, we found it */ + return pix; + + if( url.isEmpty() || !pix.load( url ) ) + pix = QPixmap( ":/noart64" ); + else + pix = pix.scaled( ART_SIZE, ART_SIZE, Qt::KeepAspectRatioByExpanding ); + + QPixmapCache::insert( url, pix ); /* save it for next time */ + return pix; +} + void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform ); @@ -50,19 +67,25 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt PLItem *currentItem = static_cast( index.internalPointer() ); assert( currentItem ); - QPixmap pix; + QPixmap artpix; QString url = InputManager::decodeArtURL( currentItem->inputItem() ); - if( !url.isEmpty() && pix.load( url ) ) - { - pix = pix.scaled( ART_SIZE, ART_SIZE, Qt::KeepAspectRatioByExpanding ); - } - else + /* look up through all children and use the first picture found */ + if( url.isEmpty() ) { - pix = QPixmap( ":/noart64" ); + int children = currentItem->childCount(); + for( int i = 0; i < children; i++ ) + { + PLItem *child = currentItem->child( i ); + url = InputManager::decodeArtURL( child->inputItem() ); + if( !url.isEmpty() ) + break; + } } QRect artRect = option.rect.adjusted( OFFSET - 1, 0, - OFFSET, - OFFSET *2 ); + artpix = find_art_pixmap( url ); /* look in the QPixmapCache for art */ + QPainterPath artRectPath; artRectPath.addRoundedRect( artRect, ART_RADIUS, ART_RADIUS ); @@ -75,7 +98,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt // Draw the art pixmap painter->setClipPath( artRectPath ); - painter->drawPixmap( artRect, pix ); + painter->drawPixmap( artRect, artpix ); painter->setClipping( false ); QColor text = qApp->palette().text().color(); -- 2.39.2