diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-04-14 16:27:33 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-04-14 16:27:33 +0200 |
commit | 56b72d7809a6016149668b7df0dfd35022ff01c6 (patch) | |
tree | 06aaf93c55ce6f3185f70e1d5f9aa68372d2d807 /src/gui | |
parent | 04e4feae6c2fc0074839c490c81977ade20011c9 (diff) |
Per-screen scaleFactor
To enable, set QT_SCALE_FACTOR=auto
Tons of bugs, since this does not port all the QT_DEVICE_PIXEL_RATIO
fixes from xcb.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling_p.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.cpp | 2 |
5 files changed, 32 insertions, 7 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index eeeb995d43..0d847a243f 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -77,6 +77,7 @@ static inline qreal initialScaleFactor() */ qreal QHighDpiScaling::m_factor = initialScaleFactor(); +bool QHighDpiScaling::m_autoFactor = qgetenv("QT_SCALE_FACTOR").toLower() == "auto"; bool QHighDpiScaling::m_active = !qFuzzyCompare(QHighDpiScaling::m_factor, qreal(1)); bool QHighDpiScaling::m_perWindowActive = false; @@ -103,13 +104,24 @@ void QHighDpiScaling::setWindowFactor(QWindow *window, qreal factor) window->setProperty(scaleFactorProperty, QVariant(factor)); } +qreal QHighDpiScaling::factor(const QScreen *screen) +{ + if (m_autoFactor && screen && screen->handle()) + return screen->handle()->pixelDensity(); + return m_factor; +} + + qreal QHighDpiScaling::factor(const QWindow *window) { + qreal f = m_factor; + if (m_autoFactor && window && window->screen() && window->screen()->handle()) + f = window->screen()->handle()->pixelDensity(); if (!m_perWindowActive || window == 0) - return m_factor; + return f; QVariant windowFactor = window->property(scaleFactorProperty); - return m_factor * (windowFactor.isValid() ? windowFactor.toReal() : 1); + return f * (windowFactor.isValid() ? windowFactor.toReal() : 1); } Q_GUI_EXPORT QSize QHighDpi::toDevicePixelsConstrained(const QSize &size, const QWindow *window) diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 6929b3ac83..5827bc1565 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -79,11 +79,13 @@ Q_DECLARE_LOGGING_CATEGORY(lcScaling); class Q_GUI_EXPORT QHighDpiScaling { public: static bool isActive() { return m_active; } - static qreal factor(const QWindow *window = 0); + static qreal factor(const QWindow *window); + static qreal factor(const QScreen *screen); static void setFactor(qreal factor); static void setWindowFactor(QWindow *window, qreal factor); private: static qreal m_factor; + static bool m_autoFactor; static bool m_active; static bool m_perWindowActive; }; diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index e2c84fbc2c..6088e6495e 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -157,9 +157,9 @@ QDpi QPlatformScreen::logicalDpi() const } /*! - Reimplement this function in subclass to return the device pixel - ratio for the screen. This is the ratio between physical pixels - and device-independent pixels. + Reimplement this function in subclass to return the device pixel ratio + for the screen. This is the ratio between physical pixels and the + device-independent pixels of the windowing system. \sa QPlatformWindow::devicePixelRatio(); */ @@ -169,6 +169,16 @@ qreal QPlatformScreen::devicePixelRatio() const } /*! + Reimplement this function in subclass to return the pixel density of the + screen. This is the scale factor needed to make a low-dpi application + usable on this screen. The default implementation returns 1.0. +*/ +qreal QPlatformScreen::pixelDensity() const +{ + return 1.0; +} + +/*! Reimplement this function in subclass to return the vertical refresh rate of the screen, in Hz. diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index ad1cb6f9b3..8dceef26eb 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -96,6 +96,7 @@ public: virtual QSizeF physicalSize() const; virtual QDpi logicalDpi() const; virtual qreal devicePixelRatio() const; + virtual qreal pixelDensity() const; virtual qreal refreshRate() const; diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 684b298631..91cef9640b 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -259,7 +259,7 @@ qreal QScreen::logicalDotsPerInch() const qreal QScreen::devicePixelRatio() const { Q_D(const QScreen); - return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(); + return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(this); } /*! |