diff --git a/src/utils/viconutils.cpp b/src/utils/viconutils.cpp index aeb8dfc9..081d6556 100644 --- a/src/utils/viconutils.cpp +++ b/src/utils/viconutils.cpp @@ -1,6 +1,5 @@ #include "viconutils.h" -#include #include #include #include @@ -8,13 +7,20 @@ #include "vutils.h" +QHash VIconUtils::m_cache; + VIconUtils::VIconUtils() { - } QIcon VIconUtils::icon(const QString &p_file, const QString &p_fg, bool p_addDisabled) { + const QString key = cacheKey(p_file, p_fg, p_addDisabled); + auto it = m_cache.find(key); + if (it != m_cache.end()) { + return it.value(); + } + QFileInfo fi(p_file); bool isSvg = fi.suffix().toLower() == "svg"; if (p_fg.isEmpty() || !isSvg) { @@ -48,5 +54,8 @@ QIcon VIconUtils::icon(const QString &p_file, const QString &p_fg, bool p_addDis icon.addPixmap(disabledPixmap, QIcon::Disabled); } + // Add to cache. + m_cache.insert(key, icon); + return icon; } diff --git a/src/utils/viconutils.h b/src/utils/viconutils.h index e1b0b10a..4e0d0b73 100644 --- a/src/utils/viconutils.h +++ b/src/utils/viconutils.h @@ -3,12 +3,12 @@ #include #include +#include #include "vpalette.h" extern VPalette *g_palette; - class VIconUtils { public: @@ -94,6 +94,14 @@ public: private: VIconUtils(); + + static QString cacheKey(const QString &p_file, const QString &p_fg, bool p_addDisabled) + { + return p_file + "_" + p_fg + "_" + (p_addDisabled ? "1" : "0"); + } + + // file_fg_addDisabled as key. + static QHash m_cache; }; #endif // VICONUTILS_H