# HG changeset patch # User Chris Cannam # Date 1306250775 -3600 # Node ID ce6a70970808e003a55414c81a90cfd7fd335c36 # Parent 7ef46fb73b486976ab95d190d40d55727589e310 Use a plain small circle for merge commits diff -r 7ef46fb73b48 -r ce6a70970808 src/changesetitem.cpp --- a/src/changesetitem.cpp Tue May 24 14:05:35 2011 +0100 +++ b/src/changesetitem.cpp Tue May 24 16:26:15 2011 +0100 @@ -68,6 +68,7 @@ scene()->addItem(m_detail); int w = 100; if (m_wide) w = 180; + if (isMerge()) w = 60; int h = 80; // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, // y() + 60); @@ -240,6 +241,22 @@ void ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) { + if (isMerge()) { + paintMerge(paint); + } else { + paintNormal(paint); + } +} + +bool +ChangesetItem::isMerge() const +{ + return (m_changeset && m_changeset->parents().size() > 1); +} + +void +ChangesetItem::paintNormal(QPainter *paint) +{ paint->save(); ColourSet *colourSet = ColourSet::instance(); @@ -391,3 +408,59 @@ paint->restore(); } + +void +ChangesetItem::paintMerge(QPainter *paint) +{ + paint->save(); + + ColourSet *colourSet = ColourSet::instance(); + QColor branchColour = colourSet->getColourFor(m_changeset->branch()); + QColor userColour = colourSet->getColourFor(m_changeset->author()); + + QFont f(m_font); + + QTransform t = paint->worldTransform(); + float scale = std::min(t.m11(), t.m22()); + if (scale > 1.0) { + int ps = int((f.pixelSize() / scale) + 0.5); + if (ps < 8) ps = 8; + f.setPixelSize(ps); + } + + bool showText = (scale >= 0.2); + bool showProperLines = (scale >= 0.1); + + if (!showProperLines) { + paint->setPen(QPen(branchColour, 0)); + } else { + paint->setPen(QPen(branchColour, 2)); + } + + paint->setFont(f); + QFontMetrics fm(f); + int fh = fm.height(); + int size = fh * 2; + int x0 = -size/2 + 25; + + paint->setBrush(Qt::white); + paint->drawEllipse(QRectF(x0, fh, size, size)); + + if (m_showBranch) { + // write branch name + paint->save(); + f.setBold(true); + paint->setFont(f); + paint->setPen(QPen(branchColour)); + QString branch = m_changeset->branch(); + if (branch == "") branch = "default"; + int wid = size * 3; + branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); + paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch); + f.setBold(false); + paint->restore(); + } + + paint->restore(); +} + diff -r 7ef46fb73b48 -r ce6a70970808 src/changesetitem.h --- a/src/changesetitem.h Tue May 24 14:05:35 2011 +0100 +++ b/src/changesetitem.h Tue May 24 16:26:15 2011 +0100 @@ -100,6 +100,10 @@ QMap m_parentDiffActions; QMap m_summaryActions; + + bool isMerge() const; + virtual void paintNormal(QPainter *); + virtual void paintMerge(QPainter *); }; #endif // CHANGESETITEM_H diff -r 7ef46fb73b48 -r ce6a70970808 src/connectionitem.cpp --- a/src/connectionitem.cpp Tue May 24 14:05:35 2011 +0100 +++ b/src/connectionitem.cpp Tue May 24 16:26:15 2011 +0100 @@ -41,9 +41,9 @@ } return QRectF(xscale * c_col + size/2 - 2, - yscale * c_row + size - 2, + yscale * c_row + size - 22, xscale * p_col - xscale * c_col + 4, - yscale * p_row - yscale * c_row - size + 4) + yscale * p_row - yscale * c_row - size + 44) .normalized(); } @@ -125,6 +125,10 @@ } } + // ensure line reaches the node -- again doesn't matter if we + // overshoot + p.lineTo(p_x, yscale * p_row + 20); + paint->drawPath(p); paint->restore(); }