if (delay == undefined)
delay = -1
+ // Divide dx and dy to have intermediate mouseMove while dragging
+ // Fractions of dx/dy need be superior to the dragThreshold
+ // to make the drag works though
+ var ddx = Math.round(dx/3)
+ if (ddx < (util.dragThreshold + 1))
+ ddx = 0
+ var ddy = Math.round(dy/3)
+ if (ddy < (util.dragThreshold + 1))
+ ddy = 0
+
mousePress(item, x, y, button, modifiers, delay)
//trigger dragging
mouseMove(item, x + util.dragThreshold + 1, y + util.dragThreshold + 1, delay, button)
+ if (ddx > 0 || ddy > 0) {
+ mouseMove(item, x + ddx, y + ddy, delay, button)
+ mouseMove(item, x + 2*ddx, y + 2*ddy, delay, button)
+ }
mouseMove(item, x + dx, y + dy, delay, button)
mouseRelease(item, x + dx, y + dy, button, modifiers, delay)
}
id: util
}
+ SignalSpy {
+ id: spyX
+ target: container2
+ signalName: "posXChanged"
+ }
+ SignalSpy {
+ id: spyY
+ target: container2
+ signalName: "posYChanged"
+ }
+
Rectangle {
id:container
width:20
}
}
+ Rectangle {
+ id: container2
+ x: 25
+ y: 25
+ width:100
+ height:100
+ color: "red"
+ property bool updatePositionWhileDragging: false
+ property var posX: 0
+ property var posY: 0
+
+ function reset() {
+ fakeHandle.x = 0
+ fakeHandle.y = 0
+ spyX.clear()
+ spyY.clear()
+ }
+
+ Binding {
+ when: container2.updatePositionWhileDragging
+ target: container2
+ property: "posX"
+ value: fakeHandle.x
+ }
+
+ Binding {
+ when: container2.updatePositionWhileDragging
+ target: container2
+ property: "posY"
+ value: fakeHandle.y
+ }
+
+ Item { id: fakeHandle }
+
+ MouseArea {
+ anchors.fill : container2
+ drag.maximumX: 180
+ drag.maximumY: 180
+ drag.minimumX: 0
+ drag.minimumY: 0
+ drag.target: fakeHandle
+
+ onReleased: if (!container2.updatePositionWhileDragging) {
+ container2.posX = mouse.x;
+ container2.posY = mouse.y
+ }
+ }
+ }
+
TestCase {
name:"mouserelease"
when:windowShown
compare(container.x, 20 - util.dragThreshold - 1);
compare(container.y, 30 - util.dragThreshold - 1);
}
+
+ function test_doSomethingWhileDragging() {
+ container2.updatePositionWhileDragging = false
+ // dx and dy are superior to 3 times util.dragThreshold.
+ // but here the dragging does not update posX and posY
+ // posX and posY are only updated on mouseRelease
+ container2.reset()
+ mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 10*util.dragThreshold);
+ compare(spyX.count, 1)
+ compare(spyY.count, 1)
+
+ container2.updatePositionWhileDragging = true
+ // dx and dy are superior to 3 times util.dragThreshold.
+ // 3 intermediate mouseMove when dragging
+ container2.reset()
+ mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 10*util.dragThreshold);
+ compare(spyX.count, 3)
+ compare(spyY.count, 3)
+
+ // dx and dy are inferior to 3 times util.dragThreshold.
+ // No intermediate mouseMove when dragging, only one mouseMove
+ container2.reset()
+ mouseDrag(container2, container2.x + 10, container2.y + 10, 2*util.dragThreshold, 2*util.dragThreshold);
+ compare(spyX.count, 1)
+ compare(spyY.count, 1)
+
+ // dx is superior to 3 times util.dragThreshold.
+ // 3 intermediate mouseMove when dragging on x axis
+ // no move on the y axis
+ container2.reset()
+ mouseDrag(container2, container2.x + 10, container2.y + 10, 10*util.dragThreshold, 0);
+ compare(spyX.count, 3)
+ compare(spyY.count, 0)
+
+ // dy is inferior to 3 times util.dragThreshold.
+ // No intermediate mouseMove when dragging, only one mouseMove on y axis
+ // no move on the x axis
+ container2.reset()
+ mouseDrag(container2, container2.x + 10, container2.y + 10, 0, 2*util.dragThreshold);
+ compare(spyX.count, 0)
+ compare(spyY.count, 1)
+ }
}
}