From e346c751eccf023b668c6b653f9f72382f830250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Thu, 23 Jan 2014 04:05:45 +0100 Subject: [PATCH] Allow to reset devicePixelRatio Setting devicePixelRatio to 0 re-reads it and resets it to its default value. --- src/declarativeimports/core/units.cpp | 21 ++++++++++++--------- src/declarativeimports/core/units.h | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/declarativeimports/core/units.cpp b/src/declarativeimports/core/units.cpp index bc5ec0df5..d02835fa1 100644 --- a/src/declarativeimports/core/units.cpp +++ b/src/declarativeimports/core/units.cpp @@ -32,13 +32,10 @@ Units::Units (QObject *parent) : QObject(parent), - m_gridUnit(-1) + m_gridUnit(-1), + m_devicePixelRatio(-1) { - //Usual "default" is 96 dpi - //that magic ratio follows the definition of "device independent pixel" by Microsoft - m_dpi = QApplication::desktop()->physicalDpiX(); - m_devicePixelRatio = (qreal)m_dpi / (qreal)96; - + setDevicePixelRatio(0); updateSpacing(); m_iconSizes = new QQmlPropertyMap(this); @@ -80,15 +77,21 @@ QQmlPropertyMap *Units::iconSizes() const qreal Units::devicePixelRatio() const { - return m_devicePixelRatio; } void Units::setDevicePixelRatio(const qreal scale) { if (m_devicePixelRatio != scale) { - m_devicePixelRatio = scale; - qDebug() << "Setting dpi scale to " << scale; + if (scale <= 0) { + //Usual "default" is 96 dpi + //that magic ratio follows the definition of "device independent pixel" by Microsoft + m_dpi = QApplication::desktop()->physicalDpiX(); + m_devicePixelRatio = (qreal)m_dpi / (qreal)96; + } else { + m_devicePixelRatio = scale; + } + qDebug() << "Setting dpi scale to " << scale; emit devicePixelRatioChanged(); } } diff --git a/src/declarativeimports/core/units.h b/src/declarativeimports/core/units.h index dde38d843..7f6da5cc7 100644 --- a/src/declarativeimports/core/units.h +++ b/src/declarativeimports/core/units.h @@ -64,6 +64,9 @@ class Units : public QObject Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged) Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged) + /** + * The ratio between physical and device-independent pixels. + */ Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged) public: @@ -74,7 +77,19 @@ public: qreal gridUnit() const; - void setDevicePixelRatio(const qreal scale); + + /** + * Overrides the devicePixelRatio + * + * Set the device pixel ratio to a custom value. + * + * @arg ratio, 0 resets to detected value + */ + void setDevicePixelRatio(const qreal ratio); + + /** + * @return The ratio between physical and device-independent pixels. + */ qreal devicePixelRatio() const; QQmlPropertyMap *iconSizes() const;