Mercurial > hg > easyhg
changeset 387:ce6a70970808 item_appearance_adjustments
Use a plain small circle for merge commits
author | Chris Cannam |
---|---|
date | Tue, 24 May 2011 16:26:15 +0100 |
parents | 7ef46fb73b48 |
children | 6718bbc073b4 |
files | src/changesetitem.cpp src/changesetitem.h src/connectionitem.cpp |
diffstat | 3 files changed, 83 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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(); +} +
--- 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<QAction *, QString> m_parentDiffActions; QMap<QAction *, QString> m_summaryActions; + + bool isMerge() const; + virtual void paintNormal(QPainter *); + virtual void paintMerge(QPainter *); }; #endif // CHANGESETITEM_H
--- 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(); }