service/tray: use bilinear scaling for tray icons

Apparently some programs think it is a good idea to send 1000x+ images.
This commit is contained in:
outfoxxed 2024-04-21 00:16:22 -07:00
parent c6e5a35745
commit ce4e697667
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -6,6 +6,7 @@
#include <qicon.h> #include <qicon.h>
#include <qlogging.h> #include <qlogging.h>
#include <qloggingcategory.h> #include <qloggingcategory.h>
#include <qnamespace.h>
#include <qobject.h> #include <qobject.h>
#include <qpainter.h> #include <qpainter.h>
#include <qpixmap.h> #include <qpixmap.h>
@ -123,7 +124,13 @@ QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
pixmap = icon.pixmap(size.width(), size.height()); pixmap = icon.pixmap(size.width(), size.height());
} else { } else {
const auto* icon = closestPixmap(size, this->attentionIconPixmaps.get()); const auto* icon = closestPixmap(size, this->attentionIconPixmaps.get());
if (icon != nullptr) pixmap = QPixmap::fromImage(icon->createImage());
if (icon != nullptr) {
const auto image =
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixmap = QPixmap::fromImage(image);
}
} }
} else { } else {
if (!this->iconName.get().isEmpty()) { if (!this->iconName.get().isEmpty()) {
@ -131,7 +138,13 @@ QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
pixmap = icon.pixmap(size.width(), size.height()); pixmap = icon.pixmap(size.width(), size.height());
} else { } else {
const auto* icon = closestPixmap(size, this->iconPixmaps.get()); const auto* icon = closestPixmap(size, this->iconPixmaps.get());
if (icon != nullptr) pixmap = QPixmap::fromImage(icon->createImage());
if (icon != nullptr) {
const auto image =
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixmap = QPixmap::fromImage(image);
}
} }
QPixmap overlay; QPixmap overlay;
@ -140,7 +153,13 @@ QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
overlay = icon.pixmap(pixmap.width(), pixmap.height()); overlay = icon.pixmap(pixmap.width(), pixmap.height());
} else { } else {
const auto* icon = closestPixmap(pixmap.size(), this->overlayIconPixmaps.get()); const auto* icon = closestPixmap(pixmap.size(), this->overlayIconPixmaps.get());
if (icon != nullptr) overlay = QPixmap::fromImage(icon->createImage());
if (icon != nullptr) {
const auto image =
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
overlay = QPixmap::fromImage(image);
}
} }
if (!overlay.isNull()) { if (!overlay.isNull()) {