changeset 250:be483734bde5

* Make it possible for changeset items to take two or three lines of description, depending on how much there is * Some other small improvements to how changeset items are drawn (e.g. give them opaque white backgrounds)
author Chris Cannam
date Tue, 11 Jan 2011 17:58:14 +0000
parents 123e06d5d9af
children 0689dada1419 669f2a8ff1a8
files changesetitem.cpp connectionitem.cpp grapher.cpp historywidget.cpp panner.cpp uncommitteditem.cpp
diffstat 6 files changed, 73 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/changesetitem.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/changesetitem.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -55,7 +55,7 @@
 {
     int w = 100;
     if (m_wide) w = 180;
-    return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
+    return QRectF(-((w-50)/2 - 1), -30, w - 3, 90);
 }
 
 void
@@ -211,7 +211,10 @@
 	f.setPixelSize(ps);
     }
 
-    if (scale < 0.1) {
+    bool showText = (scale >= 0.2);
+    bool showProperLines = (scale >= 0.1);
+
+    if (!showProperLines) {
 	paint->setPen(QPen(branchColour, 0));
     } else {
 	paint->setPen(QPen(branchColour, 2));
@@ -225,22 +228,54 @@
     if (m_wide) width = 180;
     int x0 = -((width - 50) / 2 - 1);
 
-    int height = 49;
+    int textwid = width - 7;
+
+    QString comment;
+    QStringList lines;
+    int lineCount = 3;
+
+    if (showText) {
+    
+        comment = m_changeset->comment().trimmed();
+        comment = comment.replace("\\n", " ");
+        comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
+        comment = comment.replace(QRegExp("\"$"), "");
+        comment = comment.replace("\\\"", "\"");
+
+        comment = TextAbbrev::abbreviate(comment, fm, textwid,
+                                         TextAbbrev::ElideEnd, "...", 3);
+        // abbreviate() changes this (ouch!), restore it
+        textwid = width - 5;
+
+        lines = comment.split('\n');
+        lineCount = lines.size();
+
+        if (lineCount < 2) lineCount = 2;
+    }
+
+    int height = (lineCount + 1) * fh + 2;
     QRectF r(x0, 0, width - 3, height);
+
+    if (showProperLines) {
+
+        paint->setBrush(Qt::white);
+
+        if (m_current) {
+            paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8));
+        }
+
+        if (m_new) {
+            paint->save();
+            paint->setPen(Qt::yellow);
+            paint->setBrush(Qt::NoBrush);
+            paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4));
+            paint->restore();
+        }
+    }
+
     paint->drawRect(r);
 
-    if (m_new) {
-        paint->save();
-        paint->setPen(Qt::yellow);
-        paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4));
-        paint->restore();
-    }
-
-    if (m_current) {
-        paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8));
-    }
-
-    if (scale < 0.2) {
+    if (!showText) {
 	paint->restore();
 	return;
     }
@@ -250,8 +285,8 @@
 
     paint->setPen(QPen(Qt::white));
 
-    int wid = width - 5;
-    QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
+    QString person = TextAbbrev::abbreviate(m_changeset->authorName(),
+                                            fm, textwid);
     paint->drawText(x0 + 3, fm.ascent(), person);
 
     paint->setPen(QPen(Qt::black));
@@ -293,23 +328,8 @@
         paint->restore();
     }
 
-    fm = QFontMetrics(f);
-    fh = fm.height();
     paint->setFont(f);
 
-    QString comment = m_changeset->comment().trimmed();
-    comment = comment.replace("\\n", " ");
-    comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
-    comment = comment.replace(QRegExp("\"$"), "");
-    comment = comment.replace("\\\"", "\"");
-
-    wid = width - 5;
-    int nlines = (height / fh) - 1;
-    if (nlines < 1) nlines = 1;
-    comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
-				     "...", nlines);
-
-    QStringList lines = comment.split('\n');
     for (int i = 0; i < lines.size(); ++i) {
 	paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
     }
--- a/connectionitem.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/connectionitem.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -89,7 +89,12 @@
     float c_x = xscale * c_col + size/2;
     float p_x = xscale * p_col + size/2;
 
-    p.moveTo(c_x, yscale * c_row + size);
+    // ensure line reaches the box, even if it's in a small height --
+    // doesn't matter if we overshoot as the box is opaque and has a
+    // greater Z value
+    p.moveTo(c_x, yscale * c_row + size - 20);
+
+    p.lineTo(c_x, yscale * c_row + size);
 
     if (p_col == c_col) {
 
--- a/grapher.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/grapher.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -427,6 +427,7 @@
         ChangesetItem *item = new ChangesetItem(cs);
         item->setX(0);
         item->setY(0);
+        item->setZValue(0);
         m_items[id] = item;
         m_scene->addChangesetItem(item);
     }
@@ -445,6 +446,7 @@
             if (merge) conn->setConnectionType(ConnectionItem::Merge);
             conn->setChild(item);
             conn->setParent(m_items[parentId]);
+            conn->setZValue(-1);
             m_scene->addItem(conn);
         }
     }
@@ -454,12 +456,14 @@
     if (!m_uncommittedParents.empty()) {
         m_uncommitted = new UncommittedItem();
         m_uncommitted->setBranch(uncommittedBranch);
+        m_uncommitted->setZValue(10);
         m_scene->addUncommittedItem(m_uncommitted);
         foreach (QString p, m_uncommittedParents) {
             ConnectionItem *conn = new ConnectionItem();
             conn->setConnectionType(ConnectionItem::Merge);
             conn->setParent(m_items[p]);
             conn->setChild(m_uncommitted);
+            conn->setZValue(0);
             m_scene->addItem(conn);
         }
     }
@@ -583,7 +587,7 @@
                 item->setCols(datemincol, datemaxcol - datemincol + 1);
                 item->setRows(changeRow, n);
                 item->setEven(even);
-                item->setZValue(-1);
+                item->setZValue(-2);
                 m_scene->addDateItem(item);
                 even = !even;
             }
@@ -599,7 +603,7 @@
         item->setCols(datemincol, datemaxcol - datemincol + 1);
         item->setRows(changeRow, n+1);
         item->setEven(even);
-        item->setZValue(-1);
+        item->setZValue(-2);
         m_scene->addDateItem(item);
         even = !even;
     }
--- a/historywidget.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/historywidget.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -36,6 +36,7 @@
     m_panner = new Panner;
 
     m_panned->setDragMode(QGraphicsView::ScrollHandDrag);
+    m_panned->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
 
     QGridLayout *layout = new QGridLayout;
     layout->addWidget(m_panned, 0, 0);
--- a/panner.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/panner.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -110,6 +110,7 @@
 void
 Panner::resizeEvent(QResizeEvent *)
 {
+    DEBUG << "Panner::resizeEvent" << endl;
     if (scene()) fit(sceneRect());
     m_cache = QPixmap();
 }
@@ -117,6 +118,7 @@
 void
 Panner::slotSceneRectChanged(const QRectF &newRect)
 {
+    DEBUG << "Panner::slotSceneRectChanged" << endl;
     if (!scene()) return; // spurious
     fit(newRect);
     m_cache = QPixmap();
@@ -126,6 +128,7 @@
 void
 Panner::slotSceneChanged(const QList<QRectF> &)
 {
+    DEBUG << "Panner::slotSceneChanged" << endl;
     if (!scene()) return; // spurious
     m_cache = QPixmap();
     viewport()->update();
@@ -163,7 +166,8 @@
 void
 Panner::updateScene(const QList<QRectF> &rects)
 {
-    if (!m_cache.isNull()) m_cache = QPixmap();
+    DEBUG << "Panner::updateScene" << endl;
+//    if (!m_cache.isNull()) m_cache = QPixmap();
     QGraphicsView::updateScene(rects);
 }
 
@@ -187,6 +191,8 @@
         cachePainter.setTransform(viewportTransform());
         ps->drawItems(&cachePainter, numItems, items, options);
         cachePainter.end();
+
+        DEBUG << "done" << endl;
     }
 
     painter->save();
--- a/uncommitteditem.cpp	Tue Jan 11 17:56:22 2011 +0000
+++ b/uncommitteditem.cpp	Tue Jan 11 17:58:14 2011 +0000
@@ -127,6 +127,7 @@
 
     int height = 49;
     QRectF r(x0, 0, width - 3, height);
+    paint->setBrush(Qt::white);
     paint->drawRect(r);
 
     if (m_wide) {