Make QSimpleDrag work with highDPI scaling

Task-number: QTBUG-57863
Change-Id: I940179a694ce992245dabb77ef6e92e027427524
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
bb10
Paul Olav Tvete 2017-01-03 12:11:02 +01:00
parent db226cbadc
commit f3992dac6a
1 changed files with 29 additions and 8 deletions

View File

@ -53,6 +53,8 @@
#include "qdir.h"
#include "qimagereader.h"
#include "qimagewriter.h"
#include "qplatformscreen.h"
#include "qplatformwindow.h"
#include <QtCore/QEventLoop>
#include <QtCore/QDebug>
@ -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()) {