# HG changeset patch # User Chris Cannam # Date 1306331929 -3600 # Node ID b1f0fa991c49fe7f20791b0dc463bc27fe07c216 # Parent 4f3d96c1916f2328fe3d91f6707daa1a5b9a26b2 Use circle presentation for uncommitted merge as well as merge changeset diff -r 4f3d96c1916f -r b1f0fa991c49 src/changesetitem.h --- a/src/changesetitem.h Wed May 25 14:48:42 2011 +0100 +++ b/src/changesetitem.h Wed May 25 14:58:49 2011 +0100 @@ -105,8 +105,8 @@ static QImage *m_star; bool isMerge() const; - virtual void paintNormal(QPainter *); - virtual void paintMerge(QPainter *); + void paintNormal(QPainter *); + void paintMerge(QPainter *); }; #endif // CHANGESETITEM_H diff -r 4f3d96c1916f -r b1f0fa991c49 src/grapher.cpp --- a/src/grapher.cpp Wed May 25 14:48:42 2011 +0100 +++ b/src/grapher.cpp Wed May 25 14:58:49 2011 +0100 @@ -464,6 +464,9 @@ // tell it it has a new branch (the "show branch" flag is set // elsewhere for this item) m_uncommitted->setIsNewBranch(!haveParentOnBranch); + + // Uncommitted is a merge if it has more than one parent + m_uncommitted->setIsMerge(m_uncommittedParents.size() > 1); } // Add the branch labels diff -r 4f3d96c1916f -r b1f0fa991c49 src/uncommitteditem.cpp --- a/src/uncommitteditem.cpp Wed May 25 14:48:42 2011 +0100 +++ b/src/uncommitteditem.cpp Wed May 25 14:58:49 2011 +0100 @@ -29,7 +29,7 @@ #include UncommittedItem::UncommittedItem() : - m_showBranch(false), m_isNewBranch(false), + m_showBranch(false), m_isNewBranch(false), m_isMerge(false), m_column(0), m_row(0), m_wide(false) { m_font = QFont(); @@ -70,7 +70,10 @@ UncommittedItem::activateMenu() { QMenu *menu = new QMenu; - QLabel *label = new QLabel(tr(" Uncommitted changes")); + QLabel *label = new QLabel + (m_isMerge ? + tr(" Uncommitted merge") : + tr(" Uncommitted changes")); QWidgetAction *wa = new QWidgetAction(menu); wa->setDefaultWidget(label); menu->addAction(wa); @@ -102,8 +105,17 @@ } void -UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, - QWidget *w) +UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) +{ + if (isMerge()) { + paintMerge(paint); + } else { + paintNormal(paint); + } +} + +void +UncommittedItem::paintNormal(QPainter *paint) { paint->save(); @@ -168,3 +180,66 @@ paint->restore(); return; } + +void +UncommittedItem::paintMerge(QPainter *paint) +{ + paint->save(); + + ColourSet *colourSet = ColourSet::instance(); + QColor branchColour = colourSet->getColourFor(m_branch); + + 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); + } + + if (scale < 0.1) { + paint->setPen(QPen(branchColour, 0, Qt::DashLine)); + } else { + paint->setPen(QPen(branchColour, 2, Qt::DashLine)); + } + + 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_wide) { + QString label = tr("Uncommitted merge"); + paint->drawText(size/2 + 28, + 25 - fm.height()/2 + fm.ascent(), + label); + } else { + QString label = tr("Uncommitted"); + paint->drawText(size/2 + 28, + 25 - fm.height() + fm.ascent(), + label); + label = tr("merge"); + paint->drawText(size/2 + 28, + 25 + fm.ascent(), + label); + } + + if (m_showBranch && m_branch != "") { + // write branch name + f.setBold(true); + paint->setFont(f); + int wid = size * 3; + QString branch = TextAbbrev::abbreviate(m_branch, QFontMetrics(f), wid); + paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch); + } + + paint->restore(); + return; +} diff -r 4f3d96c1916f -r b1f0fa991c49 src/uncommitteditem.h --- a/src/uncommitteditem.h Wed May 25 14:48:42 2011 +0100 +++ b/src/uncommitteditem.h Wed May 25 14:58:49 2011 +0100 @@ -39,6 +39,9 @@ bool isNewBranch() const { return m_isNewBranch; } void setIsNewBranch(bool s) { m_isNewBranch = s; } + + bool isMerge() const { return m_isMerge; } + void setIsMerge(bool m) { m_isMerge = m; } int column() const { return m_column; } int row() const { return m_row; } @@ -67,10 +70,14 @@ QString m_branch; bool m_showBranch; bool m_isNewBranch; + bool m_isMerge; QFont m_font; int m_column; int m_row; bool m_wide; + + void paintNormal(QPainter *); + void paintMerge(QPainter *); }; #endif // UNCOMMITTEDITEM_H