aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen D'Angelo <stephen.m.dangelo@gmail.com>2017-11-30 12:14:16 -0500
committerShawn Rutledge <shawn.rutledge@qt.io>2019-10-09 19:23:31 +0000
commit3fde977a817498817e98ce350d493658b0ed4458 (patch)
treedb4d1c465fb3e7886b188d7bcf3c21fd581d1286
parent6b6ef3a8417e628ca01a1c2cad81af69ea5c9d3a (diff)
QQuickWindow: Higher z-order items now steal drop target
Previously, an active drop target would remain the drop target until the drag left it's area, or entered a child item that accepted a DragEnterEvent, even if the drag entered a drop target with a globally higher z-order from a different subtree. When moving to an item with a higher z-order, the DragEnterEvent is now sent to the new drop target before DragLeaveEvent is sent to the old drop target. There can now only be one drop target. If an item is the current drop target and a higher z-order child accepts the DragEnterEvent, the parent is no longer a drop target. Fixes: QTBUG-30305 Change-Id: I7b985d6317be70867e7727222a4cd44ace7559e6 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquickwindow.cpp95
-rw-r--r--src/quick/items/qquickwindow_p.h2
-rw-r--r--tests/auto/quick/qquickdrag/tst_qquickdrag.cpp8
-rw-r--r--tests/auto/quick/qquickdroparea/data/nested1.qml93
-rw-r--r--tests/auto/quick/qquickdroparea/data/nested2.qml93
-rw-r--r--tests/auto/quick/qquickdroparea/qquickdroparea.pro7
-rw-r--r--tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp88
7 files changed, 338 insertions, 48 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index b83c9159a4..0bbc400d08 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -2828,32 +2828,49 @@ void QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *e
for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem))
QCoreApplication::sendEvent(**grabItem, &leaveEvent);
return;
- } else for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem)) {
+ } else {
QDragMoveEvent *moveEvent = static_cast<QDragMoveEvent *>(event);
- if (deliverDragEvent(grabber, **grabItem, moveEvent)) {
- for (++grabItem; grabItem != grabber->end();) {
- QPointF p = (**grabItem)->mapFromScene(moveEvent->pos());
- if ((**grabItem)->contains(p)) {
- QDragMoveEvent translatedEvent(
- p.toPoint(),
- moveEvent->possibleActions(),
- moveEvent->mimeData(),
- moveEvent->mouseButtons(),
- moveEvent->keyboardModifiers());
- QQuickDropEventEx::copyActions(&translatedEvent, *moveEvent);
- QCoreApplication::sendEvent(**grabItem, &translatedEvent);
- ++grabItem;
- } else {
- QDragLeaveEvent leaveEvent;
- QCoreApplication::sendEvent(**grabItem, &leaveEvent);
- grabItem = grabber->release(grabItem);
- }
+
+ // Used to ensure we don't send DragEnterEvents to current drop targets,
+ // and to detect which current drop targets we have left
+ QVarLengthArray<QQuickItem*, 64> currentGrabItems;
+ for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem))
+ currentGrabItems.append(**grabItem);
+
+ // Look for any other potential drop targets that are higher than the current ones
+ QDragEnterEvent enterEvent(
+ moveEvent->pos(),
+ moveEvent->possibleActions(),
+ moveEvent->mimeData(),
+ moveEvent->mouseButtons(),
+ moveEvent->keyboardModifiers());
+ QQuickDropEventEx::copyActions(&enterEvent, *moveEvent);
+ event->setAccepted(deliverDragEvent(grabber, contentItem, &enterEvent, &currentGrabItems));
+
+ for (grabItem = grabber->begin(); grabItem != grabber->end(); ++grabItem) {
+ int i = currentGrabItems.indexOf(**grabItem);
+ if (i >= 0) {
+ currentGrabItems.remove(i);
+ // Still grabbed: send move event
+ QDragMoveEvent translatedEvent(
+ (**grabItem)->mapFromScene(moveEvent->pos()).toPoint(),
+ moveEvent->possibleActions(),
+ moveEvent->mimeData(),
+ moveEvent->mouseButtons(),
+ moveEvent->keyboardModifiers());
+ QQuickDropEventEx::copyActions(&translatedEvent, *moveEvent);
+ QCoreApplication::sendEvent(**grabItem, &translatedEvent);
+ event->setAccepted(translatedEvent.isAccepted());
+ QQuickDropEventEx::copyActions(moveEvent, translatedEvent);
}
- return;
- } else {
- QDragLeaveEvent leaveEvent;
- QCoreApplication::sendEvent(**grabItem, &leaveEvent);
}
+
+ // Anything left in currentGrabItems is no longer a drop target and should be sent a DragLeaveEvent
+ QDragLeaveEvent leaveEvent;
+ for (QQuickItem *i : currentGrabItems)
+ QCoreApplication::sendEvent(i, &leaveEvent);
+
+ return;
}
}
if (event->type() == QEvent::DragEnter || event->type() == QEvent::DragMove) {
@@ -2869,9 +2886,8 @@ void QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *e
}
}
-bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickItem *item, QDragMoveEvent *event)
+bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickItem *item, QDragMoveEvent *event, QVarLengthArray<QQuickItem*, 64> *currentGrabItems)
{
- bool accepted = false;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
if (!item->isVisible() || !item->isEnabled() || QQuickItemPrivate::get(item)->culled)
return false;
@@ -2890,12 +2906,24 @@ bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte
event->keyboardModifiers());
QQuickDropEventEx::copyActions(&enterEvent, *event);
QList<QQuickItem *> children = itemPrivate->paintOrderChildItems();
+
+ // Check children in front of this item first
for (int ii = children.count() - 1; ii >= 0; --ii) {
- if (deliverDragEvent(grabber, children.at(ii), &enterEvent))
+ if (children.at(ii)->z() < 0)
+ continue;
+ if (deliverDragEvent(grabber, children.at(ii), &enterEvent, currentGrabItems))
return true;
}
if (itemContained) {
+ // If this item is currently grabbed, don't send it another DragEnter,
+ // just grab it again if it's still contained.
+ if (currentGrabItems && currentGrabItems->contains(item)) {
+ grabber->grab(item);
+ grabber->setTarget(item);
+ return true;
+ }
+
if (event->type() == QEvent::DragMove || itemPrivate->flags & QQuickItem::ItemAcceptsDrops) {
QDragMoveEvent translatedEvent(
p.toPoint(),
@@ -2912,15 +2940,24 @@ bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte
if (event->type() == QEvent::DragEnter) {
if (translatedEvent.isAccepted()) {
grabber->grab(item);
- accepted = true;
+ grabber->setTarget(item);
+ return true;
}
} else {
- accepted = true;
+ return true;
}
}
}
- return accepted;
+ // Check children behind this item if this item or any higher children have not accepted
+ for (int ii = children.count() - 1; ii >= 0; --ii) {
+ if (children.at(ii)->z() >= 0)
+ continue;
+ if (deliverDragEvent(grabber, children.at(ii), &enterEvent, currentGrabItems))
+ return true;
+ }
+
+ return false;
}
#endif // quick_draganddrop
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index 7d1767c40e..165859b5f3 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -192,7 +192,7 @@ public:
#if QT_CONFIG(quick_draganddrop)
void deliverDragEvent(QQuickDragGrabber *, QEvent *);
- bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
+ bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *, QVarLengthArray<QQuickItem*, 64> *currentGrabItems = nullptr);
#endif
#if QT_CONFIG(cursor)
void updateCursor(const QPointF &scenePos);
diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
index 9d832066af..ee43e5e06a 100644
--- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
+++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
@@ -598,7 +598,7 @@ void tst_QQuickDrag::move()
QCoreApplication::processEvents();
QCOMPARE(evaluate<QObject *>(item, "Drag.target"), static_cast<QObject *>(&rightTarget));
QCOMPARE(evaluate<QObject *>(item, "dragTarget"), static_cast<QObject *>(&rightTarget));
- QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 0); QCOMPARE(outerTarget.moveEvents, 0);
+ QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 1); QCOMPARE(outerTarget.moveEvents, 0);
QCOMPARE(leftTarget .enterEvents, 0); QCOMPARE(leftTarget .leaveEvents, 0); QCOMPARE(leftTarget .moveEvents, 0);
QCOMPARE(rightTarget.enterEvents, 1); QCOMPARE(rightTarget.leaveEvents, 0); QCOMPARE(rightTarget.moveEvents, 0);
QCOMPARE(rightTarget.position.x(), qreal(5)); QCOMPARE(rightTarget.position.y(), qreal(15));
@@ -620,10 +620,10 @@ void tst_QQuickDrag::move()
QCoreApplication::processEvents();
QCOMPARE(evaluate<QObject *>(item, "Drag.target"), static_cast<QObject *>(&leftTarget));
QCOMPARE(evaluate<QObject *>(item, "dragTarget"), static_cast<QObject *>(&leftTarget));
- QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 0); QCOMPARE(outerTarget.moveEvents, 1);
+ QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 0); QCOMPARE(outerTarget.moveEvents, 0);
QCOMPARE(leftTarget .enterEvents, 0); QCOMPARE(leftTarget .leaveEvents, 0); QCOMPARE(leftTarget .moveEvents, 1);
QCOMPARE(rightTarget.enterEvents, 0); QCOMPARE(rightTarget.leaveEvents, 0); QCOMPARE(rightTarget.moveEvents, 0);
- QCOMPARE(outerTarget.position.x(), qreal(25)); QCOMPARE(outerTarget.position.y(), qreal(40));
+ QCOMPARE(outerTarget.position.x(), qreal(60)); QCOMPARE(outerTarget.position.y(), qreal(50));
QCOMPARE(leftTarget.position.x(), qreal(25)); QCOMPARE(leftTarget.position.y(), qreal(5));
// Move out of all targets.
@@ -632,7 +632,7 @@ void tst_QQuickDrag::move()
QCoreApplication::processEvents();
QCOMPARE(evaluate<QObject *>(item, "Drag.target"), static_cast<QObject *>(nullptr));
QCOMPARE(evaluate<QObject *>(item, "dragTarget"), static_cast<QObject *>(nullptr));
- QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 1); QCOMPARE(outerTarget.moveEvents, 0);
+ QCOMPARE(outerTarget.enterEvents, 0); QCOMPARE(outerTarget.leaveEvents, 0); QCOMPARE(outerTarget.moveEvents, 0);
QCOMPARE(leftTarget .enterEvents, 0); QCOMPARE(leftTarget .leaveEvents, 1); QCOMPARE(leftTarget .moveEvents, 0);
QCOMPARE(rightTarget.enterEvents, 0); QCOMPARE(rightTarget.leaveEvents, 0); QCOMPARE(rightTarget.moveEvents, 0);
diff --git a/tests/auto/quick/qquickdroparea/data/nested1.qml b/tests/auto/quick/qquickdroparea/data/nested1.qml
new file mode 100644
index 0000000000..de6ac70d08
--- /dev/null
+++ b/tests/auto/quick/qquickdroparea/data/nested1.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+Item {
+ width: 200; height: 200
+ property int outerEnterEvents: 0
+ property int outerExitEvents: 0
+ property int innerEnterEvents: 0
+ property int innerExitEvents: 0
+
+ DropArea {
+ objectName: "outerDropArea"
+ x: 75; y: 75
+ width: 100; height: 100
+ Rectangle {
+ anchors.fill: parent
+ color: "green"
+ }
+ onEntered: ++outerEnterEvents
+ onExited: ++outerExitEvents
+
+ DropArea {
+ objectName: "innerDropArea"
+ width: 50; height: 50
+ Rectangle {
+ anchors.fill: parent
+ color: "blue"
+ }
+ onEntered: ++innerEnterEvents
+ onExited: ++innerExitEvents
+ }
+ }
+
+ Rectangle {
+ width: 20; height: 20
+ color: dragArea.pressed ? "red" : "brown"
+ Drag.active: dragArea.drag.active
+ MouseArea {
+ id: dragArea
+ objectName: "dragArea"
+ anchors.fill: parent
+ drag.target: parent
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickdroparea/data/nested2.qml b/tests/auto/quick/qquickdroparea/data/nested2.qml
new file mode 100644
index 0000000000..93630c3779
--- /dev/null
+++ b/tests/auto/quick/qquickdroparea/data/nested2.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+Item {
+ width: 200; height: 200
+ property int outerEnterEvents: 0
+ property int outerExitEvents: 0
+ property int innerEnterEvents: 0
+ property int innerExitEvents: 0
+
+ Rectangle {
+ x: 75; y: 75
+ width: 100; height: 100
+ color: "green"
+ DropArea {
+ objectName: "outerDropArea"
+ anchors.fill: parent
+ onEntered: ++outerEnterEvents
+ onExited: ++outerExitEvents
+ }
+
+ Rectangle {
+ width: 50; height: 50
+ color: "blue"
+ DropArea {
+ objectName: "innerDropArea"
+ anchors.fill: parent
+ onEntered: ++innerEnterEvents
+ onExited: ++innerExitEvents
+ }
+ }
+ }
+
+ Rectangle {
+ width: 20; height: 20
+ color: dragArea.pressed ? "red" : "brown"
+ Drag.active: dragArea.drag.active
+ MouseArea {
+ id: dragArea
+ objectName: "dragArea"
+ anchors.fill: parent
+ drag.target: parent
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickdroparea/qquickdroparea.pro b/tests/auto/quick/qquickdroparea/qquickdroparea.pro
index a34d5ad009..7a8fdef7b9 100644
--- a/tests/auto/quick/qquickdroparea/qquickdroparea.pro
+++ b/tests/auto/quick/qquickdroparea/qquickdroparea.pro
@@ -4,4 +4,11 @@ macx:CONFIG -= app_bundle
SOURCES += tst_qquickdroparea.cpp
+OTHER_FILES += $$files(data/*.qml)
+
+include (../../shared/util.pri)
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
QT += core-private gui-private qml-private quick-private network testlib
diff --git a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp
index cf01cc927b..dcba4c872e 100644
--- a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp
+++ b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp
@@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QtTest/QSignalSpy>
+#include <QtGui/qstylehints.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <QtQml/qqmlcontext.h>
@@ -36,6 +37,8 @@
#include <qpa/qplatformdrag.h>
#include <qpa/qwindowsysteminterface.h>
+#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
template <typename T> static T evaluate(QObject *scope, const QString &expression)
{
@@ -54,13 +57,10 @@ template <> void evaluate<void>(QObject *scope, const QString &expression)
qWarning() << expr.error().toString();
}
-class tst_QQuickDropArea: public QObject
+class tst_QQuickDropArea: public QQmlDataTest
{
Q_OBJECT
private slots:
- void initTestCase();
- void cleanupTestCase();
-
void containsDrag_internal();
void containsDrag_external();
void keys_internal();
@@ -74,21 +74,13 @@ private slots:
void competingDrags();
void simultaneousDrags();
void dropStuff();
+ void nestedDropAreas_data();
+ void nestedDropAreas();
private:
QQmlEngine engine;
};
-void tst_QQuickDropArea::initTestCase()
-{
-
-}
-
-void tst_QQuickDropArea::cleanupTestCase()
-{
-
-}
-
void tst_QQuickDropArea::containsDrag_internal()
{
QQuickWindow window;
@@ -1224,6 +1216,74 @@ void tst_QQuickDropArea::dropStuff()
QCOMPARE(evaluate<QByteArray>(dropArea, "array"), QByteArray("red"));
}
+void tst_QQuickDropArea::nestedDropAreas_data()
+{
+ QTest::addColumn<QString>("qmlFile");
+
+ QTest::newRow("dropRectDropRect") << "nested1.qml";
+ QTest::newRow("rectDropRectDrop") << "nested2.qml";
+}
+
+void tst_QQuickDropArea::nestedDropAreas()
+{
+ QFETCH(QString, qmlFile);
+
+ const int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(QQuickTest::initView(window, testFileUrl(qmlFile.toLatin1().data()), true, &errorMessage), errorMessage.constData());
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject() != nullptr);
+
+ QQuickItem *dragArea = window.rootObject()->findChild<QQuickItem*>("dragArea");
+ QVERIFY(dragArea);
+ QQuickItem *outerDropArea = window.rootObject()->findChild<QQuickItem*>("outerDropArea");
+ QVERIFY(outerDropArea);
+ QQuickItem *innerDropArea = window.rootObject()->findChild<QQuickItem*>("innerDropArea");
+ QVERIFY(innerDropArea);
+
+ QPoint p = QPoint(10,10);
+ QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
+
+ // move the minimum distance to activate drag
+ p += QPoint(dragThreshold + 1, dragThreshold + 1);
+ QTest::mouseMove(&window, p);
+
+ // drag the red rectangle into the inner DropArea
+ p += QPoint(100, 100);
+ QTest::mouseMove(&window, p);
+ QCOMPARE(window.rootObject()->property("outerEnterEvents"), 0);
+ QCOMPARE(window.rootObject()->property("outerExitEvents"), 0);
+ QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1);
+ QCOMPARE(window.rootObject()->property("innerExitEvents"), 0);
+
+ // drag the red rectangle into the outer DropArea
+ p += QPoint(0, 50);
+ QTest::mouseMove(&window, p);
+ QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1);
+ QCOMPARE(window.rootObject()->property("outerExitEvents"), 0);
+ QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1);
+ QCOMPARE(window.rootObject()->property("innerExitEvents"), 1);
+
+ // drag the red rectangle into the inner DropArea
+ p -= QPoint(0, 50);
+ QTest::mouseMove(&window, p);
+ QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1);
+ QCOMPARE(window.rootObject()->property("outerExitEvents"), 1);
+ QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2);
+ QCOMPARE(window.rootObject()->property("innerExitEvents"), 1);
+
+ // drag the red rectangle back out of both
+ p -= QPoint(100, 100);
+ QTest::mouseMove(&window, p);
+ QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1);
+ QCOMPARE(window.rootObject()->property("outerExitEvents"), 1);
+ QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2);
+ QCOMPARE(window.rootObject()->property("innerExitEvents"), 2);
+}
+
QTEST_MAIN(tst_QQuickDropArea)
#include "tst_qquickdroparea.moc"