Made more QScreen properties NOTIFY and added average DPI properties.
authorSamuel Rødal <samuel.rodal@nokia.com>
Tue, 22 Nov 2011 09:34:47 +0000 (10:34 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 30 Nov 2011 18:04:18 +0000 (19:04 +0100)
The physicalDotsPerInch() is the average of the horizontal and vertical
physical dots per inch, and likewise logicalDotsPerInch() is the average
of the horizontal and vertical logical dots per inch.

Change-Id: I18aa610dc9a63efe062f78c823ba29f90b2712f4
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qscreen.cpp
src/gui/kernel/qscreen.h

index a329f99..63e8909 100644 (file)
@@ -982,19 +982,43 @@ void QGuiApplicationPrivate::reportScreenOrientationChange(QWindowSystemInterfac
     QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
 }
 
-void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *)
+void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
 {
     // This operation only makes sense after the QGuiApplication constructor runs
     if (QCoreApplication::startingUp())
         return;
+
+    if (!e->screen)
+        return;
+
+    QScreen *s = e->screen.data();
+
+    emit s->sizeChanged(s->size());
+    emit s->geometryChanged(s->geometry());
+    emit s->physicalDotsPerInchXChanged(s->physicalDotsPerInchX());
+    emit s->physicalDotsPerInchYChanged(s->physicalDotsPerInchY());
+    emit s->physicalDotsPerInchChanged(s->physicalDotsPerInch());
+    emit s->logicalDotsPerInchXChanged(s->logicalDotsPerInchX());
+    emit s->logicalDotsPerInchYChanged(s->logicalDotsPerInchY());
+    emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch());
+    emit s->availableSizeChanged(s->availableSize());
+    emit s->availableGeometryChanged(s->availableGeometry());
 }
 
 void QGuiApplicationPrivate::reportAvailableGeometryChange(
-        QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *)
+        QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e)
 {
     // This operation only makes sense after the QGuiApplication constructor runs
     if (QCoreApplication::startingUp())
         return;
+
+    if (!e->screen)
+        return;
+
+    QScreen *s = e->screen.data();
+
+    emit s->availableSizeChanged(s->availableSize());
+    emit s->availableGeometryChanged(s->availableGeometry());
 }
 
 void QGuiApplicationPrivate::processMapEvent(QWindowSystemInterfacePrivate::MapEvent *e)
index 682e42a..8a35ce6 100644 (file)
@@ -134,7 +134,7 @@ QSize QScreen::size() const
 */
 qreal QScreen::physicalDotsPerInchX() const
 {
-    return size().width() / physicalSize().width() * 25.4;
+    return size().width() / physicalSize().width() * qreal(25.4);
 }
 
 /*!
@@ -149,7 +149,28 @@ qreal QScreen::physicalDotsPerInchX() const
 */
 qreal QScreen::physicalDotsPerInchY() const
 {
-    return size().height() / physicalSize().height() * 25.4;
+    return size().height() / physicalSize().height() * qreal(25.4);
+}
+
+/*!
+  \property QScreen::physicalDotsPerInch
+  \brief the number of physical dots or pixels per inch
+
+  This value represents the pixel density on the screen's display.
+  Depending on what information the underlying system provides the value might not be
+  entirely accurate.
+
+  This is a convenience property that's simply the average of the physicalDotsPerInchX
+  and physicalDotsPerInchY properties.
+
+  \sa physicalDotsPerInchX()
+  \sa physicalDotsPerInchY()
+*/
+qreal QScreen::physicalDotsPerInch() const
+{
+    QSize sz = size();
+    QSizeF psz = physicalSize();
+    return ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
 }
 
 /*!
@@ -181,6 +202,25 @@ qreal QScreen::logicalDotsPerInchY() const
 }
 
 /*!
+  \property QScreen::logicalDotsPerInch
+  \brief the number of logical dots or pixels per inch
+
+  This value can be used to convert font point sizes to pixel sizes.
+
+  This is a convenience property that's simply the average of the logicalDotsPerInchX
+  and logicalDotsPerInchY properties.
+
+  \sa logicalDotsPerInchX()
+  \sa logicalDotsPerInchY()
+*/
+qreal QScreen::logicalDotsPerInch() const
+{
+    Q_D(const QScreen);
+    QDpi dpi = d->platformScreen->logicalDpi();
+    return (dpi.first + dpi.second) * qreal(0.5);
+}
+
+/*!
   \property QScreen::physicalSize
   \brief the screen's physical size (in millimeters)
 
index 8631180..6fc97c1 100644 (file)
@@ -70,17 +70,17 @@ class Q_GUI_EXPORT QScreen : public QObject
 
     Q_PROPERTY(QString name READ name CONSTANT)
     Q_PROPERTY(int depth READ depth CONSTANT)
-    Q_PROPERTY(QSize size READ size CONSTANT)
-    Q_PROPERTY(QRect geometry READ geometry CONSTANT)
+    Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
+    Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
     Q_PROPERTY(QSizeF physicalSize READ physicalSize CONSTANT)
-    Q_PROPERTY(qreal physicalDotsPerInchX READ physicalDotsPerInchX CONSTANT)
-    Q_PROPERTY(qreal physicalDotsPerInchY READ physicalDotsPerInchY CONSTANT)
-    Q_PROPERTY(qreal logicalDotsPerInchX READ logicalDotsPerInchX CONSTANT)
-    Q_PROPERTY(qreal logicalDotsPerInchY READ logicalDotsPerInchY CONSTANT)
-    Q_PROPERTY(QSize availableSize READ availableSize CONSTANT)
-    Q_PROPERTY(QRect availableGeometry READ availableGeometry CONSTANT)
-    Q_PROPERTY(QSize virtualSize READ virtualSize CONSTANT)
-    Q_PROPERTY(QRect availableVirtualGeometry READ availableVirtualGeometry CONSTANT)
+    Q_PROPERTY(qreal physicalDotsPerInchX READ physicalDotsPerInchX NOTIFY physicalDotsPerInchXChanged)
+    Q_PROPERTY(qreal physicalDotsPerInchY READ physicalDotsPerInchY NOTIFY physicalDotsPerInchYChanged)
+    Q_PROPERTY(qreal physicalDotsPerInch READ physicalDotsPerInch NOTIFY physicalDotsPerInchChanged)
+    Q_PROPERTY(qreal logicalDotsPerInchX READ logicalDotsPerInchX NOTIFY logicalDotsPerInchXChanged)
+    Q_PROPERTY(qreal logicalDotsPerInchY READ logicalDotsPerInchY NOTIFY logicalDotsPerInchYChanged)
+    Q_PROPERTY(qreal logicalDotsPerInch READ logicalDotsPerInch NOTIFY logicalDotsPerInchChanged)
+    Q_PROPERTY(QSize availableSize READ availableSize NOTIFY availableSizeChanged)
+    Q_PROPERTY(QRect availableGeometry READ availableGeometry NOTIFY availableGeometryChanged)
     Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation CONSTANT)
     Q_PROPERTY(Qt::ScreenOrientation currentOrientation READ currentOrientation NOTIFY currentOrientationChanged)
 
@@ -98,9 +98,11 @@ public:
 
     qreal physicalDotsPerInchX() const;
     qreal physicalDotsPerInchY() const;
+    qreal physicalDotsPerInch() const;
 
     qreal logicalDotsPerInchX() const;
     qreal logicalDotsPerInchY() const;
+    qreal logicalDotsPerInch() const;
 
     QSize availableSize() const;
     QRect availableGeometry() const;
@@ -121,6 +123,16 @@ public:
     static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
 
 Q_SIGNALS:
+    void sizeChanged(const QSize &size);
+    void geometryChanged(const QRect &geometry);
+    void physicalDotsPerInchXChanged(qreal dpi);
+    void physicalDotsPerInchYChanged(qreal dpi);
+    void physicalDotsPerInchChanged(qreal dpi);
+    void logicalDotsPerInchXChanged(qreal dpi);
+    void logicalDotsPerInchYChanged(qreal dpi);
+    void logicalDotsPerInchChanged(qreal dpi);
+    void availableSizeChanged(const QSize &size);
+    void availableGeometryChanged(const QRect &rect);
     void currentOrientationChanged(Qt::ScreenOrientation orientation);
 
 private: