Move QT_FONT_DPI to cross-platform code

This makes it possible to test the effects of setting
Qt::AA_HighDpiScaling/QT_AUTO_SCREEN_SCALE_FACTOR, with different DPI
values on all platforms.

This also makes it possible to access the actual DPI values reported
by the OS/WS via the QPlatformScreen API.

A drawback is that there is no single place to check the environment
variable; currently done in three places. This may be
further simplified later on.

Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io>
Task-number: QTBUG-53022
Change-Id: Idd6463219d3ae58fe0ab72c17686cce2eb9dbadd
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Morten Johan Sørvig 2016-06-02 09:52:21 +02:00
parent 3e5362bfa1
commit 70a893e9be
6 changed files with 19 additions and 10 deletions

View File

@ -276,7 +276,7 @@ qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen)
qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch(); qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch();
factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first); factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first);
} else { } else {
QDpi platformLogicalDpi = screen->logicalDpi(); const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi());
factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first); factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first);
} }
@ -629,7 +629,7 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
return QDpi(96, 96); return QDpi(96, 96);
if (!m_usePixelDensity) if (!m_usePixelDensity)
return screen->handle()->logicalDpi(); return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi());
const qreal scaleFactor = rawScaleFactor(screen->handle()); const qreal scaleFactor = rawScaleFactor(screen->handle());
const qreal roundedScaleFactor = roundScaleFactor(scaleFactor); const qreal roundedScaleFactor = roundScaleFactor(scaleFactor);

View File

@ -193,6 +193,14 @@ QDpi QPlatformScreen::logicalDpi() const
25.4 * s.height() / ps.height()); 25.4 * s.height() / ps.height());
} }
// Helper function for accessing the platform screen logical dpi
// which accounts for QT_FONT_DPI.
QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in)
{
static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI");
return overrideDpi > 0 ? QDpi(overrideDpi, overrideDpi) : in;
}
/*! /*!
Reimplement to return the base logical DPI for the platform. This Reimplement to return the base logical DPI for the platform. This
DPI value should correspond to a standard-DPI (1x) display. The DPI value should correspond to a standard-DPI (1x) display. The

View File

@ -161,6 +161,8 @@ public:
// The platform screen's geometry in device independent coordinates // The platform screen's geometry in device independent coordinates
QRect deviceIndependentGeometry() const; QRect deviceIndependentGeometry() const;
static QDpi overrideDpi(const QDpi &in);
protected: protected:
void resizeMaximizedWindows(); void resizeMaximizedWindows();

View File

@ -84,8 +84,11 @@ void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen)
platformScreen->d_func()->screen = q; platformScreen->d_func()->screen = q;
orientation = platformScreen->orientation(); orientation = platformScreen->orientation();
geometry = platformScreen->deviceIndependentGeometry(); geometry = platformScreen->deviceIndependentGeometry();
availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft()); availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(),
logicalDpi = platformScreen->logicalDpi(); QHighDpiScaling::factor(platformScreen), geometry.topLeft());
logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
refreshRate = platformScreen->refreshRate(); refreshRate = platformScreen->refreshRate();
// safeguard ourselves against buggy platform behavior... // safeguard ourselves against buggy platform behavior...
if (refreshRate < 1.0) if (refreshRate < 1.0)

View File

@ -857,8 +857,8 @@ void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const Q
void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY) void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
{ {
QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e = const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, dpiX, dpiY); // ### tja auto e = new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, effectiveDpi.first, effectiveDpi.second);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
} }

View File

@ -660,10 +660,6 @@ QImage::Format QXcbScreen::format() const
int QXcbScreen::forcedDpi() const int QXcbScreen::forcedDpi() const
{ {
static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI");
if (overrideDpi)
return overrideDpi;
const int forcedDpi = m_virtualDesktop->forcedDpi(); const int forcedDpi = m_virtualDesktop->forcedDpi();
if (forcedDpi > 0) if (forcedDpi > 0)
return forcedDpi; return forcedDpi;