diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-09-30 14:25:43 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-06 09:36:39 +0200 |
commit | 7d2cfbe5aa1e67d12010a66481625c9d40f0c174 (patch) | |
tree | 26734132827c40ba425d79481c2c4193bac5c5ea /src/widgets | |
parent | 29948e666583a26966ddb97faf4808099824b80d (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/widgets')
-rw-r--r-- | src/widgets/kernel/qwidget_qpa.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
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<QWidget *>(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<QWidget *>(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 } |