From c2570ca0fb7858f968c55e3dcd32a76b10658c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Fri, 2 Dec 2022 18:13:17 +0100 Subject: [PATCH] [ui] GraphEditor: Import pipeline on the mouse's position with the node menu If a pipeline is imported with the node menu instead of the "Import Project" action from the File menu, the top-left "corner" of the graph should be placed on the mouse's position. The position of pipelines imported with the "Import Project" menu remains unchanged: they are automatically placed below the lowest node in the current graph. --- meshroom/ui/commands.py | 8 ++++++-- meshroom/ui/graph.py | 7 +++++-- meshroom/ui/qml/GraphEditor/GraphEditor.qml | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/meshroom/ui/commands.py b/meshroom/ui/commands.py index a5db90ae..20882613 100755 --- a/meshroom/ui/commands.py +++ b/meshroom/ui/commands.py @@ -221,10 +221,11 @@ class ImportProjectCommand(GraphCommand): """ Handle the import of a project into a Graph. """ - def __init__(self, graph, filepath=None, yOffset=0, parent=None): + def __init__(self, graph, filepath=None, position=None, yOffset=0, parent=None): super(ImportProjectCommand, self).__init__(graph, parent) self.filepath = filepath self.importedNames = [] + self.position = position self.yOffset = yOffset def redoImpl(self): @@ -239,7 +240,10 @@ class ImportProjectCommand(GraphCommand): for node in importedNodes: self.importedNames.append(node.name) - self.graph.node(node.name).position = Position(node.x, node.y + lowestY + self.yOffset) + if self.position is not None: + self.graph.node(node.name).position = Position(node.x + self.position.x, node.y + self.position.y) + else: + self.graph.node(node.name).position = Position(node.x, node.y + lowestY + self.yOffset) return status diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 0abf173b..e9769bd4 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -354,7 +354,8 @@ class UIGraph(QObject): return status @Slot(QUrl, result=bool) - def importProject(self, filepath): + @Slot(QUrl, QPoint, result=bool) + def importProject(self, filepath, position=None): if isinstance(filepath, (QUrl)): # depending how the QUrl has been initialized, # toLocalFile() may return the local path or an empty string @@ -363,8 +364,10 @@ class UIGraph(QObject): localFile = filepath.toString() else: localFile = filepath + if isinstance(position, QPoint): + position = Position(position.x(), position.y()) yOffset = self.layout.gridSpacing + self.layout.nodeHeight - return self.push(commands.ImportProjectCommand(self._graph, localFile, yOffset=yOffset)) + return self.push(commands.ImportProjectCommand(self._graph, localFile, position=position, yOffset=yOffset)) @Slot(QUrl) def saveAs(self, url): diff --git a/meshroom/ui/qml/GraphEditor/GraphEditor.qml b/meshroom/ui/qml/GraphEditor/GraphEditor.qml index 6f4b6b68..28265a86 100755 --- a/meshroom/ui/qml/GraphEditor/GraphEditor.qml +++ b/meshroom/ui/qml/GraphEditor/GraphEditor.qml @@ -240,7 +240,7 @@ Item { if (pipelineNames.includes(pipeline)) { var url = Filepath.stringToUrl(pipelinePaths[pipelineNames.indexOf(pipeline)]) - uigraph.importProject(url) + uigraph.importProject(url, spawnPosition) return true } return false