nodeeditor icon indicating copy to clipboard operation
nodeeditor copied to clipboard

Issues with Geometry

Open ypnos opened this issue 8 years ago • 1 comments

I don't fully understand what is going on with the scene geometry. For example, if (in the flow view) I want to place a node's center under the mouse cursor:

auto pos = this->mapToScene(event->pos());
auto shift = _scene->getNodeSize(node) / 2.f;
pos = {pos.x() - shift.width(), pos.y() - shift.height()};
_scene->setNodePosition(node, pos);

This works correctly. However, with this code, nodes are off:

auto pos = this->mapToScene(event->pos());
auto shift = node.nodeGraphicsObject().boundingRect().size() / 2.f; // wrong?
pos = {pos.x() - shift.width(), pos.y() - shift.height()};
_scene->setNodePosition(node, pos);

Similarly, if I do something like this:

fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);

I would expect all nodes to fit in the view nicely. Instead, the zoom is too strong and also the view is somewhat displaced. Why does the QGraphicsScene get the bounding rectangle wrong?

ypnos avatar Aug 28 '17 17:08 ypnos

The fitInView bug might be related to this pull request I made a while back to fix an issue with the scene locking up. The fix for that was to set the scene rectangle according to the mouse movement .

setSceneRect(sceneRect().translated(difference.x(), difference.y()));

I also need a way to fit the entire node graph in view but am facing the same issue as you where the items are displaced by a certain amount. The problem gets worse when you're loading different node graphs in the same scene and happen to drag the scene in between. For some reason setting the scene rect seems to have an effect on the items bounding rect. Not sure why.

kPanesar avatar Sep 05 '17 19:09 kPanesar