changeset 55:261bfb9481fe

* Make changeset item boxes wider if they have no neighbours. Changeset item code is horrible -- items generally need refactoring to take out hardcoded dimensions.
author Chris Cannam
date Fri, 12 Nov 2010 17:30:53 +0000
parents 0e5fba6750c2
children 1394c8cbf991
files changesetitem.cpp changesetitem.h grapher.cpp
diffstat 3 files changed, 34 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/changesetitem.cpp	Fri Nov 12 17:04:36 2010 +0000
+++ b/changesetitem.cpp	Fri Nov 12 17:30:53 2010 +0000
@@ -6,7 +6,7 @@
 #include <QPainter>
 
 ChangesetItem::ChangesetItem(Changeset *cs) :
-    m_changeset(cs), m_column(0), m_row(0)
+    m_changeset(cs), m_column(0), m_row(0), m_wide(false)
 {
     m_font = QFont();
     m_font.setPixelSize(11);
@@ -17,7 +17,9 @@
 QRectF
 ChangesetItem::boundingRect() const
 {
-    return QRectF(-24, -30, 97, 79);
+    int w = 100;
+    if (m_wide) w = 180;
+    return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
 }
 
 void
@@ -49,8 +51,12 @@
     paint->setFont(f);
     QFontMetrics fm(f);
     int fh = fm.height();
-    
-    QRectF r(-24, 0, 97, 49);
+
+    int width = 100;
+    if (m_wide) width = 180;
+    int x0 = -((width - 50) / 2 - 1);
+
+    QRectF r(x0, 0, width - 3, 49);
     paint->drawRect(r);
 
     if (scale < 0.1) {
@@ -62,19 +68,20 @@
 	f.setBold(true);
 	paint->setFont(f);
 	QString branch = m_changeset->branch();
-	int wid = 97;
+	int wid = width - 3;
 	branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
-	paint->drawText(-24, -fh + fm.ascent() - 4, branch);
+	paint->drawText(x0, -fh + fm.ascent() - 4, branch);
 	f.setBold(false);
     }
 
-    paint->fillRect(QRectF(-23.5, 0.5, 96, fh - 0.5), QBrush(userColour));
+    paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
+		    QBrush(userColour));
 
     paint->setPen(QPen(Qt::white));
 
-    int wid = 95;
+    int wid = width - 5;
     QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
-    paint->drawText(-21, fm.ascent(), person);
+    paint->drawText(x0 + 3, fm.ascent(), person);
 
     paint->setPen(QPen(Qt::black));
 
@@ -90,13 +97,13 @@
     comment = comment.replace("\\\"", "\"");
     comment = comment.split('\n')[0];
 
-    wid = 95;
+    wid = width - 5;
     comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
 				     "...", 2);
 
     QStringList lines = comment.split('\n');
     for (int i = 0; i < lines.size(); ++i) {
-	paint->drawText(-21, i * fh + fh + fm.ascent(), lines[i].trimmed());
+	paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
     }
 
     paint->restore();
--- a/changesetitem.h	Fri Nov 12 17:04:36 2010 +0000
+++ b/changesetitem.h	Fri Nov 12 17:30:53 2010 +0000
@@ -21,11 +21,15 @@
     void setColumn(int c) { m_column = c; setX(c * 100); }
     void setRow(int r) { m_row = r; setY(r * 90); }
 
+    bool isWide() const { return m_wide; }
+    void setWide(bool w) { m_wide = w; }
+
 private:
     QFont m_font;
     Changeset *m_changeset;
     int m_column;
     int m_row;
+    bool m_wide;
 };
 
 #endif // CHANGESETITEM_H
--- a/grapher.cpp	Fri Nov 12 17:04:36 2010 +0000
+++ b/grapher.cpp	Fri Nov 12 17:30:53 2010 +0000
@@ -186,8 +186,9 @@
         if (!m_changesets.contains(childId)) continue;
         Changeset *child = m_changesets[childId];
 	int childRow = m_items[childId]->row();
-        if (child->parents().size() > 1 || child->branch() == cs->branch()) {
-            for (int r = row; r > childRow; --r) {
+        if (child->parents().size() > 1 ||
+	    child->branch() == cs->branch()) {
+            for (int r = row-1; r > childRow; --r) {
                 m_alloc[r].insert(col);
             }
 	}	    
@@ -211,9 +212,8 @@
 	    for (int i = 0; i < 2; ++i) {
 		int off = i * 2 - 1; // 0 -> -1, 1 -> 1
 		ChangesetItem *it = m_items[special[i]];
-		m_alloc[it->row()].insert(col); // avoid our column
 		it->setColumn(findAvailableColumn(it->row(), col + off, true));
-		for (int r = row; r >= it->row(); --r) {
+		for (int r = row-1; r >= it->row(); --r) {
 		    m_alloc[r].insert(it->column());
 		}
 		m_handled.insert(special[i]);
@@ -384,6 +384,14 @@
 	layoutCol(cs->id());
     }
 
+    foreach (Changeset *cs, csets) {
+	ChangesetItem *item = m_items[cs->id()];
+	if (!m_alloc[item->row()].contains(item->column()-1) &&
+	    !m_alloc[item->row()].contains(item->column()+1)) {
+	    item->setWide(true);
+	}
+    }
+
     // we know that 0 is an upper bound on row, and that mincol must
     // be <= 0 and maxcol >= 0, so these initial values are good
     int minrow = 0, maxrow = 0;