Skip to content

Commit

Permalink
fix several NodeGraph issues
Browse files Browse the repository at this point in the history
- when using the right-click menu, use the click position to paste, rather than the visible area center (more control)
- fixes #627
- pasting nodes from the menu was also affected
- fix behavior of "f" key (menu "Center on All Nodes") to always work (use moveRootInternal before centerOn to avoid negative values)
- this fixes *some* Navigator issues, but not all (see #491)
  • Loading branch information
devernay committed Jun 4, 2021
1 parent 022ac52 commit dd33485
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
7 changes: 6 additions & 1 deletion Engine/EffectInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,12 @@ EffectInstance::Implementation::tiledRenderingFunctor(const RectToRender & rectT
#endif
EffectTLSDataPtr tls = tlsData->getOrCreateTLSData();

assert( !rectToRender.rect.isNull() );
if ( rectToRender.rect.isNull() ) {
// should never happen, but crashes when loading
// https://github.com/NatronGitHub/Natron/files/4630686/maskissue.log
//assert(false);
return eRenderingFunctorRetOK;
}

/*
* renderMappedRectToRender is in the mapped mipmap level, i.e the expected mipmap level of the render action of the plug-in
Expand Down
1 change: 0 additions & 1 deletion Gui/NodeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ NodeGraph::NodeGraph(Gui* gui,
_imp->_bR->setPos( _imp->_bR->mapFromScene( QPointF(NATRON_SCENE_MAX, NATRON_SCENE_MIN) ) );
_imp->_bL->setPos( _imp->_bL->mapFromScene( QPointF(NATRON_SCENE_MIN, NATRON_SCENE_MIN) ) );
centerOn(0, 0);
setSceneRect(NATRON_SCENE_MIN, NATRON_SCENE_MIN, NATRON_SCENE_MAX, NATRON_SCENE_MAX);

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Expand Down
1 change: 0 additions & 1 deletion Gui/NodeGraph30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ NodeGraph::wheelEventInternal(bool ctrlDown,
_imp->_accumDelta += delta;
if (std::abs(_imp->_accumDelta) > 60) {
scaleFactor = pow( NATRON_WHEEL_ZOOM_PER_DELTA, _imp->_accumDelta );
// setSceneRect(NATRON_SCENE_MIN,NATRON_SCENE_MIN,NATRON_SCENE_MAX,NATRON_SCENE_MAX);
scale(scaleFactor, scaleFactor);
_imp->_accumDelta = 0;
}
Expand Down
15 changes: 9 additions & 6 deletions Gui/NodeGraph35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,17 @@ NodeGraph::showMenu(const QPoint & pos)
if (ret == findAction) {
popFindDialog();
} else if (ret == duplicateAction) {
QRectF rect = visibleSceneRect();
duplicateSelectedNodes( rect.center() );
// Duplicate at mouse click position:
QPointF scenePos = mapToScene( mapFromGlobal(pos) );
cloneSelectedNodes(scenePos);
} else if (ret == cloneAction) {
QRectF rect = visibleSceneRect();
cloneSelectedNodes( rect.center() );
// Clone at mouse click position:
QPointF scenePos = mapToScene( mapFromGlobal(pos) );
cloneSelectedNodes(scenePos);
} else if (ret == pasteAction) {
QRectF rect = visibleSceneRect();
pasteNodeClipBoards( rect.center() );
// Paste at mouse click position:
QPointF scenePos = mapToScene( mapFromGlobal(pos) );
cloneSelectedNodes(scenePos);
}
} // NodeGraph::showMenu

Expand Down
15 changes: 9 additions & 6 deletions Gui/NodeGraph40.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ NodeGraph::pasteNodeClipBoards(const QPointF& pos)
return false;
}

_imp->pasteNodesInternal(cb, pos, true, &newNodes);
_imp->pasteNodesInternal(cb, _imp->_root->mapFromScene(pos), true, &newNodes);

return true;
}

bool
NodeGraph::pasteNodeClipBoards()
{
QPointF position = _imp->_root->mapFromScene( mapToScene( mapFromGlobal( QCursor::pos() ) ) );
QPointF position = mapToScene( mapFromGlobal( QCursor::pos() ) );

return pasteNodeClipBoards(position);
}
Expand All @@ -215,13 +215,13 @@ NodeGraph::duplicateSelectedNodes(const QPointF& pos)
NodeClipBoard tmpClipboard;
_imp->copyNodesInternal(_imp->_selection, tmpClipboard);
std::list<std::pair<std::string, NodeGuiPtr> > newNodes;
_imp->pasteNodesInternal(tmpClipboard, pos, true, &newNodes);
_imp->pasteNodesInternal(tmpClipboard, _imp->_root->mapFromScene(pos), true, &newNodes);
}

void
NodeGraph::duplicateSelectedNodes()
{
QPointF scenePos = _imp->_root->mapFromScene( mapToScene( mapFromGlobal( QCursor::pos() ) ) );
QPointF scenePos = mapToScene( mapFromGlobal( QCursor::pos() ) );

duplicateSelectedNodes(scenePos);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ NodeGraph::cloneSelectedNodes(const QPointF& scenePos)
void
NodeGraph::cloneSelectedNodes()
{
QPointF scenePos = _imp->_root->mapFromScene( mapToScene( mapFromGlobal( QCursor::pos() ) ) );
QPointF scenePos = mapToScene( mapFromGlobal( QCursor::pos() ) );

cloneSelectedNodes(scenePos);
} // cloneSelectedNodes
Expand Down Expand Up @@ -457,7 +457,10 @@ NodeGraph::centerOnAllNodes()
}
}
}
QRectF bbox( xmin, ymin, (xmax - xmin), (ymax - ymin) );
// Move the scene so that topleft of the viewing area is at 0,0, and avoid issues
// when topleft has negative coords.
moveRootInternal(-xmin, -ymin);
QRectF bbox( 0, 0, (xmax - xmin), (ymax - ymin) );
fitInView(bbox, Qt::KeepAspectRatio);

double currentZoomFactor = transform().mapRect( QRectF(0, 0, 1, 1) ).width();
Expand Down
6 changes: 5 additions & 1 deletion Gui/NodeGraphUndoRedo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ AddMultipleNodesCommand::undo()
for (std::list<ViewerInstance* >::iterator it = viewersToRefresh.begin(); it != viewersToRefresh.end(); ++it) {
(*it)->renderCurrentFrame(true);
}
_graph->updateNavigator();
}

void
Expand Down Expand Up @@ -212,6 +213,7 @@ AddMultipleNodesCommand::redo()
}

_firstRedoCalled = true;
_graph->updateNavigator();
}

RemoveMultipleNodesCommand::RemoveMultipleNodesCommand(NodeGraph* graph,
Expand Down Expand Up @@ -246,6 +248,7 @@ RemoveMultipleNodesCommand::RemoveMultipleNodesCommand(NodeGraph* graph,
}
_nodes.push_back(n);
}
setText( tr("Remove node(s)") );
}

RemoveMultipleNodesCommand::~RemoveMultipleNodesCommand()
Expand All @@ -258,7 +261,6 @@ RemoveMultipleNodesCommand::~RemoveMultipleNodesCommand()
}
}
}
setText( tr("Remove node(s)") );
}

void
Expand Down Expand Up @@ -310,6 +312,7 @@ RemoveMultipleNodesCommand::undo()

_isRedone = false;
_graph->scene()->update();
_graph->updateNavigator();
} // RemoveMultipleNodesCommand::undo

void
Expand Down Expand Up @@ -402,6 +405,7 @@ RemoveMultipleNodesCommand::redo()
_graph->updateNavigator();

_graph->scene()->update();
_graph->updateNavigator();
} // redo

ConnectCommand::ConnectCommand(NodeGraph* graph,
Expand Down

0 comments on commit dd33485

Please sign in to comment.