summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/dbustray
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2015-02-04 10:58:06 +0100
committerShawn Rutledge <shawn.rutledge@digia.com>2015-02-04 14:41:36 +0000
commit315145ac95f45af32b86c16ef15cb7c0f08a5304 (patch)
tree2b815a9486bbc84b2f402c191713f77140dcc418 /src/platformsupport/dbustray
parent1f4b84f69f13edd10300d035321623291c5d073e (diff)
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 <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/platformsupport/dbustray')
-rw-r--r--src/platformsupport/dbustray/qdbustraytypes.cpp17
1 files changed, 9 insertions, 8 deletions
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<QSize> 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);