diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 73074e827..c27c196a2 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -185,6 +185,25 @@ QPixmap Metadata::customIconPixmap(const Uuid& uuid) const return pixmap; } +QPixmap Metadata::customIconScaledPixmap(const Uuid& uuid) const +{ + QPixmap pixmap; + + if (!m_customIcons.contains(uuid)) { + return pixmap; + } + + QPixmapCache::Key& cacheKey = m_customIconScaledCacheKeys[uuid]; + + if (!QPixmapCache::find(cacheKey, &pixmap)) { + QImage image = m_customIcons.value(uuid).scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation); + pixmap = QPixmap::fromImage(image); + cacheKey = QPixmapCache::insert(pixmap); + } + + return pixmap; +} + bool Metadata::containsCustomIcon(const Uuid& uuid) const { return m_customIcons.contains(uuid); @@ -358,6 +377,7 @@ void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon) m_customIcons.insert(uuid, icon); // reset cache in case there is also an icon with that uuid m_customIconCacheKeys[uuid] = QPixmapCache::Key(); + m_customIconScaledCacheKeys[uuid] = QPixmapCache::Key(); m_customIconsOrder.append(uuid); Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count()); Q_EMIT modified(); @@ -387,6 +407,8 @@ void Metadata::removeCustomIcon(const Uuid& uuid) m_customIcons.remove(uuid); QPixmapCache::remove(m_customIconCacheKeys.value(uuid)); m_customIconCacheKeys.remove(uuid); + QPixmapCache::remove(m_customIconScaledCacheKeys.value(uuid)); + m_customIconScaledCacheKeys.remove(uuid); m_customIconsOrder.removeAll(uuid); Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count()); Q_EMIT modified(); diff --git a/src/core/Metadata.h b/src/core/Metadata.h index a15e3e0e7..b6e25c288 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -81,6 +81,7 @@ public: // bool autoEnableVisualHiding() const; QImage customIcon(const Uuid& uuid) const; QPixmap customIconPixmap(const Uuid& uuid) const; + QPixmap customIconScaledPixmap(const Uuid& uuid) const; bool containsCustomIcon(const Uuid& uuid) const; QHash customIcons() const; QList customIconsOrder() const; @@ -157,6 +158,7 @@ private: QHash m_customIcons; mutable QHash m_customIconCacheKeys; + mutable QHash m_customIconScaledCacheKeys; QList m_customIconsOrder; QPointer m_recycleBin;