diff options
author | Sergio Martins <sergio.martins.qnx@kdab.com> | 2013-01-07 12:27:44 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-07 21:57:33 +0100 |
commit | 742f0c6e0b8e3ec6fddc146205e78a93f600c1cf (patch) | |
tree | eea2dc6e5d6a1818da5de634bb8cc0e201c34d0e | |
parent | 25ae39046197a30c773bc300646dea05d4a124ca (diff) |
Fix DnD when using QSimpleDrag.
qApp->topLevelAt() returns the QShapedPixmapWindow that the DnD
operation created, but what we want is the QWidgetWindow.
QWidgetWindow has the code to handle QDragMove events.
In Qt4, QShapedPixmapWidget had a parent, so was never returned
by qApp->topLevelWidgets().
In Qt5 we must filter it out. Bug is visible in the QNX plugin,
which is the only user of QSimpleDrag.
Change-Id: I920da86f3a1a92ce8e087f5948292fa4c68d4d81
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/platformsupport/dnd/qshapedpixmapdndwindow_p.h | 1 | ||||
-rw-r--r-- | src/platformsupport/dnd/qsimpledrag.cpp | 17 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/platformsupport/dnd/qshapedpixmapdndwindow_p.h b/src/platformsupport/dnd/qshapedpixmapdndwindow_p.h index d377871f99..0448169ec6 100644 --- a/src/platformsupport/dnd/qshapedpixmapdndwindow_p.h +++ b/src/platformsupport/dnd/qshapedpixmapdndwindow_p.h @@ -52,6 +52,7 @@ QT_BEGIN_HEADER class QShapedPixmapWindow : public QWindow { + Q_OBJECT public: QShapedPixmapWindow(); diff --git a/src/platformsupport/dnd/qsimpledrag.cpp b/src/platformsupport/dnd/qsimpledrag.cpp index efaede4c5f..13938d6c39 100644 --- a/src/platformsupport/dnd/qsimpledrag.cpp +++ b/src/platformsupport/dnd/qsimpledrag.cpp @@ -68,6 +68,17 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_DRAGANDDROP +static QWindow* topLevelAt(const QPoint &pos) +{ + QWindowList list = QGuiApplication::topLevelWindows(); + for (int i = list.count()-1; i >= 0; --i) { + QWindow *w = list.at(i); + if (w->isVisible() && w->geometry().contains(pos) && !qobject_cast<QShapedPixmapWindow*>(w)) + return w; + } + return 0; +} + /*! \class QBasicDrag \brief QBasicDrag is a base class for implementing platform drag and drop. @@ -298,7 +309,7 @@ QMimeData *QSimpleDrag::platformDropData() void QSimpleDrag::startDrag() { QBasicDrag::startDrag(); - m_current_window = QGuiApplication::topLevelAt(QCursor::pos()); + m_current_window = topLevelAt(QCursor::pos()); if (m_current_window) { QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(m_current_window, drag()->mimeData(), QCursor::pos(), drag()->supportedActions()); setCanDrop(response.isAccepted()); @@ -321,7 +332,7 @@ void QSimpleDrag::cancel() void QSimpleDrag::move(const QMouseEvent *me) { QBasicDrag::move(me); - QWindow *window = QGuiApplication::topLevelAt(me->globalPos()); + QWindow *window = topLevelAt(me->globalPos()); if (!window) return; @@ -336,7 +347,7 @@ void QSimpleDrag::move(const QMouseEvent *me) void QSimpleDrag::drop(const QMouseEvent *me) { QBasicDrag::drop(me); - QWindow *window = QGuiApplication::topLevelAt(me->globalPos()); + QWindow *window = topLevelAt(me->globalPos()); if (!window) return; |