From 6008c889f5699627edbabea126a30efef5abd795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=C4=8Cuki=C4=87?= Date: Thu, 6 Mar 2014 20:16:16 +0100 Subject: [PATCH] Added the units.displayAspectRatio property --- src/declarativeimports/core/units.cpp | 15 +++++++++++++++ src/declarativeimports/core/units.h | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/declarativeimports/core/units.cpp b/src/declarativeimports/core/units.cpp index 138742f2c..4205ef2a7 100644 --- a/src/declarativeimports/core/units.cpp +++ b/src/declarativeimports/core/units.cpp @@ -46,6 +46,7 @@ Units::Units (QObject *parent) { m_iconSizes = new QQmlPropertyMap(this); updateDevicePixelRatio(); + updateDisplayAspectRatio(); updateSpacing(); //iconLoaderSettingsChanged(); @@ -142,11 +143,25 @@ int Units::devicePixelIconSize(const int size) const return out; } +qreal Units::displayAspectRatio() const +{ + return m_displayAspectRatio; +} + qreal Units::devicePixelRatio() const { return m_devicePixelRatio; } +void Units::updateDisplayAspectRatio() +{ + QWidget *screen = QApplication::desktop()->screen(); + + m_displayAspectRatio = screen->width() / (qreal)screen->height(); + + emit displayAspectRatioChanged(); +} + void Units::updateDevicePixelRatio() { // Going through QDesktopWidget seems to be the most reliable way no diff --git a/src/declarativeimports/core/units.h b/src/declarativeimports/core/units.h index 25dcd1027..312356fe5 100644 --- a/src/declarativeimports/core/units.h +++ b/src/declarativeimports/core/units.h @@ -83,6 +83,11 @@ class Units : public QObject */ Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged) + /** + * The ratio between the screen width and height of the main screen. + */ + Q_PROPERTY(qreal displayAspectRatio READ displayAspectRatio NOTIFY displayAspectRatioChanged) + /** * units.longDuration should be used for longer, screen-covering animations, for opening and * closing of dialogs and other "not too small" animations @@ -111,6 +116,11 @@ public: */ qreal devicePixelRatio() const; + /** + * @return The ratio between physical and device-independent pixels. + */ + qreal displayAspectRatio() const; + /** * @return map with iconsizes, indexed by name */ @@ -142,6 +152,7 @@ public: Q_SIGNALS: void devicePixelRatioChanged(); + void displayAspectRatioChanged(); void gridUnitChanged(); void iconSizesChanged(); void spacingChanged(); @@ -154,6 +165,7 @@ private Q_SLOTS: private: void updateDevicePixelRatio(); + void updateDisplayAspectRatio(); void updateSpacing(); /** * @return The dpi-adjusted size for a given icon size @@ -164,6 +176,7 @@ private: int m_gridUnit; qreal m_devicePixelRatio; + qreal m_displayAspectRatio; qreal m_dpi; QQmlPropertyMap *m_iconSizes;