Commit 0002340d authored by Aleks Kissinger's avatar Aleks Kissinger

infinite canvas (closes #20)

parent 86e379ef
......@@ -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()) {
......
......@@ -80,6 +80,7 @@ public:
void getSelection(QSet<Node*> &selNodes, QSet<Edge*> &selEdges);
QSet<Node*> getSelectedNodes();
void refreshSceneBounds();
public slots:
void graphReplaced();
......
......@@ -49,7 +49,7 @@ void TikzView::zoomOut()
void TikzView::setScene(QGraphicsScene *scene)
{
QGraphicsView::setScene(scene);
centerOn(QPointF(0.0f,0.0f));
centerOn(QPointF(0.0,0.0));
}
void TikzView::drawBackground(QPainter *painter, const QRectF &rect)
......
......@@ -29,16 +29,14 @@ GraphUpdateCommand::GraphUpdateCommand(TikzScene *scene, QUndoCommand *parent) :
void GraphUpdateCommand::undo()
{
_scene->tikzDocument()->refreshTikz();
//refreshSceneBounds does nothing
//_scene->refreshSceneBounds();
_scene->refreshSceneBounds();
_scene->invalidate();
}
void GraphUpdateCommand::redo()
{
_scene->tikzDocument()->refreshTikz();
//refreshSceneBounds does nothing
//_scene->refreshSceneBounds();
_scene->refreshSceneBounds();
_scene->invalidate();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment