comparison connectionitem.cpp @ 53:3c46b2ac45d3

* Put proper labels &c in changeset items; colour branches and users; etc
author Chris Cannam
date Fri, 12 Nov 2010 16:48:18 +0000
parents bd3accba9b3f
children 0e5fba6750c2
comparison
equal deleted inserted replaced
52:384420567575 53:3c46b2ac45d3
1 1
2 2
3 #include "connectionitem.h" 3 #include "connectionitem.h"
4 4
5 #include "changesetitem.h" 5 #include "changesetitem.h"
6 #include "changeset.h"
7 #include "colourset.h"
6 8
7 #include <QPainter> 9 #include <QPainter>
8 10
9 QRectF 11 QRectF
10 ConnectionItem::boundingRect() const 12 ConnectionItem::boundingRect() const
11 { 13 {
12 if (!m_parent || !m_child) return QRectF(); 14 if (!m_parent || !m_child) return QRectF();
13 float scale = 100; 15 float xscale = 100;
16 float yscale = 90;
14 float size = 50; 17 float size = 50;
15 return QRectF(scale * m_child->column() + size/2 - 2, 18 return QRectF(xscale * m_child->column() + size/2 - 2,
16 scale * m_child->row() + size - 2, 19 yscale * m_child->row() + size - 2,
17 scale * m_parent->column() - scale * m_child->column() + 4, 20 xscale * m_parent->column() - xscale * m_child->column() + 4,
18 scale * m_parent->row() - scale * m_child->row() - size + 4) 21 yscale * m_parent->row() - yscale * m_child->row() - size + 4)
19 .normalized(); 22 .normalized();
20 } 23 }
21 24
22 void 25 void
23 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) 26 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
24 { 27 {
25 QPainterPath p; 28 QPainterPath p;
26 float scale = 100; 29
30 paint->save();
31
32 ColourSet *colourSet = ColourSet::instance();
33 QColor branchColour = colourSet->getColourFor(m_child->getChangeset()->branch());
34 paint->setPen(QPen(branchColour, 2));
35
36 float xscale = 100;
37
38 float yscale = 90;
27 float size = 50; 39 float size = 50;
28 p.moveTo(scale * m_child->column() + size/2, 40 float ygap = yscale - size;
29 scale * m_child->row() + size); 41
30 if (m_parent->column() == m_child->column()) { 42 int c_col = m_child->column(), c_row = m_child->row();
31 p.lineTo(scale * m_parent->column() + size/2, 43 int p_col = m_parent->column(), p_row = m_parent->row();
32 scale * m_parent->row()); 44
33 } else { 45 float c_x = xscale * c_col + size/2;
34 p.cubicTo(scale * m_child->column() + size/2, 46 float p_x = xscale * p_col + size/2;
35 scale * m_child->row() + size + size, 47
36 scale * m_parent->column() + size/2, 48 p.moveTo(c_x, yscale * c_row + size);
37 scale * m_child->row() + size, 49
38 scale * m_parent->column() + size/2, 50 if (p_col == c_col) {
39 scale * m_child->row() + scale); 51
40 if (abs(m_parent->row() - m_child->row()) > 1) { 52 p.lineTo(p_x, yscale * p_row);
41 p.lineTo(scale * m_parent->column() + size/2, 53
42 scale * m_parent->row()); 54 } else if (m_type == Split || m_type == Normal) {
55
56 // place the bulk of the line on the child (i.e. branch) row
57
58 if (abs(p_row - c_row) > 1) {
59 p.lineTo(c_x, yscale * p_row - ygap);
60 }
61
62 p.cubicTo(c_x, yscale * p_row,
63 p_x, yscale * p_row - ygap,
64 p_x, yscale * p_row);
65
66 } else if (m_type == Merge) {
67
68 // place bulk of the line on the parent row
69
70 p.cubicTo(c_x, yscale * c_row + size + ygap,
71 p_x, yscale * c_row + size,
72 p_x, yscale * c_row + size + ygap);
73
74 if (abs(p_row - c_row) > 1) {
75 p.lineTo(p_x, yscale * p_row);
43 } 76 }
44 } 77 }
78
45 paint->drawPath(p); 79 paint->drawPath(p);
80 paint->restore();
46 } 81 }
47 82
48 83