[ui] Paste a node on the mouse's position

When creating a node with a "paste" operation, place the node
on the mouse's position in the graph instead of default position (0,0).

If the mouse is placed on an existing node, the pasted node will be
placed on the mouse's position plus an offset so that the pasted node
does not directly overlap with the existing node.
This commit is contained in:
Candice Bentéjac 2022-08-19 11:02:42 +02:00
parent ddda62a652
commit 5b65866e49
4 changed files with 14 additions and 8 deletions

View file

@ -199,14 +199,15 @@ class PasteNodeCommand(GraphCommand):
"""
Handle node pasting in a Graph.
"""
def __init__(self, graph, nodeType, parent=None, **kwargs):
def __init__(self, graph, nodeType, position=None, parent=None, **kwargs):
super(PasteNodeCommand, self).__init__(graph, parent)
self.nodeType = nodeType
self.position = position
self.nodeName = None
self.kwargs = kwargs
def redoImpl(self):
node = self.graph.pasteNode(self.nodeType, **self.kwargs)
node = self.graph.pasteNode(self.nodeType, self.position, **self.kwargs)
self.nodeName = node.name
self.setText("Paste Node {}".format(self.nodeName))
return node