diff options
author | Shawn Rutledge <[email protected]> | 2013-10-25 15:16:46 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-10-26 01:52:10 +0200 |
commit | cca9522e7ca0c040ae354b20f09983005ef955bd (patch) | |
tree | c3b728631f0d167c4c57041cb19b7d90df40a0d1 /src | |
parent | b3bff5bb3c8ee0e1c45d20d04b1c3c0236aa9d38 (diff) |
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 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickscreen.cpp | 18 | ||||
-rw-r--r-- | src/quick/items/qquickscreen_p.h | 3 |
2 files changed, 21 insertions, 0 deletions
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 @@ -136,6 +136,13 @@ QT_BEGIN_NAMESPACE 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(); |