Compute logical DPI on a per-screen basis

The logical DPI reported to applications is the platform screen
logical DPI divided by the platform screen scale factor.

Use the screen in question when calculating the DPI instead of
the values from the main screen.

QHighDpiScaling::logicalDpi now takes a QScreen pointer.

Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io>
Task-number: QTBUG-53022
Change-Id: I0f62b5878c37e3488e9a8cc48aef183ff822d0c4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Morten Johan Sørvig 2016-04-25 09:27:48 +02:00
parent 16868bd6a2
commit dd9da0441b
3 changed files with 13 additions and 15 deletions

View File

@ -226,7 +226,6 @@ bool QHighDpiScaling::m_usePixelDensity = false; // use scale factor from platfo
bool QHighDpiScaling::m_pixelDensityScalingActive = false; // pixel density scale factor > 1
bool QHighDpiScaling::m_globalScalingActive = false; // global scale factor is active
bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFactor has been used
QDpi QHighDpiScaling::m_logicalDpi = QDpi(-1,-1); // The scaled logical DPI of the primary screen
/*
Initializes the QHighDpiScaling global variables. Called before the
@ -314,14 +313,6 @@ void QHighDpiScaling::updateHighDpiScaling()
}
}
m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
QScreen *primaryScreen = QGuiApplication::primaryScreen();
if (!primaryScreen)
return;
QPlatformScreen *platformScreen = primaryScreen->handle();
qreal sf = screenSubfactor(platformScreen);
QDpi primaryDpi = platformScreen->logicalDpi();
m_logicalDpi = QDpi(primaryDpi.first / sf, primaryDpi.second / sf);
}
/*
@ -447,9 +438,16 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
return factor;
}
QDpi QHighDpiScaling::logicalDpi()
QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
{
return m_logicalDpi;
// (Note: m_active test is performed at call site.)
if (!screen)
return QDpi(96, 96);
qreal platformScreenfactor = screenSubfactor(screen->handle());
QDpi platformScreenDpi = screen->handle()->logicalDpi();
return QDpi(platformScreenDpi.first / platformScreenfactor,
platformScreenDpi.second / platformScreenfactor);
}
QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *platformScreen, QPoint *nativePosition)

View File

@ -98,7 +98,7 @@ public:
static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen);
static QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
static QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
static QDpi logicalDpi();
static QDpi logicalDpi(const QScreen *screen);
private:
static qreal screenSubfactor(const QPlatformScreen *screen);

View File

@ -285,7 +285,7 @@ qreal QScreen::logicalDotsPerInchX() const
{
Q_D(const QScreen);
if (QHighDpiScaling::isActive())
return QHighDpiScaling::logicalDpi().first;
return QHighDpiScaling::logicalDpi(this).first;
return d->logicalDpi.first;
}
@ -301,7 +301,7 @@ qreal QScreen::logicalDotsPerInchY() const
{
Q_D(const QScreen);
if (QHighDpiScaling::isActive())
return QHighDpiScaling::logicalDpi().second;
return QHighDpiScaling::logicalDpi(this).second;
return d->logicalDpi.second;
}
@ -320,7 +320,7 @@ qreal QScreen::logicalDotsPerInchY() const
qreal QScreen::logicalDotsPerInch() const
{
Q_D(const QScreen);
QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi() : d->logicalDpi;
QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(this) : d->logicalDpi;
return (dpi.first + dpi.second) * qreal(0.5);
}