Changeset View
Changeset View
Standalone View
Standalone View
libs/widgetutils/kis_icon_utils.cpp
Show All 27 Lines | |||||
28 | #include <QDebug> | 28 | #include <QDebug> | ||
29 | 29 | | |||
30 | #include <KoIcon.h> | 30 | #include <KoIcon.h> | ||
31 | 31 | | |||
32 | 32 | | |||
33 | namespace KisIconUtils | 33 | namespace KisIconUtils | ||
34 | { | 34 | { | ||
35 | 35 | | |||
36 | static QMap<QString, QIcon> s_cache; | ||||
36 | static QMap<qint64, QString> s_icons; | 37 | static QMap<qint64, QString> s_icons; | ||
37 | 38 | | |||
38 | QIcon loadIcon(const QString &name) | 39 | QIcon loadIcon(const QString &name) | ||
39 | { | 40 | { | ||
41 | QMap<QString, QIcon>::const_iterator cached = s_cache.constFind(name); | ||||
42 | if (cached != s_cache.constEnd()) { | ||||
43 | return cached.value(); | ||||
44 | } | ||||
40 | 45 | | |||
41 | // try load themed icon | 46 | // try load themed icon | ||
42 | 47 | | |||
43 | 48 | | |||
44 | const char * const prefix = useDarkIcons() ? "dark_" : "light_"; | 49 | const char * const prefix = useDarkIcons() ? "dark_" : "light_"; | ||
45 | 50 | | |||
46 | QString realName = QLatin1String(prefix) + name; | 51 | QString realName = QLatin1String(prefix) + name; | ||
47 | 52 | | |||
Show All 11 Lines | 54 | const QStringList names = { ":/pics/" + realName + ".png", | |||
59 | ":/" + name + ".png", | 64 | ":/" + name + ".png", | ||
60 | ":/" + name + ".svg", | 65 | ":/" + name + ".svg", | ||
61 | ":/" + name + ".svgz"}; | 66 | ":/" + name + ".svgz"}; | ||
62 | 67 | | |||
63 | for (const QString &resname : names) { | 68 | for (const QString &resname : names) { | ||
64 | if (QFile(resname).exists()) { | 69 | if (QFile(resname).exists()) { | ||
65 | QIcon icon(resname); | 70 | QIcon icon(resname); | ||
66 | s_icons.insert(icon.cacheKey(), name); | 71 | s_icons.insert(icon.cacheKey(), name); | ||
72 | s_cache.insert(name, icon); | ||||
67 | return icon; | 73 | return icon; | ||
68 | } | 74 | } | ||
69 | } | 75 | } | ||
70 | 76 | | |||
71 | // Now check for icons with sizes | 77 | // Now check for icons with sizes | ||
72 | QStringList sizes = QStringList() << "16_" << "22_" << "32_" << "48_" << "64_" << "128_" << "256_" << "512_" << "1048_"; | 78 | QStringList sizes = QStringList() << "16_" << "22_" << "32_" << "48_" << "64_" << "128_" << "256_" << "512_" << "1048_"; | ||
73 | QVector<QPair<QString, QString> > icons; | 79 | QVector<QPair<QString, QString> > icons; | ||
74 | Q_FOREACH (const QString &size, sizes) { | 80 | Q_FOREACH (const QString &size, sizes) { | ||
Show All 22 Lines | 102 | if (!icons.isEmpty()) { | |||
97 | QIcon icon; | 103 | QIcon icon; | ||
98 | Q_FOREACH (auto p, icons) { | 104 | Q_FOREACH (auto p, icons) { | ||
99 | QString sz = p.first; | 105 | QString sz = p.first; | ||
100 | sz.chop(1); | 106 | sz.chop(1); | ||
101 | int size = sz.toInt(); | 107 | int size = sz.toInt(); | ||
102 | icon.addFile(p.second, QSize(size, size)); | 108 | icon.addFile(p.second, QSize(size, size)); | ||
103 | } | 109 | } | ||
104 | s_icons.insert(icon.cacheKey(), name); | 110 | s_icons.insert(icon.cacheKey(), name); | ||
111 | s_cache.insert(name, icon); | ||||
105 | return icon; | 112 | return icon; | ||
106 | } | 113 | } | ||
107 | 114 | | |||
108 | QIcon icon = QIcon::fromTheme(name); | 115 | QIcon icon = QIcon::fromTheme(name); | ||
109 | qWarning() << "\tfalling back on QIcon::FromTheme:" << name; | 116 | qWarning() << "\tfalling back on QIcon::FromTheme:" << name; | ||
117 | s_icons.insert(icon.cacheKey(), name); | ||||
118 | s_cache.insert(name, icon); | ||||
110 | return icon; | 119 | return icon; | ||
111 | } | 120 | } | ||
112 | 121 | | |||
113 | bool useDarkIcons() { | 122 | bool useDarkIcons() { | ||
114 | QColor background = qApp->palette().background().color(); | 123 | QColor background = qApp->palette().background().color(); | ||
115 | return background.value() > 100; | 124 | return background.value() > 100; | ||
116 | } | 125 | } | ||
117 | 126 | | |||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |