@@ -105,6 +105,24 @@ void StatusNotifierButton::newAttentionIcon()
105
105
});
106
106
}
107
107
108
+ QImage StatusNotifierButton::convertToGrayScale (const QImage &srcImage) {
109
+ // Convert to 32bit pixel format
110
+ QImage dstImage = srcImage.convertToFormat (srcImage.hasAlphaChannel () ?
111
+ QImage::Format_ARGB32 : QImage::Format_RGB32);
112
+
113
+ unsigned int *data = (unsigned int *)dstImage.bits ();
114
+ int pixelCount = dstImage.width () * dstImage.height ();
115
+
116
+ // Convert each pixel to grayscale
117
+ for (int i = 0 ; i < pixelCount; ++i) {
118
+ int val = qGray (*data);
119
+ *data = qRgba (val, val, val, qAlpha (*data));
120
+ ++data;
121
+ }
122
+
123
+ return dstImage;
124
+ }
125
+
108
126
void StatusNotifierButton::refetchIcon (Status status, const QString& themePath)
109
127
{
110
128
QString nameProperty, pixmapProperty;
@@ -128,15 +146,19 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
128
146
QIcon nextIcon;
129
147
if (!iconName.isEmpty ())
130
148
{
131
- if (QIcon::hasThemeIcon (iconName))
132
- nextIcon = QIcon::fromTheme (iconName);
149
+ if (QIcon::hasThemeIcon (iconName)){
150
+ // nextIcon = QIcon::fromTheme(iconName);
151
+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale (QIcon::fromTheme (iconName).pixmap (16 , 16 ).toImage ())));
152
+
153
+ }
133
154
else
134
155
{
135
156
QDir themeDir (themePath);
136
157
if (themeDir.exists ())
137
158
{
138
159
if (themeDir.exists (iconName + QStringLiteral (" .png" )))
139
- nextIcon.addFile (themeDir.filePath (iconName + QStringLiteral (" .png" )));
160
+ // nextIcon.addFile(themeDir.filePath(iconName + QStringLiteral(".png")));
161
+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale (QImage (themeDir.filePath (iconName + QStringLiteral (" .png" ))))));
140
162
141
163
if (themeDir.cd (QStringLiteral (" hicolor" )) || (themeDir.cd (QStringLiteral (" icons" )) && themeDir.cd (QStringLiteral (" hicolor" ))))
142
164
{
@@ -148,7 +170,9 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
148
170
{
149
171
QString file = themeDir.absolutePath () + QLatin1Char (' /' ) + dir + QLatin1Char (' /' ) + innerDir + QLatin1Char (' /' ) + iconName + QStringLiteral (" .png" );
150
172
if (QFile::exists (file))
151
- nextIcon.addFile (file);
173
+ // nextIcon.addFile(file);
174
+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale (QImage (file))));
175
+
152
176
}
153
177
}
154
178
}
@@ -190,7 +214,7 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
190
214
for (const uchar *src = image.constBits (); src < end; src += 4 , dest += 4 )
191
215
qToUnaligned (qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);
192
216
193
- nextIcon.addPixmap (QPixmap::fromImage (image));
217
+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale ( image) ));
194
218
}
195
219
}
196
220
0 commit comments