summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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: