19 #include <QApplication> 23 #include <QSvgRenderer> 26 #include <QMutexLocker> 32 #include "base/Debug.h" 33 #include "base/Profiler.h" 68 Profiler profiler(
"IconLoader::load");
71 static map<QString, QIcon> icons;
72 static const vector<int> sizes { 0, 16, 22, 24, 32, 48, 64, 128 };
74 QMutexLocker locker(&mutex);
76 if (icons.find(name) != icons.end()) {
77 return icons.at(name);
82 QPixmap pmap(loadPixmap(name, sz));
83 if (!pmap.isNull()) icon.addPixmap(pmap);
95 settings.beginGroup(
"IconLoader");
96 if (!settings.value(
"invert-icons-on-dark-background",
true).toBool()) {
99 QColor bg = QApplication::palette().window().color();
100 bool darkBackground = (bg.red() + bg.green() + bg.blue() <= 384);
101 return darkBackground;
107 if (shouldInvert()) {
117 bool invert = shouldInvert();
119 QString scalableName, nonScalableName;
123 nonScalableName = makeNonScalableFilename(name, size, invert);
124 pmap = QPixmap(nonScalableName);
126 if (pmap.isNull() && size > 0) {
129 scalableName = makeScalableFilename(name, invert);
130 pmap = loadScalable(scalableName, size);
133 if (pmap.isNull() && invert) {
137 nonScalableName = makeNonScalableFilename(name, size,
false);
138 pmap = QPixmap(nonScalableName);
140 if (pmap.isNull() && size > 0) {
141 scalableName = makeScalableFilename(name,
false);
142 pmap = loadScalable(scalableName, size);
145 if (!pmap.isNull() && shouldAutoInvert(name)) {
146 pmap = invertPixmap(pmap);
156 if (!QFile(name).exists()) {
160 QPixmap pmap(size, size);
161 pmap.fill(Qt::transparent);
162 QSvgRenderer renderer(name);
164 painter.begin(&pmap);
166 renderer.render(&painter);
177 return QString(
":icons/%1_inverse.png").arg(name);
179 return QString(
":icons/%1-%2_inverse.png").arg(name).arg(size);
183 return QString(
":icons/%1.png").arg(name);
185 return QString(
":icons/%1-%2.png").arg(name).arg(size);
194 return QString(
":icons/scalable/%1_inverse.svg").arg(name);
196 return QString(
":icons/scalable/%1.svg").arg(name);
206 QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32);
208 for (
int y = 0; y < img.height(); ++y) {
209 for (
int x = 0; x < img.width(); ++x) {
211 QRgb rgba = img.pixel(x, y);
212 QColor colour = QColor
213 (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));
215 int alpha = colour.alpha();
216 if (colour.saturation() < 5 && colour.alpha() > 10) {
217 colour.setHsv(colour.hue(),
219 255 - colour.value());
220 colour.setAlpha(alpha);
221 img.setPixel(x, y, colour.rgba());
226 pmap = QPixmap::fromImage(img);
static set< QString > autoInvertExceptions
QString makeNonScalableFilename(QString, int, bool)
QString makeScalableFilename(QString, bool)
QPixmap invertPixmap(QPixmap)
bool shouldInvert() const
QPixmap loadScalable(QString, int)
QPixmap loadPixmap(QString, int)
bool shouldAutoInvert(QString) const