diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-03-18 11:58:33 -0400 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-03-18 11:58:33 -0400 |
commit | 8b8ea9395bdda4bb1404497ff654b82098084822 (patch) | |
tree | c92d720990686acda5eeba18b028fe1e4b656a25 /src/gui | |
parent | 3cea1514203a451c0a8806d276807863b463a78f (diff) |
finally got bboxes working...i think
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/tikzscene.cpp | 62 | ||||
-rw-r--r-- | src/gui/tikzscene.h | 3 | ||||
-rw-r--r-- | src/gui/undocommands.cpp | 7 |
3 files changed, 49 insertions, 23 deletions
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 2ee3c50..59faa65 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -456,13 +456,15 @@ void TikzScene::pasteFromClipboard() // make sure names in the new subgraph are fresh g->renameApart(graph()); - // shift g to the right until there is some free space - QPointF p0 = toScreen(g->nodes()[0]->point()); - QPointF p = p0; - while (!items(p).isEmpty()) p.setX(p.x()+GLOBAL_SCALEF); - QPointF shift(roundf((p.x() - p0.x())/GLOBAL_SCALEF), 0.0f); - foreach (Node *n, g->nodes()) { - n->setPoint(n->point() + shift); + QRectF srcRect = g->realBbox(); + QRectF tgtRect = graph()->realBbox(); + QPointF shift(tgtRect.right() - srcRect.left(), 0.0f); + + // shift g to the right until it is in free space + if (shift.x() > 0) { + foreach (Node *n, g->nodes()) { + n->setPoint(n->point() + shift); + } } PasteCommand *cmd = new PasteCommand(this, g); @@ -507,6 +509,26 @@ void TikzScene::reloadStyles() } } +void TikzScene::refreshSceneBounds() +{ + if (!views().empty()) { + QGraphicsView *v = views().first(); + QRectF viewB = v->mapToScene(v->viewport()->rect()).boundingRect(); + //QPointF tl = v->mapToScene(viewB.topLeft()); + //viewB.setTopLeft(tl); + + QRectF bounds = viewB.united(rectToScreen(graph()->realBbox().adjusted(-1.0f, -1.0f, 1.0f, 1.0f))); + qDebug() << viewB; + + if (bounds != sceneRect()) { + QPointF c = viewB.center(); + setSceneRect(bounds); + v->centerOn(c); + } + } + //setBounds(graphB); +} + void TikzScene::refreshAdjacentEdges(QList<Node*> nodes) { if (nodes.empty()) return; @@ -518,19 +540,19 @@ void TikzScene::refreshAdjacentEdges(QList<Node*> nodes) } } -void TikzScene::setBounds(QRectF bounds) -{ - if (bounds != sceneRect()) { - if (!views().empty()) { - QGraphicsView *v = views().first(); - QPointF c = v->mapToScene(v->viewport()->rect().center()); - setSceneRect(bounds); - v->centerOn(c); - } else { - setSceneRect(bounds); - } - } -} +//void TikzScene::setBounds(QRectF bounds) +//{ +// if (bounds != sceneRect()) { +// if (!views().empty()) { +// QGraphicsView *v = views().first(); +// QPointF c = v->mapToScene(v->viewport()->rect().center()); +// setSceneRect(bounds); +// v->centerOn(c); +// } else { +// setSceneRect(bounds); +// } +// } +//} QMap<Node*,NodeItem *> &TikzScene::nodeItems() { diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 5d3eec2..b551abd 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -30,11 +30,12 @@ public: QMap<Node*,NodeItem*> &nodeItems(); QMap<Edge*,EdgeItem*> &edgeItems(); void refreshAdjacentEdges(QList<Node*> nodes); - void setBounds(QRectF bounds); +// void setBounds(QRectF bounds); TikzDocument *tikzDocument() const; void setTikzDocument(TikzDocument *tikzDocument); void reloadStyles(); + void refreshSceneBounds(); void applyActiveStyleToNodes(); void deleteSelectedItems(); void copyToClipboard(); diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 0ebfd21..c9ca041 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -11,12 +11,14 @@ GraphUpdateCommand::GraphUpdateCommand(TikzScene *scene, QUndoCommand *parent) : void GraphUpdateCommand::undo() { _scene->tikzDocument()->refreshTikz(); + _scene->refreshSceneBounds(); _scene->invalidate(); } void GraphUpdateCommand::redo() { _scene->tikzDocument()->refreshTikz(); + _scene->refreshSceneBounds(); _scene->invalidate(); } @@ -174,7 +176,7 @@ void AddNodeCommand::undo() _scene->graph()->removeNode(_node); - _scene->setBounds(_oldBounds); + //_scene->setBounds(_oldBounds); GraphUpdateCommand::undo(); } @@ -187,7 +189,8 @@ void AddNodeCommand::redo() _scene->nodeItems().insert(_node, ni); _scene->addItem(ni); - _scene->setBounds(_newBounds); + //_scene->setBounds(_newBounds); + GraphUpdateCommand::redo(); } |