summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-07-31 10:23:39 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-08-01 13:20:23 +0200
commit174061f9f32ac76c6b8a6d155d772e37708d8cfc (patch)
tree44845c0ef7b52dee6e524ce86fa3554ed560ece6
parent3d7bd7ad19254bb1c4794349e71501e58c91891e (diff)
QHighDPI: Fix broken scaling of QPoint(F)
For some reason, the overload resolution of the High DPI scale() functions introduced by b6ded193ee64ffe67df6d22e7a23aa1ea9e02ec7 chose the wrong overloads for QPointF and/or QPoint; it fell back to the generic template intended for qreal, QSize, etc, ignoring the origin. Remove the template and spell out all overloads. Fixes: QTBUG-77255 Change-Id: I5661f16f7326f65156f646f430f5a0c71d5302d2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h20
-rw-r--r--tests/auto/gui/kernel/kernel.pro3
-rw-r--r--tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro6
-rw-r--r--tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp77
4 files changed, 103 insertions, 3 deletions
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index 3410c1d345..c43641b8c9 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -59,6 +59,7 @@
#include <QtCore/qloggingcategory.h>
#include <QtGui/qregion.h>
#include <QtGui/qscreen.h>
+#include <QtGui/qvector2d.h>
#include <QtGui/qwindow.h>
QT_BEGIN_NAMESPACE
@@ -117,13 +118,26 @@ private:
namespace QHighDpi {
-template <typename T>
-inline T scale(const T &value, qreal scaleFactor, QPoint origin = QPoint(0, 0))
+inline qreal scale(qreal value, qreal scaleFactor, QPointF /* origin */ = QPointF(0, 0))
{
- Q_UNUSED(origin)
return value * scaleFactor;
}
+inline QSize scale(const QSize &value, qreal scaleFactor, QPointF /* origin */ = QPointF(0, 0))
+{
+ return value * scaleFactor;
+}
+
+inline QSizeF scale(const QSizeF &value, qreal scaleFactor, QPointF /* origin */ = QPointF(0, 0))
+{
+ return value * scaleFactor;
+}
+
+inline QVector2D scale(const QVector2D &value, qreal scaleFactor, QPointF /* origin */ = QPointF(0, 0))
+{
+ return value * float(scaleFactor);
+}
+
inline QPointF scale(const QPointF &pos, qreal scaleFactor, QPointF origin = QPointF(0, 0))
{
return (pos - origin) * scaleFactor + origin;
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
index fbd3b1b371..42135dae24 100644
--- a/tests/auto/gui/kernel/kernel.pro
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -11,6 +11,7 @@ SUBDIRS=\
qguimetatype \
qguitimer \
qguivariant \
+ qhighdpiscaling \
qinputmethod \
qkeyevent \
qkeysequence \
@@ -35,6 +36,8 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop
!qtHaveModule(network): SUBDIRS -= \
qguieventloop
+!qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling
+
!qtConfig(opengl): SUBDIRS -= qopenglwindow
android|uikit: SUBDIRS -= qclipboard
diff --git a/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro b/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro
new file mode 100644
index 0000000000..6cd7bb01f5
--- /dev/null
+++ b/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro
@@ -0,0 +1,6 @@
+CONFIG += testcase
+TARGET = tst_qhighdpiscaling
+
+QT += core-private gui-private testlib
+
+SOURCES += tst_qhighdpiscaling.cpp
diff --git a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp
new file mode 100644
index 0000000000..969b2351ec
--- /dev/null
+++ b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <private/qhighdpiscaling_p.h>
+#include <qpa/qplatformscreen.h>
+
+#include <QtTest/QtTest>
+
+class tst_QHighDpiScaling: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void scale();
+};
+
+// Emulate the case of a High DPI secondary screen
+class MyPlatformScreen : public QPlatformScreen
+{
+public:
+ QRect geometry() const override { return QRect(3840, 0, 3840, 1920); }
+ QRect availableGeometry() const override { return geometry(); }
+
+ int depth() const override { return 32; }
+ QImage::Format format() const override { return QImage::Format_ARGB32_Premultiplied; }
+};
+
+// QTBUG-77255: Test some scaling overloads
+void tst_QHighDpiScaling::scale()
+{
+ QHighDpiScaling::setGlobalFactor(2);
+ QScopedPointer<QPlatformScreen> screen(new MyPlatformScreen);
+
+ qreal nativeValue = 10;
+ const qreal value = QHighDpi::fromNativePixels(nativeValue, screen.data());
+ QCOMPARE(value, qreal(5));
+ QCOMPARE(QHighDpi::toNativePixels(value, screen.data()), nativeValue);
+
+ // 10, 10 within screen should translate to 5,5 with origin preserved
+ const QPoint nativePoint = screen->geometry().topLeft() + QPoint(10, 10);
+ const QPoint point = QHighDpi::fromNativePixels(nativePoint, screen.data());
+ QCOMPARE(point, QPoint(3845, 5));
+ QCOMPARE(QHighDpi::toNativePixels(point, screen.data()), nativePoint);
+
+ const QPointF nativePointF(nativePoint);
+ const QPointF pointF = QHighDpi::fromNativePixels(nativePointF, screen.data());
+ QCOMPARE(pointF, QPointF(3845, 5));
+ QCOMPARE(QHighDpi::toNativePixels(pointF, screen.data()), nativePointF);
+}
+
+#include "tst_qhighdpiscaling.moc"
+QTEST_MAIN(tst_QHighDpiScaling);