Mercurial > hg > easyhg
diff panned.cpp @ 133:aaeab914f2a3
* Better attempt at retaining current visible area when history scene changes; first cut at highlighting new items
author | Chris Cannam |
---|---|
date | Tue, 30 Nov 2010 12:45:34 +0000 |
parents | 16ceeee30e2a |
children | 4bad3c5c053a |
line wrap: on
line diff
--- a/panned.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/panned.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -44,6 +44,32 @@ if (pr != m_pannedRect) { DEBUG << "Panned: setting panned rect to " << pr << endl; m_pannedRect = pr; + centerOn(pr.center()); + emit pannedRectChanged(pr); + } +} + +void +Panned::setScene(QGraphicsScene *s) +{ + if (!scene()) { + QGraphicsView::setScene(s); + return; + } + + QPointF nearpt = mapToScene(0, 0); + QPointF farpt = mapToScene(width(), height()); + QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y()); + QRectF pr(nearpt, sz); + + QGraphicsView::setScene(s); + + DEBUG << "Panned::setScene: pr = " << pr << ", sceneRect = " << sceneRect() << endl; + + if (scene() && sceneRect().intersects(pr)) { + DEBUG << "Panned::setScene: restoring old rect " << pr << endl; + m_pannedRect = pr; + centerOn(pr.center()); emit pannedRectChanged(pr); } } @@ -63,6 +89,7 @@ QRectF pr(nearpt, sz); if (pr != m_pannedRect) { + DEBUG << "Panned::drawForeground: visible rect " << pr << " differs from panned rect " << m_pannedRect << ", updating panned rect" <<endl; if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled(); m_pannedRect = pr; emit pannedRectChanged(pr);