diff options
author | Gatis Paeglis <gatis.paeglis@digia.com> | 2014-09-19 10:55:11 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@digia.com> | 2014-09-25 12:04:48 +0300 |
commit | 0200b91ae7326dd5c19e07407f48312f80c79368 (patch) | |
tree | 3b8069d54006b78c0c8a39e98ce0d44f25b07d84 | |
parent | ca4bd3b0bd675365ebc64628c3fac9ba36f47c9e (diff) |
Add few helper functions to qml context
m_dpcm is a "scaled cm" based on visual angle, meaning
the eye has a given viewing angle, say you can see 180
degrees horizontally and 120 degrees vertically so both
the cellphone and the TV takes up about 30 degrees
vertically (a phone at 40cm away takes up about the same
as a 40 inch TV a few meters away) so a button could be
2 degrees on both devices. Thanks to Gunnar for explaining
this.
We can use these helper functions to create demos that
scale well on devices with different screen sizes and
pixel density.
Change-Id: I29bbc8128207d4f494ed1181d845e1416e7fada9
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
-rw-r--r-- | qml/main_landscape.qml | 5 | ||||
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/engine.h | 6 |
3 files changed, 9 insertions, 4 deletions
diff --git a/qml/main_landscape.qml b/qml/main_landscape.qml index 599645c..527e23b 100644 --- a/qml/main_landscape.qml +++ b/qml/main_landscape.qml @@ -18,9 +18,8 @@ import QtQuick 2.0 Item { - width: 800 - height: 1280 - + width: engine.screenWidth() + height: engine.screenHeight() Main { anchors.centerIn: parent width: parent.height diff --git a/src/engine.cpp b/src/engine.cpp index 1ecd06a..2fe960b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -61,6 +61,8 @@ Engine::Engine(QObject *parent) float high = 20; float screenSizeCM = qMax<float>(qMin(m_screenSize.width(), m_screenSize.height()) / m_dpcm, low); m_dpcm *= (screenSizeCM - low) / (high - low) * 0.5 + 0.5; + m_screenWidth = m_screenSize.width(); + m_screenHeight = m_screenSize.height(); } diff --git a/src/engine.h b/src/engine.h index a837879..a33c08a 100644 --- a/src/engine.h +++ b/src/engine.h @@ -77,7 +77,10 @@ public: Q_INVOKABLE int smallFontSize() const { return qMax<int>(m_dpcm * 0.4, 10); } Q_INVOKABLE int fontSize() const { return qMax<int>(m_dpcm * 0.6, 14); } Q_INVOKABLE int titleFontSize() const { return qMax<int>(m_dpcm * 0.9, 20); } - Q_INVOKABLE int centimeter() const { return m_dpcm; } + Q_INVOKABLE int centimeter(int val = 1) const { return (m_dpcm * val); } + Q_INVOKABLE int mm(int val) const { return (int)(m_dpcm * val * 0.1); } + Q_INVOKABLE int screenWidth() const { return m_screenWidth; } + Q_INVOKABLE int screenHeight() const { return m_screenHeight; } protected: @@ -114,6 +117,7 @@ private: QSize m_screenSize; qreal m_dpcm; + int m_screenWidth, m_screenHeight; FpsCounter *m_fpsCounter; qreal m_fps; |