diff --git a/kcms/icons/main.h b/kcms/icons/main.h --- a/kcms/icons/main.h +++ b/kcms/icons/main.h @@ -72,7 +72,7 @@ Q_INVOKABLE void setIconSize(int group, int size); Q_INVOKABLE QList availableIconSizes(int group) const; - Q_INVOKABLE QVariantList/*QList*/ previewIcons(const QString &themeName, int size, qreal dpr) const; + Q_INVOKABLE QVariantList/*QList*/ previewIcons(const QString &themeName, int size, qreal dpr); signals: void iconSizesChanged(); @@ -106,6 +106,9 @@ QStringList m_iconGroups; + // ListView deletes and recreates delegates as you scroll, so once we generated previews, cache them + QHash*/> m_previewCache; + QScopedPointer m_tempInstallFile; QPointer m_newStuffDialog; diff --git a/kcms/icons/main.cpp b/kcms/icons/main.cpp --- a/kcms/icons/main.cpp +++ b/kcms/icons/main.cpp @@ -284,6 +284,7 @@ // reload the display icontheme items KIconLoader::global()->newIconLoader(); m_model->load(); + m_previewCache.clear(); }); } @@ -340,6 +341,7 @@ KIconLoader::global()->newIconLoader(); m_model->load(); + m_previewCache.clear(); } void IconModule::exportToKDE4() @@ -477,8 +479,15 @@ return everythingOk; } -QVariantList IconModule::previewIcons(const QString &themeName, int size, qreal dpr) const +QVariantList IconModule::previewIcons(const QString &themeName, int size, qreal dpr) { + const QString cacheKey = themeName + QLatin1Char('@') + QString::number(size) + QLatin1Char('@') + QString::number(dpr,'f',1); + + auto it = m_previewCache.constFind(cacheKey); + if (it != m_previewCache.constEnd()) { + return *it; + } + KIconTheme theme(themeName); QSvgRenderer renderer; @@ -553,6 +562,8 @@ return pixmapVariant.value().isNull(); }), pixmaps.end()); + m_previewCache.insert(cacheKey, pixmaps); + return pixmaps; }