┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2023-11-20 14:16:18 +0100
committerKai Uwe Broulik <[email protected]>2023-11-21 13:53:54 +0100
commitecd3675aaa55b8224f1fa81b031471d834a18fad (patch)
tree11722acc75ab4f5c2a345b0b7880c24957d3ee2d /src/kitemviews/private
parent26adfe689a70af60933809c6106723ff5962b67e (diff)
views: Use scene devicePixelRatio rather than qApp
When possible, use the devicePixelRatio from the scene which on Wayland unlike the QApplication will properly support fractional scaling. A KItemViewsUtils class is introduced that can be reused elsewhere.
Diffstat (limited to 'src/kitemviews/private')
-rw-r--r--src/kitemviews/private/kitemviewsutils.cpp23
-rw-r--r--src/kitemviews/private/kitemviewsutils.h20
2 files changed, 43 insertions, 0 deletions
diff --git a/src/kitemviews/private/kitemviewsutils.cpp b/src/kitemviews/private/kitemviewsutils.cpp
new file mode 100644
index 000000000..9e343b6d0
--- /dev/null
+++ b/src/kitemviews/private/kitemviewsutils.cpp
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "kitemviewsutils.h"
+
+#include <QApplication>
+#include <QGraphicsItem>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+
+qreal KItemViewsUtils::devicePixelRatio(const QGraphicsItem *item)
+{
+ qreal dpr = qApp->devicePixelRatio();
+ if (item->scene()) {
+ if (const auto views = item->scene()->views(); !views.isEmpty()) {
+ dpr = views.first()->devicePixelRatioF();
+ }
+ }
+ return dpr;
+}
diff --git a/src/kitemviews/private/kitemviewsutils.h b/src/kitemviews/private/kitemviewsutils.h
new file mode 100644
index 000000000..e9c8bd3e8
--- /dev/null
+++ b/src/kitemviews/private/kitemviewsutils.h
@@ -0,0 +1,20 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef KITEMVIEWSUTILS_H
+#define KITEMVIEWSUTILS_H
+
+#include <qtypes.h>
+
+class QGraphicsItem;
+
+class KItemViewsUtils
+{
+public:
+ static qreal devicePixelRatio(const QGraphicsItem *item);
+};
+
+#endif // KITEMVIEWSUTILS_H