@@ -105,6 +105,24 @@ void StatusNotifierButton::newAttentionIcon()
105105 });
106106}
107107
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+
108126void StatusNotifierButton::refetchIcon (Status status, const QString& themePath)
109127{
110128 QString nameProperty, pixmapProperty;
@@ -128,15 +146,19 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
128146 QIcon nextIcon;
129147 if (!iconName.isEmpty ())
130148 {
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+ }
133154 else
134155 {
135156 QDir themeDir (themePath);
136157 if (themeDir.exists ())
137158 {
138159 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" ))))));
140162
141163 if (themeDir.cd (QStringLiteral (" hicolor" )) || (themeDir.cd (QStringLiteral (" icons" )) && themeDir.cd (QStringLiteral (" hicolor" ))))
142164 {
@@ -148,7 +170,9 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
148170 {
149171 QString file = themeDir.absolutePath () + QLatin1Char (' /' ) + dir + QLatin1Char (' /' ) + innerDir + QLatin1Char (' /' ) + iconName + QStringLiteral (" .png" );
150172 if (QFile::exists (file))
151- nextIcon.addFile (file);
173+ // nextIcon.addFile(file);
174+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale (QImage (file))));
175+
152176 }
153177 }
154178 }
@@ -190,7 +214,7 @@ void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
190214 for (const uchar *src = image.constBits (); src < end; src += 4 , dest += 4 )
191215 qToUnaligned (qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);
192216
193- nextIcon.addPixmap (QPixmap::fromImage (image));
217+ nextIcon.addPixmap (QPixmap::fromImage (convertToGrayScale ( image) ));
194218 }
195219 }
196220
0 commit comments