diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-06-16 13:16:03 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-06-18 12:52:52 +0000 |
commit | 30ab9184ad452c892ddd02126ff52d7c7b5f5c38 (patch) | |
tree | 6798b50866c5cd98d866ba3b234d52b0d265135c /src/gui/kernel/qhighdpiscaling.cpp | |
parent | 41bb5f362e49cc68b85022b749aaf654fa5c55bf (diff) |
Only turn off font hinting when really scaling
We don't want to turn off font hinting based on whether auto-scaling is on,
otherwise Qt Creator will look bad on a low-DPI screen. Instead, we turn it
off only if we have at least one screen that is scaled.
QHighDpiScaling::isActive() now means that there is actual scaling going on.
There is currently no need for the old meaning, so this change does not include
QHighDpiScaling::isEnabled().
Note that nothing can save us from the case where there is one high-DPI and
one low-DPI screen. In that case we choose looking bad on the low-DPI screen
instead of looking like crap on the high-DPI screen. Also note that our font
system we doesn't allow us to change our minds on hinting later when screens
are plugged in or removed.
Change-Id: I14a4ec7a49f4ba74a4c74684c7b951d0a71b951d
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel/qhighdpiscaling.cpp')
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 56fd38486d..2fee06c77d 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -124,23 +124,41 @@ static inline qreal initialScaleFactor() qreal QHighDpiScaling::m_factor; bool QHighDpiScaling::m_active; //"overall active" - is there any scale factor set. -bool QHighDpiScaling::m_perScreenActive; // different screens may have different scale bool QHighDpiScaling::m_usePixelDensity; // use scale factor from platform plugin +bool QHighDpiScaling::m_pixelDensityScalingActive; // pixel density scale factor > 1 +bool QHighDpiScaling::m_globalScalingActive; // global scale factor is active +bool QHighDpiScaling::m_screenFactorSet; // QHighDpiScaling::setScreenFactor has been used /* Initializes the QHighDpiScaling global variables. Called before the platform plugin is created. */ -void QHighDpiScaling::initHighDPiScaling() +void QHighDpiScaling::initHighDpiScaling() { m_factor = initialScaleFactor(); bool usePlatformPluginPixelDensity = qEnvironmentVariableIsSet(autoScreenEnvVar) || qgetenv(legacyDevicePixelEnvVar).toLower() == "auto"; - // m_active below is "overall active" - is there any scale factor set. - m_active = !qFuzzyCompare(m_factor, qreal(1)) || usePlatformPluginPixelDensity; + m_globalScalingActive = !qFuzzyCompare(m_factor, qreal(1)); m_usePixelDensity = usePlatformPluginPixelDensity; - m_perScreenActive = m_usePixelDensity; + m_pixelDensityScalingActive = false; //set in updateHighDpiScaling below + + // we update m_active in updateHighDpiScaling, but while we create the + // screens, we have to assume that m_usePixelDensity implies scaling + m_active = m_globalScalingActive || m_usePixelDensity; +} + +void QHighDpiScaling::updateHighDpiScaling() +{ + if (m_usePixelDensity && !m_pixelDensityScalingActive) { + Q_FOREACH (QScreen *screen, QGuiApplication::screens()) { + if (!qFuzzyCompare(screenSubfactor(screen->handle()), qreal(1))) { + m_pixelDensityScalingActive = true; + break; + } + } + } + m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive; } /* @@ -148,14 +166,15 @@ void QHighDpiScaling::initHighDPiScaling() */ void QHighDpiScaling::setGlobalFactor(qreal factor) { - if (qFuzzyCompare(factor, QHighDpiScaling::m_factor)) + if (qFuzzyCompare(factor, m_factor)) return; if (!QGuiApplication::allWindows().isEmpty()) { qWarning() << Q_FUNC_INFO << "QHighDpiScaling::setFactor: Should only be called when no windows exist."; } - QHighDpiScaling::m_active = !qFuzzyCompare(factor, qreal(1)); - QHighDpiScaling::m_factor = QHighDpiScaling::m_active ? factor : qreal(1); + m_globalScalingActive = !qFuzzyCompare(factor, qreal(1)); + m_factor = m_globalScalingActive ? factor : qreal(1); + m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive; Q_FOREACH (QScreen *screen, QGuiApplication::screens()) screen->d_func()->updateHighDpi(); } @@ -167,8 +186,8 @@ static const char *scaleFactorProperty = "_q_scaleFactor"; */ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) { + m_screenFactorSet = true; m_active = true; - m_perScreenActive = true; screen->setProperty(scaleFactorProperty, QVariant(factor)); //### dirty hack to force re-evaluation of screen geometry @@ -215,12 +234,14 @@ QPoint QHighDpiScaling::mapPositionFromNative(const QPoint &pos, const QPlatform qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) { qreal factor = qreal(1.0); - if (m_perScreenActive && screen) { + if (screen) { if (m_usePixelDensity) factor *= screen->pixelDensity(); - QVariant screenFactor = screen->screen()->property(scaleFactorProperty); - if (screenFactor.isValid()) - factor *= screenFactor.toReal(); + if (m_screenFactorSet) { + QVariant screenFactor = screen->screen()->property(scaleFactorProperty); + if (screenFactor.isValid()) + factor *= screenFactor.toReal(); + } } return factor; } |