diff options
author | Paul Olav Tvete <paul.tvete@gmail.com> | 2015-05-04 17:48:18 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@gmail.com> | 2015-05-04 17:55:02 +0200 |
commit | c05a8757b095cb554ea3e50f202a0683ca7d5bf7 (patch) | |
tree | 0cc94f6907d57030e7db4e67e59781c269ce9906 /src/gui/kernel/qhighdpiscaling.cpp | |
parent | 3110a6642cb9424069ad89666e3cca01d1d6b420 (diff) |
Multi-screen fixes
Various fixes, including:
* Resize backingstore properly if screen has changed
* Trigger resize event on screen change if necessary
* Fix yet another race condition in screen detection
* Trying to fix screen mapping
Not completely finished, but I think it's better to
keep in sync, and not diverge too much.
Diffstat (limited to 'src/gui/kernel/qhighdpiscaling.cpp')
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index ff3f48b33f..54d06a8572 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -78,7 +78,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_active = m_autoFactor || !qFuzzyCompare(QHighDpiScaling::m_factor, qreal(1)); bool QHighDpiScaling::m_perWindowActive = false; void QHighDpiScaling::setFactor(qreal factor) @@ -104,6 +104,44 @@ void QHighDpiScaling::setWindowFactor(QWindow *window, qreal factor) window->setProperty(scaleFactorProperty, QVariant(factor)); } + +/* + +QPoint QXcbScreen::mapToNative(const QPoint &pos) const +{ + const int dpr = int(devicePixelRatio()); + return (pos - m_geometry.topLeft()) * dpr + m_nativeGeometry.topLeft(); +} + +QPoint QXcbScreen::mapFromNative(const QPoint &pos) const +{ + const int dpr = int(devicePixelRatio()); + return (pos - m_nativeGeometry.topLeft()) / dpr + m_geometry.topLeft(); +} + + + */ + + +QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen) +{ + if (!platformScreen) + return pos; + const qreal scaleFactor = factor(platformScreen); + const QPoint topLeft = platformScreen->geometry().topLeft(); + return (pos - topLeft) * scaleFactor + topLeft; +} + +QPoint QHighDpiScaling::mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen) +{ + if (!platformScreen) + return pos; + const qreal scaleFactor = factor(platformScreen); + const QPoint topLeft = platformScreen->geometry().topLeft(); + return (pos - topLeft) / scaleFactor + topLeft; +} + + qreal QHighDpiScaling::factor(const QScreen *screen) { if (m_autoFactor && screen && screen->handle()) @@ -111,6 +149,12 @@ qreal QHighDpiScaling::factor(const QScreen *screen) return m_factor; } +qreal QHighDpiScaling::factor(const QPlatformScreen *platformScreen) +{ + if (m_autoFactor && platformScreen) + return platformScreen->pixelDensity(); + return m_factor; +} qreal QHighDpiScaling::factor(const QWindow *window) { @@ -124,6 +168,17 @@ qreal QHighDpiScaling::factor(const QWindow *window) return f * (windowFactor.isValid() ? windowFactor.toReal() : 1); } +QPoint QHighDpiScaling::origin(const QScreen *screen) +{ + return screen->geometry().topLeft(); +} + +QPoint QHighDpiScaling::origin(const QPlatformScreen *platformScreen) +{ + return platformScreen->geometry().topLeft(); +} + + Q_GUI_EXPORT QSize QHighDpi::toNativePixelsConstrained(const QSize &size, const QWindow *window) { const int width = size.width(); |