From 1fbe8242ece70fe5aa2b50e9a782ec509b163b78 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 11 Jan 2012 11:49:35 +0100 Subject: QStyleHelper: Base DPI-calculation on QScreen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use qt_defaultDpiX() to obtain the resolution, which obtains it from QScreen. This implies that for X11, which previously used a hardcoded default of 96 DPI, the real resolution will be used (typically 75). - Since many tests (layouts, graphicsview) contain test data for 96 DPI, add an attribute to QCoreApplication making it possible to set the resolution to 96 DPI for testing. Change-Id: I77c8233a96b0d75de07406f58d48886a89c3de06 Reviewed-by: Samuel Rødal --- src/gui/text/qfont.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/gui') diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 5bf9094615..1ac398967d 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -138,36 +138,32 @@ extern bool qt_is_gui_used; Q_GUI_EXPORT int qt_defaultDpiX() { + if (qApp->testAttribute(Qt::AA_Use96Dpi)) + return 96; + if (!qt_is_gui_used) return 75; - int dpi; - QScreen *screen = QGuiApplication::primaryScreen(); - if (screen) { - dpi = qRound(screen->logicalDotsPerInchX()); - } else { - //PI has not been initialised, or it is being initialised. Give a default dpi - dpi = 100; - } + if (const QScreen *screen = QGuiApplication::primaryScreen()) + return qRound(screen->logicalDotsPerInchX()); - return dpi; + //PI has not been initialised, or it is being initialised. Give a default dpi + return 100; } Q_GUI_EXPORT int qt_defaultDpiY() { + if (qApp->testAttribute(Qt::AA_Use96Dpi)) + return 96; + if (!qt_is_gui_used) return 75; - int dpi; - QScreen *screen = QGuiApplication::primaryScreen(); - if (screen) { - dpi = qRound(screen->logicalDotsPerInchY()); - } else { - //PI has not been initialised, or it is being initialised. Give a default dpi - dpi = 100; - } + if (const QScreen *screen = QGuiApplication::primaryScreen()) + return qRound(screen->logicalDotsPerInchY()); - return dpi; + //PI has not been initialised, or it is being initialised. Give a default dpi + return 100; } Q_GUI_EXPORT int qt_defaultDpi() -- cgit v1.2.3