QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: enabled(true), hovered(false), longPress(false),
- moved(false), dragX(true), dragY(true), stealMouse(false), doubleClick(false), preventStealing(false),
+ moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
propagateComposedEvents(false), pressed(0)
#ifndef QT_NO_DRAGANDDROP
, drag(0)
d->pressAndHoldTimer.start(PressAndHoldDelay, this);
setKeepMouseGrab(d->stealMouse);
event->setAccepted(setPressed(event->button(), true));
-
-#ifndef QT_NO_DRAGANDDROP
- if (d->drag) {
- d->dragX = drag()->axis() & QQuickDrag::XAxis;
- d->dragY = drag()->axis() & QQuickDrag::YAxis;
- }
-#endif
}
}
QPointF dragPos = d->drag->target()->pos();
- if (d->dragX && d->drag->active()) {
+ bool dragX = drag()->axis() & QQuickDrag::XAxis;
+ bool dragY = drag()->axis() & QQuickDrag::YAxis;
+
+ if (dragX && d->drag->active()) {
qreal x = (curLocalPos.x() - startLocalPos.x()) + startPos.x();
if (x < drag()->xmin())
x = drag()->xmin();
x = drag()->xmax();
dragPos.setX(x);
}
- if (d->dragY && d->drag->active()) {
+ if (dragY && d->drag->active()) {
qreal y = (curLocalPos.y() - startLocalPos.y()) + startPos.y();
if (y < drag()->ymin())
y = drag()->ymin();
if (!keepMouseGrab()) {
bool xDragged = QQuickCanvasPrivate::dragOverThreshold(dx, Qt::XAxis, event);
bool yDragged = QQuickCanvasPrivate::dragOverThreshold(dy, Qt::YAxis, event);
- if ((!d->dragY && !yDragged && d->dragX && xDragged)
- || (!d->dragX && !xDragged && d->dragY && yDragged)
- || (d->dragX && d->dragY && (xDragged || yDragged))) {
+ if ((!dragY && !yDragged && dragX && xDragged)
+ || (!dragX && !xDragged && dragY && yDragged)
+ || (dragX && dragY && (xDragged || yDragged))) {
setKeepMouseGrab(true);
d->stealMouse = true;
}
void transformedMouseArea();
void pressedMultipleButtons_data();
void pressedMultipleButtons();
+ void changeAxis();
private:
void acceptedButton_data();
delete canvas;
}
+void tst_QQuickMouseArea::changeAxis()
+{
+ QQuickView *canvas = createView();
+
+ canvas->setSource(testFileUrl("changeAxis.qml"));
+ canvas->show();
+ canvas->requestActivateWindow();
+ QTRY_VERIFY(canvas->rootObject() != 0);
+
+ QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
+ QQuickDrag *drag = mouseRegion->drag();
+ QVERIFY(mouseRegion != 0);
+ QVERIFY(drag != 0);
+
+ mouseRegion->setAcceptedButtons(Qt::LeftButton);
+
+ // target
+ QQuickItem *blackRect = canvas->rootObject()->findChild<QQuickItem*>("blackrect");
+ QVERIFY(blackRect != 0);
+ QVERIFY(blackRect == drag->target());
+
+ QVERIFY(!drag->active());
+
+ // Start a diagonal drag
+ QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100, 100));
+
+ QVERIFY(!drag->active());
+ QCOMPARE(blackRect->x(), 50.0);
+ QCOMPARE(blackRect->y(), 50.0);
+
+ QTest::mouseMove(canvas, QPoint(111, 111));
+ QTest::qWait(50);
+ QTest::mouseMove(canvas, QPoint(122, 122));
+
+ QTRY_VERIFY(drag->active());
+ QCOMPARE(blackRect->x(), 72.0);
+ QCOMPARE(blackRect->y(), 72.0);
+ QCOMPARE(drag->axis(), QQuickDrag::XandYAxis);
+
+ /* When blackRect.x becomes bigger than 75, the drag axis is changed to
+ * Drag.YAxis by the QML code. Verify that this happens, and that the drag
+ * movement is effectively constrained to the Y axis. */
+ QTest::mouseMove(canvas, QPoint(133, 133));
+
+ QTRY_COMPARE(blackRect->x(), 83.0);
+ QTRY_COMPARE(blackRect->y(), 83.0);
+ QTRY_COMPARE(drag->axis(), QQuickDrag::YAxis);
+
+ QTest::mouseMove(canvas, QPoint(144, 144));
+
+ QTRY_COMPARE(blackRect->y(), 94.0);
+ QCOMPARE(blackRect->x(), 83.0);
+
+ QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(144, 144));
+
+ QTRY_VERIFY(!drag->active());
+ QCOMPARE(blackRect->x(), 83.0);
+ QCOMPARE(blackRect->y(), 94.0);
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"