[ui] GraphEditor: improve Edge UI

* increase EdgeMouseArea thickness for easier picking
* EdgeMouseArea: propagate modifiers on pressed
* increase edge visual thickness when hovered
* add edge contextual menu on right click
* Alt+RighClick shortcut to delete an edge
This commit is contained in:
Yann Lanthony 2018-07-27 16:33:12 +02:00
parent 41ea5a5423
commit 53be806019
3 changed files with 26 additions and 4 deletions

View file

@ -12,10 +12,12 @@ class MouseEvent(QObject):
self._x = evt.x()
self._y = evt.y()
self._button = evt.button()
self._modifiers = evt.modifiers()
x = Property(float, lambda self: self._x, constant=True)
y = Property(float, lambda self: self._y, constant=True)
button = Property(Qt.MouseButton, lambda self: self._button, constant=True)
modifiers = Property(int, lambda self: self._modifiers, constant=True)
class EdgeMouseArea(QQuickItem):

View file

@ -60,7 +60,7 @@ Shape {
anchors.fill: parent
curveScale: cubic.curveScale
acceptedButtons: Qt.LeftButton | Qt.RightButton
thickness: root.thickness + 2
thickness: root.thickness + 4
onPressed: root.pressed(arguments[0]) // can't get named args, use arguments array
onReleased: root.released(arguments[0])
}

View file

@ -182,6 +182,15 @@ Item {
width: 1000
height: 1000
Menu {
id: edgeMenu
property var currentEdge: null
MenuItem {
text: "Remove"
enabled: !root.readOnly
onTriggered: uigraph.removeEdge(edgeMenu.currentEdge)
}
}
// Edges
Repeater {
@ -196,16 +205,27 @@ Item {
property var srcAnchor: src.nodeItem.mapFromItem(src, src.edgeAnchorPos.x, src.edgeAnchorPos.y)
property var dstAnchor: dst.nodeItem.mapFromItem(dst, dst.edgeAnchorPos.x, dst.edgeAnchorPos.y)
property bool inFocus: containsMouse || (edgeMenu.opened && edgeMenu.currentEdge == edge)
edge: object
color: containsMouse && !readOnly ? activePalette.highlight : activePalette.text
color: inFocus ? activePalette.highlight : activePalette.text
thickness: inFocus ? 2 : 1
opacity: 0.7
point1x: src.nodeItem.x + srcAnchor.x
point1y: src.nodeItem.y + srcAnchor.y
point2x: dst.nodeItem.x + dstAnchor.x
point2y: dst.nodeItem.y + dstAnchor.y
onPressed: {
if(!root.readOnly && event.button == Qt.RightButton)
uigraph.removeEdge(edge)
if(event.button == Qt.RightButton)
{
if(!root.readOnly && event.modifiers & Qt.AltModifier) {
uigraph.removeEdge(edge)
}
else {
edgeMenu.currentEdge = edge
edgeMenu.popup()
}
}
}
}
}