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/widgets/kernel/qwidget_qpa.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 65ba0fcb5a..f1e0835b8b 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -739,12 +739,15 @@ int QWidget::metric(PaintDeviceMetric m) const { Q_D(const QWidget); - QPlatformScreen *screen = 0; + QScreen *screen = 0; if (QWidget *topLevel = window()) - if (QWindow *topLevelWindow = topLevel->windowHandle()) - screen = QPlatformScreen::platformScreenForWindow(topLevelWindow); + if (QWindow *topLevelWindow = topLevel->windowHandle()) { + QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow); + if (platformScreen) + screen = platformScreen->screen(); + } if (!screen && QGuiApplication::primaryScreen()) - screen = QGuiApplication::primaryScreen()->handle(); + screen = QGuiApplication::primaryScreen(); if (!screen) { if (m == PdmDpiX || m == PdmDpiY) @@ -762,18 +765,22 @@ int QWidget::metric(PaintDeviceMetric m) const val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height(); } else if (m == PdmDepth) { return screen->depth(); - } else if (m == PdmDpiX || m == PdmPhysicalDpiX) { + } else if (m == PdmDpiX) { if (d->extra && d->extra->customDpiX) return d->extra->customDpiX; else if (d->parent) return static_cast(d->parent)->metric(m); - return qRound(screen->geometry().width() / double(screen->physicalSize().width() / 25.4)); - } else if (m == PdmDpiY || m == PdmPhysicalDpiY) { + return qRound(screen->logicalDotsPerInchX()); + } else if (m == PdmDpiY) { if (d->extra && d->extra->customDpiY) return d->extra->customDpiY; else if (d->parent) return static_cast(d->parent)->metric(m); - return qRound(screen->geometry().height() / double(screen->physicalSize().height() / 25.4)); + return qRound(screen->logicalDotsPerInchY()); + } else if (m == PdmPhysicalDpiX) { + return qRound(screen->physicalDotsPerInchX()); + } else if (m == PdmPhysicalDpiY) { + return qRound(screen->physicalDotsPerInchY()); } else { val = QPaintDevice::metric(m);// XXX } -- cgit v1.2.3