summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp33
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.h6
-rw-r--r--src/gui/kernel/qscreen.cpp69
-rw-r--r--src/gui/kernel/qscreen.h12
-rw-r--r--src/gui/text/qfont.cpp8
5 files changed, 114 insertions, 14 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)
diff --git a/src/gui/kernel/qplatformscreen_qpa.h b/src/gui/kernel/qplatformscreen_qpa.h
index 7c20fba0ba..6917d5eca5 100644
--- a/src/gui/kernel/qplatformscreen_qpa.h
+++ b/src/gui/kernel/qplatformscreen_qpa.h
@@ -67,6 +67,8 @@ class QPlatformWindow;
class QScreen;
class QSurfaceFormat;
+typedef QPair<qreal, qreal> QDpi;
+
class Q_GUI_EXPORT QPlatformScreenPageFlipper : public QObject
{
Q_OBJECT
@@ -93,7 +95,9 @@ public:
virtual int depth() const = 0;
virtual QImage::Format format() const = 0;
- virtual QSize physicalSize() const;
+
+ virtual QSizeF physicalSize() const;
+ virtual QDpi logicalDpi() const;
virtual QWindow *topLevelAt(const QPoint &point) const;
virtual QList<QPlatformScreen *> virtualSiblings() const;
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
@@ -102,6 +102,75 @@ QSize QScreen::size() const
}
/*!
+ 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.
The available size is the size excluding window manager reserved areas
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index ea068cd834..72681eb6da 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -44,6 +44,9 @@
#include <QtCore/QList>
#include <QtCore/QObject>
+#include <QtCore/QRect>
+#include <QtCore/QSize>
+#include <QtCore/QSizeF>
QT_BEGIN_HEADER
@@ -54,7 +57,6 @@ QT_MODULE(Gui)
class QPlatformScreen;
class QScreenPrivate;
class QWindow;
-class QSize;
class QRect;
class Q_GUI_EXPORT QScreen : public QObject
@@ -72,6 +74,14 @@ public:
QSize size() const;
QRect geometry() const;
+ QSizeF physicalSize() const;
+
+ qreal physicalDotsPerInchX() const;
+ qreal physicalDotsPerInchY() const;
+
+ qreal logicalDotsPerInchX() const;
+ qreal logicalDotsPerInchY() const;
+
QSize availableSize() const;
QRect availableGeometry() const;
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index e8308dba06..3d2dfb9c76 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -170,9 +170,7 @@ Q_GUI_EXPORT int qt_defaultDpiX()
#elif defined(Q_WS_QPA)
QScreen *screen = QGuiApplication::primaryScreen();
if (screen) {
- const QSize screenSize = screen->geometry().size();
- const QSize physicalSize = screen->handle()->physicalSize();
- dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4)));
+ dpi = qRound(screen->logicalDotsPerInchX());
} else {
//PI has not been initialised, or it is being initialised. Give a default dpi
dpi = 100;
@@ -200,9 +198,7 @@ Q_GUI_EXPORT int qt_defaultDpiY()
#elif defined(Q_WS_QPA)
QScreen *screen = QGuiApplication::primaryScreen();
if (screen) {
- const QSize screenSize = screen->geometry().size();
- const QSize physicalSize = screen->handle()->physicalSize();
- dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4)));
+ dpi = qRound(screen->logicalDotsPerInchY());
} else {
//PI has not been initialised, or it is being initialised. Give a default dpi
dpi = 100;