From cca9522e7ca0c040ae354b20f09983005ef955bd Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 25 Oct 2013 15:16:46 +0200 Subject: Screen attached property: expose pixelDensity property Because logicalPixelDensity is different than physical density on multiple platforms, having the actual density is critical to be able to design resolution-independent controls. Change-Id: I06bbdc6e6869718058a796ca737668ce69802f2b Reviewed-by: Jens Bache-Wiig --- src/quick/items/qquickscreen.cpp | 18 ++++++++++++++++++ src/quick/items/qquickscreen_p.h | 3 +++ 2 files changed, 21 insertions(+) (limited to 'src/quick/items') diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 75eccf6c59..e32f31308e 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -135,6 +135,13 @@ QT_BEGIN_NAMESPACE usual units in QML; on some systems they may be different than physical pixels. */ +/*! + \qmlattachedproperty real QtQuick.Window::Screen::pixelDensity + \readonly + \since 5.2 + + The number of physical pixels per millimeter. +*/ /*! \qmlattachedproperty Qt::ScreenOrientation QtQuick.Window::Screen::primaryOrientation \readonly @@ -233,6 +240,13 @@ qreal QQuickScreenAttached::logicalPixelDensity() const return m_screen->logicalDotsPerInch() / 25.4; } +qreal QQuickScreenAttached::pixelDensity() const +{ + if (!m_screen) + return 0.0; + return m_screen->physicalDotsPerInch() / 25.4; +} + Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const { if (!m_screen) @@ -291,6 +305,8 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) emit desktopGeometryChanged(); if (!oldScreen || screen->logicalDotsPerInch() != oldScreen->logicalDotsPerInch()) emit logicalPixelDensityChanged(); + if (!oldScreen || screen->physicalDotsPerInch() != oldScreen->physicalDotsPerInch()) + emit pixelDensityChanged(); connect(screen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(widthChanged())); @@ -304,6 +320,8 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) this, SIGNAL(desktopGeometryChanged())); connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)), this, SIGNAL(logicalPixelDensityChanged())); + connect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)), + this, SIGNAL(pixelDensityChanged())); } } diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 0f1e79b1a2..6f837eea14 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -64,6 +64,7 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject Q_PROPERTY(int desktopAvailableWidth READ desktopAvailableWidth NOTIFY desktopGeometryChanged REVISION 1) Q_PROPERTY(int desktopAvailableHeight READ desktopAvailableHeight NOTIFY desktopGeometryChanged REVISION 1) Q_PROPERTY(qreal logicalPixelDensity READ logicalPixelDensity NOTIFY logicalPixelDensityChanged REVISION 1) + Q_PROPERTY(qreal pixelDensity READ pixelDensity NOTIFY pixelDensityChanged) Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged) Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged) @@ -76,6 +77,7 @@ public: int desktopAvailableWidth() const; int desktopAvailableHeight() const; qreal logicalPixelDensity() const; + qreal pixelDensity() const; Qt::ScreenOrientation primaryOrientation() const; Qt::ScreenOrientation orientation() const; @@ -90,6 +92,7 @@ Q_SIGNALS: void heightChanged(); Q_REVISION(1) void desktopGeometryChanged(); Q_REVISION(1) void logicalPixelDensityChanged(); + Q_REVISION(2) void pixelDensityChanged(); void primaryOrientationChanged(); void orientationChanged(); -- cgit v1.2.3