summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qhighdpiscaling.cpp
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-04-14 16:27:33 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-04-14 16:27:33 +0200
commit56b72d7809a6016149668b7df0dfd35022ff01c6 (patch)
tree06aaf93c55ce6f3185f70e1d5f9aa68372d2d807 /src/gui/kernel/qhighdpiscaling.cpp
parent04e4feae6c2fc0074839c490c81977ade20011c9 (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/kernel/qhighdpiscaling.cpp')
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp16
1 files changed, 14 insertions, 2 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)