Skip to content

Commit

Permalink
[GraphEditor] AttributePin: Do not start dragging edge on pressed
Browse files Browse the repository at this point in the history
Prior to this commit, the edge that was being dragged to be connected
appeared as soon as the `pressed` signal was emitted by the mouse. Now
that the user can actually click (press & release) without dragging the
mouse to expand or collapse groups, we want to be able to distinguish
cases where the user presses the mouse to click (to expand/collapse
groups) from those where the user presses the mouse to drag it (to
connect edges).

Instead of triggering the drag as soon as the `pressed` signal is
emitted, we wait to see if the mouse moves significantly enough to
indicate the will to drag; an arbitrary limit of 10 pixels along the
X- or Y-axis is used to determine that the user means to drag the mouse.
  • Loading branch information
cbentejac committed Dec 30, 2024
1 parent f193ed6 commit e040b81
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions meshroom/ui/qml/GraphEditor/AttributePin.qml
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,31 @@ RowLayout {
anchors.margins: inputDropArea.anchors.margins
anchors.leftMargin: inputDropArea.anchors.leftMargin
anchors.rightMargin: inputDropArea.anchors.rightMargin

property bool dragTriggered: false // An edge is being dragged from the output connector
property bool isPressed: false // The mouse has been pressed but not yet released
property double initialX: 0.0
property double initialY: 0.0

onPressed: function(mouse) {
root.pressed(mouse)
isPressed = true
initialX = mouse.x
initialY = mouse.y
}
onReleased: {
onReleased: function(mouse) {
inputDragTarget.Drag.drop()
isPressed = false
dragTriggered = false
}
onClicked: root.clicked()
onPositionChanged: function(mouse) {
// If there's been a significant (10px along the X- or Y- axis) while the mouse is being pressed,
// then we can consider being in the dragging state
if (isPressed && (Math.abs(mouse.x - initialX) >= 10.0 || Math.abs(mouse.y - initialY) >= 10.0)) {
dragTriggered = true
}
}
hoverEnabled: root.visible
}

Expand Down Expand Up @@ -371,9 +389,30 @@ RowLayout {
anchors.leftMargin: outputDropArea.anchors.leftMargin
anchors.rightMargin: outputDropArea.anchors.rightMargin

onPressed: function(mouse) { root.pressed(mouse) }
onReleased: outputDragTarget.Drag.drop()
property bool dragTriggered: false // An edge is being dragged from the output connector
property bool isPressed: false // The mouse has been pressed but not yet released
property double initialX: 0.0
property double initialY: 0.0

onPressed: function(mouse) {
root.pressed(mouse)
isPressed = true
initialX = mouse.x
initialY = mouse.y
}
onReleased: function(mouse) {
outputDragTarget.Drag.drop()
isPressed = false
dragTriggered = false
}
onClicked: root.clicked()
onPositionChanged: function(mouse) {
// If there's been a significant (10px along the X- or Y- axis) while the mouse is being pressed,
// then we can consider being in the dragging state
if (isPressed && (Math.abs(mouse.x - initialX) >= 10.0 || Math.abs(mouse.y - initialY) >= 10.0)) {
dragTriggered = true
}
}

hoverEnabled: root.visible
}
Expand All @@ -390,7 +429,7 @@ RowLayout {
}
}

state: (inputConnectMA.pressed) ? "DraggingInput" : outputConnectMA.pressed ? "DraggingOutput" : ""
state: inputConnectMA.dragTriggered ? "DraggingInput" : outputConnectMA.dragTriggered ? "DraggingOutput" : ""

states: [
State {
Expand Down

0 comments on commit e040b81

Please sign in to comment.