Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@46
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@46
|
17
|
Chris@46
|
18 #include "connectionitem.h"
|
Chris@46
|
19
|
Chris@46
|
20 #include "changesetitem.h"
|
Chris@53
|
21 #include "changeset.h"
|
Chris@53
|
22 #include "colourset.h"
|
Chris@46
|
23
|
Chris@46
|
24 #include <QPainter>
|
Chris@46
|
25
|
Chris@46
|
26 QRectF
|
Chris@46
|
27 ConnectionItem::boundingRect() const
|
Chris@46
|
28 {
|
Chris@46
|
29 if (!m_parent || !m_child) return QRectF();
|
Chris@53
|
30 float xscale = 100;
|
Chris@53
|
31 float yscale = 90;
|
Chris@46
|
32 float size = 50;
|
Chris@53
|
33 return QRectF(xscale * m_child->column() + size/2 - 2,
|
Chris@53
|
34 yscale * m_child->row() + size - 2,
|
Chris@53
|
35 xscale * m_parent->column() - xscale * m_child->column() + 4,
|
Chris@53
|
36 yscale * m_parent->row() - yscale * m_child->row() - size + 4)
|
Chris@46
|
37 .normalized();
|
Chris@46
|
38 }
|
Chris@46
|
39
|
Chris@46
|
40 void
|
Chris@46
|
41 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
|
Chris@46
|
42 {
|
Chris@46
|
43 QPainterPath p;
|
Chris@53
|
44
|
Chris@53
|
45 paint->save();
|
Chris@53
|
46
|
Chris@53
|
47 ColourSet *colourSet = ColourSet::instance();
|
Chris@53
|
48 QColor branchColour = colourSet->getColourFor(m_child->getChangeset()->branch());
|
Chris@54
|
49
|
Chris@54
|
50 QTransform t = paint->worldTransform();
|
Chris@54
|
51 float scale = std::min(t.m11(), t.m22());
|
Chris@54
|
52 if (scale < 0.1) {
|
Chris@54
|
53 paint->setPen(QPen(branchColour, 0));
|
Chris@54
|
54 } else {
|
Chris@54
|
55 paint->setPen(QPen(branchColour, 2));
|
Chris@54
|
56 }
|
Chris@53
|
57
|
Chris@53
|
58 float xscale = 100;
|
Chris@53
|
59
|
Chris@53
|
60 float yscale = 90;
|
Chris@46
|
61 float size = 50;
|
Chris@53
|
62 float ygap = yscale - size;
|
Chris@53
|
63
|
Chris@53
|
64 int c_col = m_child->column(), c_row = m_child->row();
|
Chris@53
|
65 int p_col = m_parent->column(), p_row = m_parent->row();
|
Chris@53
|
66
|
Chris@53
|
67 float c_x = xscale * c_col + size/2;
|
Chris@53
|
68 float p_x = xscale * p_col + size/2;
|
Chris@53
|
69
|
Chris@53
|
70 p.moveTo(c_x, yscale * c_row + size);
|
Chris@53
|
71
|
Chris@53
|
72 if (p_col == c_col) {
|
Chris@53
|
73
|
Chris@53
|
74 p.lineTo(p_x, yscale * p_row);
|
Chris@53
|
75
|
Chris@53
|
76 } else if (m_type == Split || m_type == Normal) {
|
Chris@53
|
77
|
Chris@53
|
78 // place the bulk of the line on the child (i.e. branch) row
|
Chris@53
|
79
|
Chris@53
|
80 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
81 p.lineTo(c_x, yscale * p_row - ygap);
|
Chris@53
|
82 }
|
Chris@53
|
83
|
Chris@53
|
84 p.cubicTo(c_x, yscale * p_row,
|
Chris@53
|
85 p_x, yscale * p_row - ygap,
|
Chris@53
|
86 p_x, yscale * p_row);
|
Chris@53
|
87
|
Chris@53
|
88 } else if (m_type == Merge) {
|
Chris@53
|
89
|
Chris@53
|
90 // place bulk of the line on the parent row
|
Chris@53
|
91
|
Chris@53
|
92 p.cubicTo(c_x, yscale * c_row + size + ygap,
|
Chris@53
|
93 p_x, yscale * c_row + size,
|
Chris@53
|
94 p_x, yscale * c_row + size + ygap);
|
Chris@53
|
95
|
Chris@53
|
96 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
97 p.lineTo(p_x, yscale * p_row);
|
Chris@46
|
98 }
|
Chris@46
|
99 }
|
Chris@53
|
100
|
Chris@46
|
101 paint->drawPath(p);
|
Chris@53
|
102 paint->restore();
|
Chris@46
|
103 }
|
Chris@46
|
104
|
Chris@46
|
105
|