summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-11-22 10:34:47 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-30 19:04:18 +0100
commit6468dd4179278276d3ad98696b6f761efa397924 (patch)
treee744103b678b4e795350df13eaa892c34a1ba979 /src/gui/kernel
parentcc9c85ecd68c8dae28567dac630f894faaaf1acf (diff)
Made more QScreen properties NOTIFY and added average DPI properties.
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>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp28
-rw-r--r--src/gui/kernel/qscreen.cpp44
-rw-r--r--src/gui/kernel/qscreen.h32
3 files changed, 90 insertions, 14 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index a329f99931..63e8909eeb 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -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)
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 682e42ad4c..8a35ce6b8f 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -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)
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index 8631180a8f..6fc97c1799 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -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: