summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qhighdpiscaling_p.h
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2020-05-27 10:57:08 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2020-10-20 07:26:24 +0200
commit95bce5b185ddc736405a952b9132e5c8f51275aa (patch)
tree0f3c542dade9d5dbfa7aaec86591159d55221c41 /src/gui/kernel/qhighdpiscaling_p.h
parent73a93981ca6bd641f2c75faf3cdce1fa0711fbb5 (diff)
QHighDpi: window geometry scaling functions
Add functions which scales window geometry: framNativeWindowGeometry() toNativeWindowGeometry() These correctly handles top-level and child windows, where top-level window positions scale around the screen origin while child window positions scale around (0, 0). Modify call cites to use the new functions. We no longer need the isTopLevel checks at the call site. Change-Id: I0158672d46a3f52dfc7d37d021fc5cebd7859200 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui/kernel/qhighdpiscaling_p.h')
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index c0aac7e646..f7cf4792f2 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -279,6 +279,22 @@ T toNativeGlobalPosition(const T &value, const C *context)
return scale(value, so.factor, so.origin);
}
+template <typename T, typename C>
+T fromNativeWindowGeometry(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context);
+ QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0);
+ return scale(value, qreal(1) / so.factor, effectiveOrigin);
+}
+
+template <typename T, typename C>
+T toNativeWindowGeometry(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context);
+ QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0);
+ return scale(value, so.factor, effectiveOrigin);
+}
+
template <typename T>
inline T fromNative(const T &value, qreal scaleFactor, QPoint origin = QPoint(0, 0))
{