changeset 402:75003687f364

Better version of ensuring the scene size is properly updated and the detail item made visible
author Chris Cannam
date Wed, 25 May 2011 16:05:40 +0100
parents c3276f8998ee
children 44cef6368690
files src/changesetdetailitem.cpp src/changesetdetailitem.h src/changesetitem.cpp src/changesetscene.cpp src/changesetscene.h
diffstat 5 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/changesetdetailitem.cpp	Wed May 25 15:38:48 2011 +0100
+++ b/src/changesetdetailitem.cpp	Wed May 25 16:05:40 2011 +0100
@@ -49,6 +49,19 @@
     return QRectF(-10, -10, w + 10, m_doc->size().height() + 10);
 }
 
+QVariant
+ChangesetDetailItem::itemChange(GraphicsItemChange c, const QVariant &v)
+{
+    if (c == ItemVisibleHasChanged) {
+        bool visible = v.toBool();
+        DEBUG << "ChangesetDetailItem::itemChange: visible = " << visible << endl;
+        if (visible && scene()) {
+            ensureVisible();
+        }
+    }
+    return v;
+}
+
 void
 ChangesetDetailItem::paint(QPainter *paint,
 			   const QStyleOptionGraphicsItem *option,
--- a/src/changesetdetailitem.h	Wed May 25 15:38:48 2011 +0100
+++ b/src/changesetdetailitem.h	Wed May 25 16:05:40 2011 +0100
@@ -39,6 +39,8 @@
     Changeset *m_changeset;
     QTextDocument *m_doc;
 
+    QVariant itemChange(GraphicsItemChange, const QVariant &);
+
     void makeDocument();
 };
 
--- a/src/changesetitem.cpp	Wed May 25 15:38:48 2011 +0100
+++ b/src/changesetitem.cpp	Wed May 25 16:05:40 2011 +0100
@@ -78,7 +78,6 @@
 //                     y() + 60);
     m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5,
                      y() - (m_detail->boundingRect().height() - h) / 2 + 0.5);
-    m_detail->ensureVisible();
     emit detailShown();
 }    
 
--- a/src/changesetscene.cpp	Wed May 25 15:38:48 2011 +0100
+++ b/src/changesetscene.cpp	Wed May 25 16:05:40 2011 +0100
@@ -106,17 +106,28 @@
 void
 ChangesetScene::itemAddCompleted()
 {
+    connect(this, SIGNAL(changed(const QList<QRectF> &)),
+            this, SLOT(recalculateSceneRect()));
+    recalculateSceneRect();
+}
+
+void
+ChangesetScene::recalculateSceneRect()
+{
+    QRectF existingSr = sceneRect();
+
     QRectF r = itemsBoundingRect();
     float minwidth = 300; //!!!
-    DEBUG << "ChangesetScene::itemAddCompleted: minwidth = " << minwidth
+    DEBUG << "ChangesetScene::recalculateSceneRect: minwidth = " << minwidth
           << ", r = " << r << endl;
     if (r.width() < minwidth) {
         float edgediff = (minwidth - r.width()) / 2;
         r.setLeft(r.left() - edgediff);
         r.setRight(r.right() + edgediff);
     }
-    DEBUG << "ChangesetScene::itemAddCompleted: r now is " << r << endl;
-    setSceneRect(r);
+    DEBUG << "ChangesetScene::recalculateSceneRect: r now is " << r << endl;
+
+    setSceneRect(r.united(existingSr));
 }
 
 void
@@ -129,8 +140,6 @@
 	m_detailShown->hideDetail();
     }
     m_detailShown = csi;
-    itemAddCompleted();
-    csi->ensureVisible();
 }
 
 void
--- a/src/changesetscene.h	Wed May 25 15:38:48 2011 +0100
+++ b/src/changesetscene.h	Wed May 25 16:05:40 2011 +0100
@@ -71,6 +71,7 @@
 private slots:
     void changesetDetailShown();
     void changesetDetailHidden();
+    void recalculateSceneRect();
 
 protected:
     void drawBackground(QPainter *, const QRectF &);