Mercurial > hg > easyhg
diff src/connectionitem.cpp @ 516:2981d2defa61
Introduce a graphical representation for merge from a closed to an open branch (half a connection item)
author | Chris Cannam |
---|---|
date | Thu, 20 Oct 2011 12:04:47 +0100 |
parents | 470829a21f98 |
children | 533519ebc0cb |
line wrap: on
line diff
--- a/src/connectionitem.cpp Thu Oct 20 11:36:49 2011 +0100 +++ b/src/connectionitem.cpp Thu Oct 20 12:04:47 2011 +0100 @@ -21,18 +21,19 @@ #include "changesetitem.h" #include "changeset.h" #include "colourset.h" +#include "textabbrev.h" #include <QPainter> +#include <QFont> QRectF ConnectionItem::boundingRect() const { - if (!m_parent || !(m_child || m_uncommitted)) return QRectF(); + if (!(m_child || m_uncommitted)) return QRectF(); float xscale = 100; float yscale = 90; float size = 50; - int p_col = m_parent->column(), p_row = m_parent->row(); int c_col, c_row; if (m_child) { c_col = m_child->column(); c_row = m_child->row(); @@ -40,6 +41,13 @@ c_col = m_uncommitted->column(); c_row = m_uncommitted->row(); } + int p_col, p_row; + if (m_parent) { + p_col = m_parent->column(); p_row = m_parent->row(); + } else { + p_col = c_col - 1; p_row = c_row + 1; + } + return QRectF(xscale * c_col + size/2 - 2, yscale * c_row + size - 22, xscale * p_col - xscale * c_col + 6, @@ -50,7 +58,7 @@ void ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) { - if (!m_parent || !(m_child || m_uncommitted)) return; + if (!(m_child || m_uncommitted)) return; QPainterPath p; paint->save(); @@ -83,7 +91,6 @@ float size = 50; float ygap = yscale - size - 2; - int p_col = m_parent->column(), p_row = m_parent->row(); int c_col, c_row; if (m_child) { c_col = m_child->column(); c_row = m_child->row(); @@ -91,6 +98,13 @@ c_col = m_uncommitted->column(); c_row = m_uncommitted->row(); } + int p_col, p_row; + if (m_parent) { + p_col = m_parent->column(); p_row = m_parent->row(); + } else { + p_col = c_col - 1; p_row = c_row + 1; + } + float c_x = xscale * c_col + size/2; float p_x = xscale * p_col + size/2; @@ -130,11 +144,42 @@ } } - // ensure line reaches the node -- again doesn't matter if we - // overshoot - p.lineTo(p_x, yscale * p_row + 20); + if (m_parent) { + // ensure line reaches the node -- again doesn't matter if we + // overshoot + p.lineTo(p_x, yscale * p_row + 20); + + } else { + + // no parent: merge from closed branch: draw only half the line + paint->setClipRect(QRectF((c_x + p_x)/2, yscale * c_row + size - 22, + xscale, yscale)); + } + paint->drawPath(p); + + if (!m_parent) { + + // merge from closed branch: draw branch name + + paint->setClipping(false); + + QFont f; + f.setPixelSize(11); + f.setBold(true); + f.setItalic(false); + paint->setFont(f); + + QString branch = m_mergedBranch; + if (branch == "") branch = "default"; + int wid = xscale; + branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); + paint->drawText((c_x + p_x)/2 - wid - 2, + yscale * c_row + size + ygap/2 + 2, + branch); + } + paint->restore(); }