From f3992dac6aa8c925b27fc0da19f8547341f534ba Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 3 Jan 2017 12:11:02 +0100 Subject: Make QSimpleDrag work with highDPI scaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-57863 Change-Id: I940179a694ce992245dabb77ef6e92e027427524 Reviewed-by: Friedemann Kleint Reviewed-by: Tor Arne Vestbø Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/kernel/qsimpledrag.cpp | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'src/gui/kernel/qsimpledrag.cpp') diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp index a6ce04dc34..fc62273325 100644 --- a/src/gui/kernel/qsimpledrag.cpp +++ b/src/gui/kernel/qsimpledrag.cpp @@ -53,6 +53,8 @@ #include "qdir.h" #include "qimagereader.h" #include "qimagewriter.h" +#include "qplatformscreen.h" +#include "qplatformwindow.h" #include #include @@ -316,6 +318,25 @@ void QBasicDrag::updateCursor(Qt::DropAction action) updateAction(action); } + +static inline QPoint fromNativeGlobalPixels(const QPoint &point) +{ +#ifndef QT_NO_HIGHDPISCALING + QPoint res = point; + if (QHighDpiScaling::isActive()) { + for (const QScreen *s : qAsConst(QGuiApplicationPrivate::screen_list)) { + if (s->handle()->geometry().contains(point)) { + res = QHighDpi::fromNativePixels(point, s); + break; + } + } + } + return res; +#else + return point; +#endif +} + /*! \class QSimpleDrag \brief QSimpleDrag implements QBasicDrag for Drag and Drop operations within the Qt Application itself. @@ -344,7 +365,7 @@ void QSimpleDrag::startDrag() QBasicDrag::startDrag(); m_current_window = topLevelAt(QCursor::pos()); if (m_current_window) { - QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(m_current_window, drag()->mimeData(), QCursor::pos(), drag()->supportedActions()); + QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(m_current_window, drag()->mimeData(), QHighDpi::toNativePixels(QCursor::pos(), m_current_window), drag()->supportedActions()); setCanDrop(response.isAccepted()); updateCursor(response.acceptedAction()); } else { @@ -363,15 +384,15 @@ void QSimpleDrag::cancel() } } -void QSimpleDrag::move(const QPoint &globalPos) +void QSimpleDrag::move(const QPoint &nativeGlobalPos) { - //### not high-DPI aware + QPoint globalPos = fromNativeGlobalPixels(nativeGlobalPos); moveShapedPixmapWindow(globalPos); QWindow *window = topLevelAt(globalPos); if (!window) return; - const QPoint pos = globalPos - window->geometry().topLeft(); + const QPoint pos = nativeGlobalPos - window->handle()->geometry().topLeft(); const QPlatformDragQtResponse qt_response = QWindowSystemInterface::handleDrag(window, drag()->mimeData(), pos, drag()->supportedActions()); @@ -379,16 +400,16 @@ void QSimpleDrag::move(const QPoint &globalPos) setCanDrop(qt_response.isAccepted()); } -void QSimpleDrag::drop(const QPoint &globalPos) +void QSimpleDrag::drop(const QPoint &nativeGlobalPos) { - //### not high-DPI aware + QPoint globalPos = fromNativeGlobalPixels(nativeGlobalPos); - QBasicDrag::drop(globalPos); + QBasicDrag::drop(nativeGlobalPos); QWindow *window = topLevelAt(globalPos); if (!window) return; - const QPoint pos = globalPos - window->geometry().topLeft(); + const QPoint pos = nativeGlobalPos - window->handle()->geometry().topLeft(); const QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(window, drag()->mimeData(),pos, drag()->supportedActions()); if (response.isAccepted()) { -- cgit v1.2.3