From f3973cbd077d2d92250958f8bda57fea30827f00 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 26 Apr 2013 14:46:05 +0200 Subject: [PATCH] Add more geometry properties to the Screen attached property desktopAvailableHeight is useful for positioning windows, and logicalPixelDensity is useful for ensuring that touch controls are a reasonable size even on very high-resolution displays. Change-Id: Id777caf6cef1df5bc01757605e3085151170760b Reviewed-by: Richard Moe Gustavsen --- src/quick/items/qquickscreen.cpp | 84 ++++++++++++++++++++++++++++++++++++++-- src/quick/items/qquickscreen_p.h | 10 +++++ 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 33a831a..91638d4 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE To use this type, you will need to import the module with the following line: \code - import QtQuick.Window 2.0 + import QtQuick.Window 2.1 \endcode It is a separate import in order to allow you to have a QML environment without access to window system features. @@ -80,6 +80,13 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlattachedproperty String QtQuick.Window2::Screen::name + \readonly + \since Qt 5.1 + + The name of the screen. +*/ +/*! \qmlattachedproperty int QtQuick.Window2::Screen::width \readonly @@ -92,6 +99,43 @@ QT_BEGIN_NAMESPACE This contains the height of the screen in pixels. */ /*! + \qmlattachedproperty int QtQuick.Window2::Screen::desktopAvailableWidth + \readonly + \since Qt 5.1 + + This contains the available width of the collection of screens which make + up the virtual desktop, in pixels, excluding window manager reserved areas + such as task bars and system menus. If you want to position a Window at + the right of the desktop, you can bind to it like this: + + \qml + x: Screen.desktopAvailableWidth - width + \endqml +*/ +/*! + \qmlattachedproperty int QtQuick.Window2::Screen::desktopAvailableHeight + \readonly + \since Qt 5.1 + + This contains the available height of the collection of screens which make + up the virtual desktop, in pixels, excluding window manager reserved areas + such as task bars and system menus. If you want to position a Window at + the bottom of the desktop, you can bind to it like this: + + \qml + y: Screen.desktopAvailableHeight - height + \endqml +*/ +/*! + \qmlattachedproperty real QtQuick.Window2::Screen::logicalPixelDensity + \readonly + \since Qt 5.1 + + The number of logical pixels per millimeter. Logical pixels are the + usual units in QML; on some systems they may be different than physical + pixels. +*/ +/*! \qmlattachedproperty Qt::ScreenOrientation QtQuick.Window2::Screen::primaryOrientation \readonly @@ -147,6 +191,13 @@ QQuickScreenAttached::QQuickScreenAttached(QObject* attachee) } } +QString QQuickScreenAttached::name() const +{ + if (!m_screen) + return QString(); + return m_screen->name(); +} + int QQuickScreenAttached::width() const { if (!m_screen) @@ -161,6 +212,27 @@ int QQuickScreenAttached::height() const return m_screen->size().height(); } +int QQuickScreenAttached::desktopAvailableWidth() const +{ + if (!m_screen) + return 0; + return m_screen->availableVirtualSize().width(); +} + +int QQuickScreenAttached::desktopAvailableHeight() const +{ + if (!m_screen) + return 0; + return m_screen->availableVirtualSize().height(); +} + +qreal QQuickScreenAttached::logicalPixelDensity() const +{ + if (!m_screen) + return 0.0; + return m_screen->logicalDotsPerInch() / 25.4; +} + Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const { if (!m_screen) @@ -209,12 +281,14 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) emit widthChanged(); emit heightChanged(); } - if (!oldScreen || screen->orientation() != oldScreen->orientation()) emit orientationChanged(); if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation()) emit primaryOrientationChanged(); - + if (!oldScreen || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry()) + emit desktopGeometryChanged(); + if (!oldScreen || screen->logicalDotsPerInch() != oldScreen->logicalDotsPerInch()) + emit logicalPixelDensityChanged(); connect(screen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(widthChanged())); @@ -224,6 +298,10 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) this, SIGNAL(orientationChanged())); connect(screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), this, SIGNAL(primaryOrientationChanged())); + connect(screen, SIGNAL(virtualGeometryChanged(const QRect &)), + this, SIGNAL(desktopGeometryChanged())); + connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)), + this, SIGNAL(logicalPixelDensityChanged())); } } diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 98f38b7..7ce035a 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -58,16 +58,24 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject { Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT REVISION 1); Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) + 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(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged) Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged) public: QQuickScreenAttached(QObject* attachee); + QString name() const; int width() const; int height() const; + int desktopAvailableWidth() const; + int desktopAvailableHeight() const; + qreal logicalPixelDensity() const; Qt::ScreenOrientation primaryOrientation() const; Qt::ScreenOrientation orientation() const; @@ -79,6 +87,8 @@ public: Q_SIGNALS: void widthChanged(); void heightChanged(); + Q_REVISION(1) void desktopGeometryChanged(); + Q_REVISION(1) void logicalPixelDensityChanged(); void primaryOrientationChanged(); void orientationChanged(); -- 2.7.4