diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-21 14:29:52 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-09 18:09:17 +0200 |
commit | 6c8adfaf5dc79b1e22c68bb9d1d07581d3ca0e34 (patch) | |
tree | 1189aceb8e1dad19c394cc3cca38dd696c27b579 /src/platformsupport | |
parent | fc4a8d18d772792db2e7b1c1b592c62cb638572b (diff) | |
download | qtbase-6c8adfaf5dc79b1e22c68bb9d1d07581d3ca0e34.tar.gz |
Avoid double pixel-ratio scaling of dbus tray icons
QIcon::pixmap does automatic scaling to DPR by default, so
use QIconEngine API to access internal pixmaps directly instead.
Task-number: QTBUG-83806
Change-Id: I3ccbed8387811a87bbea3f5d4ad9963e1be28a49
Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit e5e89d17b36a808192aa5b0c949a4ac1fc4a08ea)
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r-- | src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp | 3 | ||||
-rw-r--r-- | src/platformsupport/themes/genericunix/dbustray/qdbustraytypes.cpp | 22 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp index ca740f967e..bede70975a 100644 --- a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp +++ b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp @@ -213,10 +213,9 @@ QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon) } if (!necessary) return nullptr; - qreal dpr = qGuiApp->devicePixelRatio(); QTemporaryFile *ret = new QTemporaryFile(tempFileTemplate(), this); ret->open(); - icon.pixmap(QSize(22 * dpr, 22 * dpr)).save(ret); + icon.pixmap(QSize(22, 22)).save(ret); ret->close(); return ret; } diff --git a/src/platformsupport/themes/genericunix/dbustray/qdbustraytypes.cpp b/src/platformsupport/themes/genericunix/dbustray/qdbustraytypes.cpp index fc49fcbea9..5edde31119 100644 --- a/src/platformsupport/themes/genericunix/dbustray/qdbustraytypes.cpp +++ b/src/platformsupport/themes/genericunix/dbustray/qdbustraytypes.cpp @@ -46,6 +46,7 @@ #include <QDBusMetaType> #include <QImage> #include <QIcon> +#include <QIconEngine> #include <QImage> #include <QPixmap> #include <QDebug> @@ -53,7 +54,8 @@ #include <QPainter> #include <QGuiApplication> #include <qpa/qplatformmenu.h> -#include "qdbusplatformmenu_p.h" +#include <private/qdbusplatformmenu_p.h> +#include <private/qicon_p.h> QT_BEGIN_NAMESPACE @@ -64,35 +66,37 @@ static const int IconNormalMediumSize = 64; QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon) { QXdgDBusImageVector ret; - QList<QSize> sizes = icon.availableSizes(); + if (icon.isNull()) + return ret; + QIconEngine *engine = const_cast<QIcon &>(icon).data_ptr()->engine; + QList<QSize> sizes = engine->availableSizes(QIcon::Normal, QIcon::Off); // Omit any size larger than 64 px, to save D-Bus bandwidth; // ensure that 22px or smaller exists, because it's a common size; // and ensure that something between 22px and 64px exists, for better scaling to other sizes. bool hasSmallIcon = false; bool hasMediumIcon = false; - qreal dpr = qGuiApp->devicePixelRatio(); QList<QSize> toRemove; Q_FOREACH (const QSize &size, sizes) { int maxSize = qMax(size.width(), size.height()); - if (maxSize <= IconNormalSmallSize * dpr) + if (maxSize <= IconNormalSmallSize) hasSmallIcon = true; - else if (maxSize <= IconNormalMediumSize * dpr) + else if (maxSize <= IconNormalMediumSize) hasMediumIcon = true; - else if (maxSize > IconSizeLimit * dpr) + else if (maxSize > IconSizeLimit) toRemove << size; } Q_FOREACH (const QSize &size, toRemove) sizes.removeOne(size); if (!hasSmallIcon) - sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr)); + sizes.append(QSize(IconNormalSmallSize, IconNormalSmallSize)); if (!hasMediumIcon) - sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr)); + sizes.append(QSize(IconNormalMediumSize, IconNormalMediumSize)); ret.reserve(sizes.size()); foreach (QSize size, sizes) { // Protocol specifies ARGB32 format in network byte order - QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32); + QImage im = engine->pixmap(size, QIcon::Normal, QIcon::Off).toImage().convertToFormat(QImage::Format_ARGB32); // letterbox if necessary to make it square if (im.height() != im.width()) { int maxSize = qMax(im.width(), im.height()); |