From 7c778029cf705e2cf3717e4b1160de52116ded5c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 13 Aug 2014 07:29:56 +0200 Subject: [PATCH] * Include tint color in ImageRegistry cache-key. --- src/libtomahawk/utils/ImageRegistry.cpp | 18 +++++++++++++----- src/libtomahawk/utils/ImageRegistry.h | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/utils/ImageRegistry.cpp b/src/libtomahawk/utils/ImageRegistry.cpp index 5b36dfa6f..ad8b88cf7 100644 --- a/src/libtomahawk/utils/ImageRegistry.cpp +++ b/src/libtomahawk/utils/ImageRegistry.cpp @@ -47,6 +47,13 @@ ImageRegistry::icon( const QString& image, TomahawkUtils::ImageMode mode ) } +qint64 +ImageRegistry::cacheKey( const QSize& size, float opacity, QColor tint ) +{ + return size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) + tint.value(); +} + + QPixmap ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, QColor tint ) { @@ -61,9 +68,10 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I { subsubcache = subcache.value( mode ); - if ( subsubcache.contains( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) ) ) + const qint64 ck = cacheKey( size, opacity, tint ); + if ( subsubcache.contains( ck ) ) { - return subsubcache.value( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) ); + return subsubcache.value( ck ); } } } @@ -114,7 +122,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I if ( !size.isNull() && pixmap.size() != size ) pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); - putInCache( image, size, mode, opacity, pixmap ); + putInCache( image, size, mode, opacity, pixmap, tint ); } return pixmap; @@ -122,7 +130,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I void -ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap ) +ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode; @@ -144,7 +152,7 @@ ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtil } } - subsubcache.insert( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ), pixmap ); + subsubcache.insert( cacheKey( size, opacity, tint ), pixmap ); subcache.insert( mode, subsubcache ); s_cache.insert( image, subcache ); } diff --git a/src/libtomahawk/utils/ImageRegistry.h b/src/libtomahawk/utils/ImageRegistry.h index 85ac8e216..880fa546a 100644 --- a/src/libtomahawk/utils/ImageRegistry.h +++ b/src/libtomahawk/utils/ImageRegistry.h @@ -34,7 +34,8 @@ public: QPixmap pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode = TomahawkUtils::Original, float opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) ); private: - void putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap ); + qint64 cacheKey( const QSize& size, float opacity, QColor tint ); + void putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint ); static ImageRegistry* s_instance; };