diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-10-17 14:24:07 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-10-23 09:03:16 +0200 |
commit | e2764c722571025835e41632637d1421ba44fb02 (patch) | |
tree | fcbe4624419e0332ba0330aa6402123c39f03523 | |
parent | a1b43cb272ff05bd8c681d4d6320dcfee7339d84 (diff) |
Screen attached property: expose devicePixelRatio property
Change-Id: I08b22766b3e389b7d27ca4c56729f550b0647a08
Reviewed-by: Jens Bache-Wiig <jensbw@gmail.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
-rw-r--r-- | examples/quick/window/ScreenInfo.qml | 5 | ||||
-rw-r--r-- | src/quick/items/qquickscreen.cpp | 18 | ||||
-rw-r--r-- | src/quick/items/qquickscreen_p.h | 3 | ||||
-rw-r--r-- | tests/auto/quick/qquickscreen/data/screen.qml | 1 | ||||
-rw-r--r-- | tests/auto/quick/qquickscreen/tst_qquickscreen.cpp | 2 |
5 files changed, 28 insertions, 1 deletions
diff --git a/examples/quick/window/ScreenInfo.qml b/examples/quick/window/ScreenInfo.qml index 73700720d8..d0a233f759 100644 --- a/examples/quick/window/ScreenInfo.qml +++ b/examples/quick/window/ScreenInfo.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -import QtQuick 2.1 +import QtQuick 2.3 import QtQuick.Window 2.1 Item { @@ -85,6 +85,9 @@ Item { Text { text: "logical pixel density" } Text { text: Screen.logicalPixelDensity.toFixed(2) + " dots/mm (" + (Screen.logicalPixelDensity * 25.4).toFixed(2) + " dots/inch)" } + Text { text: "device pixel ratio" } + Text { text: Screen.devicePixelRatio.toFixed(2) } + Text { text: "available virtual desktop" } Text { text: Screen.desktopAvailableWidth + "x" + Screen.desktopAvailableHeight } diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 926ac7b4ee..8ac5a1e292 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -142,6 +142,15 @@ QT_BEGIN_NAMESPACE The number of physical pixels per millimeter. */ /*! + \qmlattachedproperty real Screen::devicePixelRatio + \readonly + \since 5.4 + + The ratio between physical pixels and device-independent pixels for the screen. + + Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays. +*/ +/*! \qmlattachedproperty Qt::ScreenOrientation Screen::primaryOrientation \readonly @@ -260,6 +269,13 @@ qreal QQuickScreenAttached::pixelDensity() const return m_screen->physicalDotsPerInch() / 25.4; } +qreal QQuickScreenAttached::devicePixelRatio() const +{ + if (!m_screen) + return 1.0; + return m_screen->devicePixelRatio(); +} + Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const { if (!m_screen) @@ -340,6 +356,8 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) emit logicalPixelDensityChanged(); if (!oldScreen || screen->physicalDotsPerInch() != oldScreen->physicalDotsPerInch()) emit pixelDensityChanged(); + if (!oldScreen || screen->devicePixelRatio() != oldScreen->devicePixelRatio()) + emit devicePixelRatioChanged(); connect(screen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(widthChanged())); diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index d661cc6f56..257b18cfe0 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -57,6 +57,7 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject Q_PROPERTY(int desktopAvailableHeight READ desktopAvailableHeight NOTIFY desktopGeometryChanged) Q_PROPERTY(qreal logicalPixelDensity READ logicalPixelDensity NOTIFY logicalPixelDensityChanged) Q_PROPERTY(qreal pixelDensity READ pixelDensity NOTIFY pixelDensityChanged) + Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged) // TODO Qt 6 Rename primaryOrientation to orientation Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged) // TODO Qt 6 Remove this orientation -> incomplete device orientation -> better use OrientationSensor @@ -74,6 +75,7 @@ public: int desktopAvailableHeight() const; qreal logicalPixelDensity() const; qreal pixelDensity() const; + qreal devicePixelRatio() const; Qt::ScreenOrientation primaryOrientation() const; Qt::ScreenOrientation orientation() const; Qt::ScreenOrientations orientationUpdateMask() const; @@ -91,6 +93,7 @@ Q_SIGNALS: void desktopGeometryChanged(); void logicalPixelDensityChanged(); void pixelDensityChanged(); + void devicePixelRatioChanged(); void primaryOrientationChanged(); void orientationChanged(); void orientationUpdateMaskChanged(); diff --git a/tests/auto/quick/qquickscreen/data/screen.qml b/tests/auto/quick/qquickscreen/data/screen.qml index dc3803f4e3..c246b3cd83 100644 --- a/tests/auto/quick/qquickscreen/data/screen.qml +++ b/tests/auto/quick/qquickscreen/data/screen.qml @@ -9,6 +9,7 @@ Item { property int curOrientation: Window.Screen.orientation property int priOrientation: Window.Screen.primaryOrientation property int updateMask: Window.Screen.orientationUpdateMask + property real devicePixelRatio: Window.Screen.devicePixelRatio Window.Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation } diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp index be543e8022..70ecff51eb 100644 --- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp @@ -63,6 +63,8 @@ void tst_qquickscreen::basicProperties() QCOMPARE(int(screen->orientation()), root->property("curOrientation").toInt()); QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation").toInt()); QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt()); + QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal()); + QVERIFY(screen->devicePixelRatio() >= 1.0); } QTEST_MAIN(tst_qquickscreen) |