diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2019-01-10 18:12:48 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2019-01-10 18:12:48 +0100 |
commit | 0002340da590611f635775d0555c66c7f22db09c (patch) | |
tree | e1671161b170f73afc5a99cacb5b08e3633c3d3a /src/gui/tikzscene.cpp | |
parent | 86e379ef12ad08dd9554b1cc288ff50382dd788f (diff) |
infinite canvas (closes #20)
Diffstat (limited to 'src/gui/tikzscene.cpp')
-rw-r--r-- | src/gui/tikzscene.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 31d5bf6..7b090d8 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -41,7 +41,8 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, _rubberBandItem = new QGraphicsRectItem(); _enabled = true; //setSceneRect(-310,-230,620,450); - setSceneRect(-1000,-1000,2000,2000); + //setSceneRect(-2000,-1500,4000,3000); + refreshSceneBounds(); QPen pen; pen.setColor(QColor::fromRgbF(0.5, 0.0, 0.5)); @@ -106,6 +107,7 @@ void TikzScene::graphReplaced() } refreshZIndices(); + refreshSceneBounds(); } void TikzScene::extendSelectionUp() @@ -870,6 +872,28 @@ void TikzScene::reloadStyles() } } +void TikzScene::refreshSceneBounds() { + qreal maxX = 30.0, maxY = 30.0; + qreal increment = 20.0; + + foreach (Node *n, graph()->nodes()) { + while (n->point().x() - increment < -maxX || n->point().x() + increment > maxX) { + maxX += increment; + } + + while (n->point().y() - increment < -maxY || n->point().y() + increment > maxY) { + maxY += increment; + } + } + + QRectF rect(-GLOBAL_SCALEF * maxX, -GLOBAL_SCALEF * maxY, 2.0 * GLOBAL_SCALEF * maxX, 2.0 * GLOBAL_SCALEF * maxY); + + if (rect != sceneRect()) { + setSceneRect(rect); + invalidate(); + } +} + // void TikzScene::refreshSceneBounds() // { // // if (!views().empty()) { |