From 7d2cfbe5aa1e67d12010a66481625c9d40f0c174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 30 Sep 2011 14:25:43 +0200 Subject: Improved logical and physical DPI APIs. Made physicalSize() return QSizeF instead, to prevent rounding errors. Added logicalSize() as the base to compute font pixel sizes instead, and added convenience functions in QScreen to access the logical and physical sizes and DPI metrics. Task-number: QTBUG-21736 Task-number: QTBUG-21737 Change-Id: Ic705dc98eb3632617659e65a0c9a552673dc0c65 Reviewed-on: http://codereview.qt-project.org/5888 Reviewed-by: Qt Sanity Bot Reviewed-by: Friedemann Kleint --- src/gui/kernel/qscreen.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/gui/kernel/qscreen.cpp') diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 96ed2bd410..c2049af1e5 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -101,6 +101,75 @@ QSize QScreen::size() const return d->platformScreen->geometry().size(); } +/*! + Gets the number of physical dots or pixels per inch in the horizontal direction. + + This value represents the actual horizontal pixel density on the screen's display. + Depending on what information the underlying system provides the value might not be + entirely accurate. + + \sa physicalDotsPerInchY() +*/ +qreal QScreen::physicalDotsPerInchX() const +{ + return size().width() / physicalSize().width() * 25.4; +} + +/*! + Gets the number of physical dots or pixels per inch in the vertical direction. + + This value represents the actual vertical pixel density on the screen's display. + Depending on what information the underlying system provides the value might not be + entirely accurate. + + \sa physicalDotsPerInchX() +*/ +qreal QScreen::physicalDotsPerInchY() const +{ + return size().height() / physicalSize().height() * 25.4; +} + +/*! + Gets the number of logical dots or pixels per inch in the horizontal direction. + + This value is used to convert font point sizes to pixel sizes. + + \sa logicalDotsPerInchY() +*/ +qreal QScreen::logicalDotsPerInchX() const +{ + Q_D(const QScreen); + return d->platformScreen->logicalDpi().first; +} + +/*! + Gets the number of logical dots or pixels per inch in the vertical direction. + + This value is used to convert font point sizes to pixel sizes. + + \sa logicalDotsPerInchX() +*/ +qreal QScreen::logicalDotsPerInchY() const +{ + Q_D(const QScreen); + return d->platformScreen->logicalDpi().second; +} + +/*! + Get the screen's physical size (in millimeters). + + The physical size represents the actual physical dimensions of the + screen's display. + + Depending on what information the underlying system provides the value + might not be entirely accurate. +*/ +QSizeF QScreen::physicalSize() const +{ + Q_D(const QScreen); + return d->platformScreen->physicalSize(); +} + /*! Get the screen's available size. -- cgit v1.2.3