[ui] Ensure the edge connecting two nodes is following the mouse

Moving the mouse rapidly when starting to connect two nodes'
attributes could lead to an unwanted offset between the tip of
the edge and the mouse's position; it forced the user to move
the mouse further than the attribute pin they wanted to connect
to in order to actually be able to connect to it.
This commit is contained in:
Candice Bentéjac 2022-07-19 10:49:52 +02:00
parent 8eaef0b367
commit 47a99963fb

View file

@ -131,14 +131,16 @@ RowLayout {
height: 4
Drag.keys: [inputDragTarget.objectName]
Drag.active: inputConnectMA.drag.active
Drag.hotSpot.x: width*0.5
Drag.hotSpot.y: height*0.5
Drag.hotSpot.x: width * 0.5
Drag.hotSpot.y: height * 0.5
}
MouseArea {
id: inputConnectMA
drag.target: attribute.isReadOnly ? undefined : inputDragTarget
drag.threshold: 0
// Move the edge's tip straight to the the current mouse position instead of waiting after the drag operation has started
drag.smoothed: false
enabled: !root.readOnly
anchors.fill: parent
// use the same negative margins as DropArea to ease pin selection
@ -281,6 +283,8 @@ RowLayout {
id: outputConnectMA
drag.target: outputDragTarget
drag.threshold: 0
// Move the edge's tip straight to the the current mouse position instead of waiting after the drag operation has started
drag.smoothed: false
anchors.fill: parent
// use the same negative margins as DropArea to ease pin selection
anchors.margins: outputDropArea.anchors.margins
@ -346,6 +350,7 @@ RowLayout {
}
StateChangeScript {
script: {
// Add the right offset if the initial click is not exactly at the center of the connection circle.
var pos = inputDragTarget.mapFromItem(inputConnectMA, inputConnectMA.mouseX, inputConnectMA.mouseY);
inputDragTarget.x = pos.x - inputDragTarget.width/2;
inputDragTarget.y = pos.y - inputDragTarget.height/2;