[vlc-devel] commit: QT4 Icon view: cache album art pixmap ( Rafaël Carré )

git version control git at videolan.org
Thu Jan 28 16:18:21 CET 2010


vlc | branch: master | Rafaël Carré <rafael.carre at gmail.com> | Thu Jan 28 16:11:56 2010 +0100| [344416ec80558bfcb24cbcc0650fecbb19da830f] | committer: Rafaël Carré 

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=344416ec80558bfcb24cbcc0650fecbb19da830f
---

 modules/gui/qt4/components/playlist/icon_view.cpp |   39 ++++++++++++++++----
 1 files 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 dadd7d7..613f2e6 100644
--- a/modules/gui/qt4/components/playlist/icon_view.cpp
+++ b/modules/gui/qt4/components/playlist/icon_view.cpp
@@ -30,6 +30,7 @@
 #include <QRect>
 #include <QStyleOptionViewItem>
 #include <QFontMetrics>
+#include <QPixmapCache>
 
 #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<PLItem*>( 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();




More information about the vlc-devel mailing list