From 315145ac95f45af32b86c16ef15cb7c0f08a5304 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 4 Feb 2015 10:58:06 +0100 Subject: D-Bus tray icons: get devicePixelRatio at runtime In static builds of Qt, static initialization may not work because we need an initialized list of screens before devicePixelRatio() can use them to find the value. Anyway, it's better to know the dpr at the time the tray icon will be shown rather than when the application is started, just in case it changes. Change-Id: Iedffb674d8e8818c2a4e64d7c7a3c89a2dca77f3 Reviewed-by: Laszlo Agocs --- src/platformsupport/dbustray/qdbustraytypes.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/platformsupport/dbustray/qdbustraytypes.cpp b/src/platformsupport/dbustray/qdbustraytypes.cpp index b954ffe412..9e9002ba70 100644 --- a/src/platformsupport/dbustray/qdbustraytypes.cpp +++ b/src/platformsupport/dbustray/qdbustraytypes.cpp @@ -51,9 +51,9 @@ QT_BEGIN_NAMESPACE -static const int IconSizeLimit = 64 * qGuiApp->devicePixelRatio(); -static const int IconNormalSmallSize = 22 * qGuiApp->devicePixelRatio(); -static const int IconNormalMediumSize = 64 * qGuiApp->devicePixelRatio(); +static const int IconSizeLimit = 64; +static const int IconNormalSmallSize = 22; +static const int IconNormalMediumSize = 64; QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon) { @@ -65,22 +65,23 @@ QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon) // 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 toRemove; Q_FOREACH (const QSize &size, sizes) { int maxSize = qMax(size.width(), size.height()); - if (maxSize <= IconNormalSmallSize) + if (maxSize <= IconNormalSmallSize * dpr) hasSmallIcon = true; - else if (maxSize <= IconNormalMediumSize) + else if (maxSize <= IconNormalMediumSize * dpr) hasMediumIcon = true; - else if (maxSize > IconSizeLimit) + else if (maxSize > IconSizeLimit * dpr) toRemove << size; } Q_FOREACH (const QSize &size, toRemove) sizes.removeOne(size); if (!hasSmallIcon) - sizes.append(QSize(IconNormalSmallSize, IconNormalSmallSize)); + sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr)); if (!hasMediumIcon) - sizes.append(QSize(IconNormalMediumSize, IconNormalMediumSize)); + sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr)); foreach (QSize size, sizes) { // Protocol specifies ARGB32 format in network byte order QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32); -- cgit v1.2.3