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@54
|
34
|
Chris@54
|
35 QTransform t = paint->worldTransform();
|
Chris@54
|
36 float scale = std::min(t.m11(), t.m22());
|
Chris@54
|
37 if (scale < 0.1) {
|
Chris@54
|
38 paint->setPen(QPen(branchColour, 0));
|
Chris@54
|
39 } else {
|
Chris@54
|
40 paint->setPen(QPen(branchColour, 2));
|
Chris@54
|
41 }
|
Chris@53
|
42
|
Chris@53
|
43 float xscale = 100;
|
Chris@53
|
44
|
Chris@53
|
45 float yscale = 90;
|
Chris@46
|
46 float size = 50;
|
Chris@53
|
47 float ygap = yscale - size;
|
Chris@53
|
48
|
Chris@53
|
49 int c_col = m_child->column(), c_row = m_child->row();
|
Chris@53
|
50 int p_col = m_parent->column(), p_row = m_parent->row();
|
Chris@53
|
51
|
Chris@53
|
52 float c_x = xscale * c_col + size/2;
|
Chris@53
|
53 float p_x = xscale * p_col + size/2;
|
Chris@53
|
54
|
Chris@53
|
55 p.moveTo(c_x, yscale * c_row + size);
|
Chris@53
|
56
|
Chris@53
|
57 if (p_col == c_col) {
|
Chris@53
|
58
|
Chris@53
|
59 p.lineTo(p_x, yscale * p_row);
|
Chris@53
|
60
|
Chris@53
|
61 } else if (m_type == Split || m_type == Normal) {
|
Chris@53
|
62
|
Chris@53
|
63 // place the bulk of the line on the child (i.e. branch) row
|
Chris@53
|
64
|
Chris@53
|
65 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
66 p.lineTo(c_x, yscale * p_row - ygap);
|
Chris@53
|
67 }
|
Chris@53
|
68
|
Chris@53
|
69 p.cubicTo(c_x, yscale * p_row,
|
Chris@53
|
70 p_x, yscale * p_row - ygap,
|
Chris@53
|
71 p_x, yscale * p_row);
|
Chris@53
|
72
|
Chris@53
|
73 } else if (m_type == Merge) {
|
Chris@53
|
74
|
Chris@53
|
75 // place bulk of the line on the parent row
|
Chris@53
|
76
|
Chris@53
|
77 p.cubicTo(c_x, yscale * c_row + size + ygap,
|
Chris@53
|
78 p_x, yscale * c_row + size,
|
Chris@53
|
79 p_x, yscale * c_row + size + ygap);
|
Chris@53
|
80
|
Chris@53
|
81 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
82 p.lineTo(p_x, yscale * p_row);
|
Chris@46
|
83 }
|
Chris@46
|
84 }
|
Chris@53
|
85
|
Chris@46
|
86 paint->drawPath(p);
|
Chris@53
|
87 paint->restore();
|
Chris@46
|
88 }
|
Chris@46
|
89
|
Chris@46
|
90
|