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