diff src/changesetscene.cpp @ 397:61bde1f0ff0a item_appearance_adjustments

Replace DateItems (background items for date shading) with a date range list in the scene and dedicated rendering for it in the graphics view: this way we can ensure the shading spans the full width and the dates are always visible
author Chris Cannam
date Wed, 25 May 2011 14:32:32 +0100
parents b9c153e00e84
children c3276f8998ee
line wrap: on
line diff
--- a/src/changesetscene.cpp	Tue May 24 18:00:12 2011 +0100
+++ b/src/changesetscene.cpp	Wed May 25 14:32:32 2011 +0100
@@ -18,10 +18,16 @@
 #include "changesetscene.h"
 #include "changesetitem.h"
 #include "uncommitteditem.h"
-#include "dateitem.h"
+#include "debug.h"
+
+#include <QPainter>
+
 
 ChangesetScene::ChangesetScene()
-    : QGraphicsScene(), m_detailShown(0)
+    // Supply a non-NULL but trivial scene rect to inhibit automatic
+    // updates from QGraphicsScene, because we will set the rect
+    // explicitly in itemAddCompleted
+    : QGraphicsScene(QRectF(0, 0, 1, 1)), m_detailShown(0)
 {
 }
 
@@ -87,12 +93,30 @@
 }
 
 void
-ChangesetScene::addDateItem(DateItem *item)
+ChangesetScene::addDateRange(QString label, int minrow, int nrows, bool even)
 {
-    addItem(item);
+    DateRange dr;
+    dr.label = label;
+    dr.minrow = minrow;
+    dr.nrows = nrows;
+    dr.even = even;
+    m_dateRanges[minrow] = dr;
+}
 
-    connect(item, SIGNAL(clicked()),
-            this, SLOT(dateItemClicked()));
+void
+ChangesetScene::itemAddCompleted()
+{
+    QRectF r = itemsBoundingRect();
+    float minwidth = 300; //!!!
+    DEBUG << "ChangesetScene::itemAddCompleted: 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);
 }
 
 void
@@ -114,12 +138,11 @@
 }
 
 void
-ChangesetScene::dateItemClicked()
+ChangesetScene::drawBackground(QPainter *paint, const QRectF &rect)
 {
-    if (m_detailShown) {
-        m_detailShown->hideDetail();
-    }
+    QGraphicsScene::drawBackground(paint, rect);
 }
+        
 
 ChangesetItem *
 ChangesetScene::getItemById(QString id)