mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-25 04:27:19 +02:00
[ui] Center pasted nodes in GraphEditor when it does not contain the mouse
When using the Edit > Paste menu, or when pressing Ctrl+V while the Graph Editor has the focus but the mouse is not contained in it, there is no current mouse position in the GraphEditor so the position that is provided to the "pasteNodes" function is the last known mouse position, which is oftentimes on the border of the GraphEditor. This commit automatically sets the mouse's position to the center of the GraphEditor, and "builds" the zone containing the pasted nodes around it.
This commit is contained in:
parent
243c278bcc
commit
021770a424
2 changed files with 36 additions and 8 deletions
|
@ -41,7 +41,6 @@ Item {
|
|||
clip: true
|
||||
|
||||
SystemPalette { id: activePalette }
|
||||
property point pastePosition
|
||||
|
||||
/// Get node delegate for the given node object
|
||||
function nodeDelegate(node)
|
||||
|
@ -89,14 +88,22 @@ Item {
|
|||
/// Paste content of clipboard to graph editor and create new node if valid
|
||||
function pasteNodes()
|
||||
{
|
||||
if (uigraph.hoveredNode != null) {
|
||||
var node = nodeDelegate(uigraph.hoveredNode)
|
||||
root.pastePosition = Qt.point(node.mousePosition.x + node.x, node.mousePosition.y + node.y)
|
||||
var finalPosition = undefined
|
||||
var centerPosition = false
|
||||
if (mouseArea.containsMouse) {
|
||||
if (uigraph.hoveredNode != null) {
|
||||
var node = nodeDelegate(uigraph.hoveredNode)
|
||||
finalPosition = Qt.point(node.mousePosition.x + node.x, node.mousePosition.y + node.y)
|
||||
} else {
|
||||
finalPosition = mapToItem(draggable, mouseArea.mouseX, mouseArea.mouseY)
|
||||
}
|
||||
} else {
|
||||
root.pastePosition = mapToItem(draggable, mouseArea.mouseX, mouseArea.mouseY)
|
||||
finalPosition = getCenterPosition()
|
||||
centerPosition = true
|
||||
}
|
||||
|
||||
var copiedContent = Clipboard.getText()
|
||||
var nodes = uigraph.pasteNodes(copiedContent, root.pastePosition)
|
||||
var nodes = uigraph.pasteNodes(copiedContent, finalPosition, centerPosition)
|
||||
if (nodes.length > 0) {
|
||||
uigraph.clearNodeSelection()
|
||||
uigraph.selectedNode = nodes[0]
|
||||
|
@ -104,6 +111,12 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the coordinates of the point at the center of the GraphEditor
|
||||
function getCenterPosition()
|
||||
{
|
||||
return mapToItem(draggable, mouseArea.width / 2, mouseArea.height / 2)
|
||||
}
|
||||
|
||||
Keys.onPressed: {
|
||||
if (event.key === Qt.Key_F)
|
||||
fit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue