diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2019-01-30 13:55:15 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2019-05-13 13:52:32 +0000 |
commit | 3af7b279177f7fb092f0e0fb9ffc8e8d846ed774 (patch) | |
tree | 576d1a52da95a0c8b2a805758da178a760ab5dfb /src/gui/kernel/qwindow.cpp | |
parent | 3da9d8a4fefc6f4e06320d2ba4c7c5fa8ebd1a10 (diff) |
Fix QWindow::mapToGlobal()/mapFromGlobal() for multi-screen windows
Make these functions handle the case where a window spans multiple
screens, and high-DPI scaling is enabled, and the local position (in the
window) is not on the window primary screen (as returned by
QWindow::screen()).
This is done by detecting the case, and then calculating
the correct position using the native coordinate system.
[ChangeLog][QtGui] QWindow::mapToGlobal()/mapFromGlobal() now handle
windows spanning screens correctly.
Done-with: Friedemann Kleint<Friedemann.Kleint@qt.io>
Task-number: QTBUG-73231
Change-Id: I3c31b741344d9e85e4f5d9e60bae75acce2db741
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 453aa1ed83..bcd8351619 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1670,9 +1670,9 @@ void QWindow::setGeometry(const QRect &rect) chicken and egg problem here: we cannot convert to native coordinates before we know which screen we are on. */ -QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) +QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) const { - Q_Q(QWindow); + Q_Q(const QWindow); QScreen *currentScreen = q->screen(); QScreen *fallback = currentScreen; QPoint center = newGeometry.center(); @@ -2542,6 +2542,10 @@ QPoint QWindow::mapToGlobal(const QPoint &pos) const && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) { return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this); } + + if (QHighDpiScaling::isActive()) + return QHighDpiScaling::mapPositionToGlobal(pos, d->globalPosition(), this); + return pos + d->globalPosition(); } @@ -2562,6 +2566,10 @@ QPoint QWindow::mapFromGlobal(const QPoint &pos) const && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) { return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this); } + + if (QHighDpiScaling::isActive()) + return QHighDpiScaling::mapPositionFromGlobal(pos, d->globalPosition(), this); + return pos - d->globalPosition(); } |