summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatformscreen_qpa.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-09-30 14:25:43 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-06 09:36:39 +0200
commit7d2cfbe5aa1e67d12010a66481625c9d40f0c174 (patch)
tree26734132827c40ba425d79481c2c4193bac5c5ea /src/gui/kernel/qplatformscreen_qpa.cpp
parent29948e666583a26966ddb97faf4808099824b80d (diff)
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 <qt_sanity_bot@ovi.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src/gui/kernel/qplatformscreen_qpa.cpp')
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp
index 1a8e6d8f7c..86dc0bd588 100644
--- a/src/gui/kernel/qplatformscreen_qpa.cpp
+++ b/src/gui/kernel/qplatformscreen_qpa.cpp
@@ -127,20 +127,41 @@ QScreen *QPlatformScreen::screen() const
/*!
Reimplement this function in subclass to return the physical size of the
- screen. This function is used by QFont to convert point sizes to pixel
- sizes.
+ screen. The physical size represents the actual physical dimensions of
+ the display.
The default implementation takes the pixel size of the screen, considers a
resolution of 100 dots per inch, and returns the calculated physical size.
A device with a screen that has different resolutions will need to be
supported by a suitable reimplementation of this function.
+
+ \sa logcalDpi
*/
-QSize QPlatformScreen::physicalSize() const
+QSizeF QPlatformScreen::physicalSize() const
{
static const int dpi = 100;
- int width = geometry().width() / dpi * qreal(25.4) ;
- int height = geometry().height() / dpi * qreal(25.4) ;
- return QSize(width,height);
+ return QSizeF(geometry().size()) / dpi * qreal(25.4);
+}
+
+/*!
+ Reimplement this function in subclass to return the logical horizontal
+ and vertical dots per inch metrics of the screen.
+
+ The logical dots per inch metrics are used by QFont to convert point sizes
+ to pixel sizes.
+
+ The default implementation uses the screen pixel size and physical size to
+ compute the metrics.
+
+ \sa physicalSize
+*/
+QDpi QPlatformScreen::logicalDpi() const
+{
+ QSizeF ps = physicalSize();
+ QSize s = geometry().size();
+
+ return QDpi(25.4 * s.width() / ps.width(),
+ 25.4 * s.height() / ps.height());
}
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)