]> git.sesse.net Git - vlc/commitdiff
QT4 Icon view: cache album art pixmap
authorRafaël Carré <rafael.carre@gmail.com>
Thu, 28 Jan 2010 15:11:56 +0000 (16:11 +0100)
committerRafaël Carré <rafael.carre@gmail.com>
Thu, 28 Jan 2010 15:18:13 +0000 (16:18 +0100)
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

modules/gui/qt4/components/playlist/icon_view.cpp

index dadd7d777cec0bbf7518935437213cc069b54093..613f2e6c844289a073b0c43c604a4eec2177d5d3 100644 (file)
@@ -30,6 +30,7 @@
 #include <QRect>
 #include <QStyleOptionViewItem>
 #include <QFontMetrics>
+#include <QPixmapCache>
 
 #include "assert.h"
 
 #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();