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@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 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@145
|
19 #include "uncommitteditem.h"
|
Chris@46
|
20
|
Chris@46
|
21 #include "changesetitem.h"
|
Chris@53
|
22 #include "changeset.h"
|
Chris@53
|
23 #include "colourset.h"
|
Chris@46
|
24
|
Chris@46
|
25 #include <QPainter>
|
Chris@46
|
26
|
Chris@46
|
27 QRectF
|
Chris@46
|
28 ConnectionItem::boundingRect() const
|
Chris@46
|
29 {
|
Chris@145
|
30 if (!m_parent || !(m_child || m_uncommitted)) return QRectF();
|
Chris@53
|
31 float xscale = 100;
|
Chris@53
|
32 float yscale = 90;
|
Chris@46
|
33 float size = 50;
|
Chris@145
|
34
|
Chris@145
|
35 int p_col = m_parent->column(), p_row = m_parent->row();
|
Chris@145
|
36 int c_col, c_row;
|
Chris@145
|
37 if (m_child) {
|
Chris@145
|
38 c_col = m_child->column(); c_row = m_child->row();
|
Chris@145
|
39 } else {
|
Chris@145
|
40 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
|
Chris@145
|
41 }
|
Chris@145
|
42
|
Chris@145
|
43 return QRectF(xscale * c_col + size/2 - 2,
|
Chris@145
|
44 yscale * c_row + size - 2,
|
Chris@145
|
45 xscale * p_col - xscale * c_col + 4,
|
Chris@145
|
46 yscale * p_row - yscale * c_row - size + 4)
|
Chris@46
|
47 .normalized();
|
Chris@46
|
48 }
|
Chris@46
|
49
|
Chris@46
|
50 void
|
Chris@46
|
51 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
|
Chris@46
|
52 {
|
Chris@145
|
53 if (!m_parent || !(m_child || m_uncommitted)) return;
|
Chris@46
|
54 QPainterPath p;
|
Chris@53
|
55
|
Chris@53
|
56 paint->save();
|
Chris@53
|
57
|
Chris@53
|
58 ColourSet *colourSet = ColourSet::instance();
|
Chris@145
|
59 QString branch;
|
Chris@145
|
60 if (m_child) branch = m_child->getChangeset()->branch();
|
Chris@145
|
61 else branch = m_uncommitted->branch();
|
Chris@145
|
62 QColor branchColour = colourSet->getColourFor(branch);
|
Chris@145
|
63
|
Chris@145
|
64 Qt::PenStyle ls = Qt::SolidLine;
|
Chris@145
|
65 if (!m_child) ls = Qt::DashLine;
|
Chris@54
|
66
|
Chris@54
|
67 QTransform t = paint->worldTransform();
|
Chris@54
|
68 float scale = std::min(t.m11(), t.m22());
|
Chris@145
|
69 if (scale < 0.2) {
|
Chris@145
|
70 paint->setPen(QPen(branchColour, 0, ls));
|
Chris@54
|
71 } else {
|
Chris@145
|
72 paint->setPen(QPen(branchColour, 2, ls));
|
Chris@54
|
73 }
|
Chris@53
|
74
|
Chris@53
|
75 float xscale = 100;
|
Chris@53
|
76
|
Chris@53
|
77 float yscale = 90;
|
Chris@46
|
78 float size = 50;
|
Chris@153
|
79 float ygap = yscale - size - 2;
|
Chris@53
|
80
|
Chris@53
|
81 int p_col = m_parent->column(), p_row = m_parent->row();
|
Chris@145
|
82 int c_col, c_row;
|
Chris@145
|
83 if (m_child) {
|
Chris@145
|
84 c_col = m_child->column(); c_row = m_child->row();
|
Chris@145
|
85 } else {
|
Chris@145
|
86 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
|
Chris@145
|
87 }
|
Chris@53
|
88
|
Chris@53
|
89 float c_x = xscale * c_col + size/2;
|
Chris@53
|
90 float p_x = xscale * p_col + size/2;
|
Chris@53
|
91
|
Chris@53
|
92 p.moveTo(c_x, yscale * c_row + size);
|
Chris@53
|
93
|
Chris@53
|
94 if (p_col == c_col) {
|
Chris@53
|
95
|
Chris@53
|
96 p.lineTo(p_x, yscale * p_row);
|
Chris@53
|
97
|
Chris@53
|
98 } else if (m_type == Split || m_type == Normal) {
|
Chris@53
|
99
|
Chris@53
|
100 // place the bulk of the line on the child (i.e. branch) row
|
Chris@53
|
101
|
Chris@53
|
102 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
103 p.lineTo(c_x, yscale * p_row - ygap);
|
Chris@53
|
104 }
|
Chris@53
|
105
|
Chris@53
|
106 p.cubicTo(c_x, yscale * p_row,
|
Chris@53
|
107 p_x, yscale * p_row - ygap,
|
Chris@53
|
108 p_x, yscale * p_row);
|
Chris@53
|
109
|
Chris@53
|
110 } else if (m_type == Merge) {
|
Chris@53
|
111
|
Chris@53
|
112 // place bulk of the line on the parent row
|
Chris@53
|
113
|
Chris@53
|
114 p.cubicTo(c_x, yscale * c_row + size + ygap,
|
Chris@53
|
115 p_x, yscale * c_row + size,
|
Chris@53
|
116 p_x, yscale * c_row + size + ygap);
|
Chris@53
|
117
|
Chris@53
|
118 if (abs(p_row - c_row) > 1) {
|
Chris@53
|
119 p.lineTo(p_x, yscale * p_row);
|
Chris@46
|
120 }
|
Chris@46
|
121 }
|
Chris@53
|
122
|
Chris@46
|
123 paint->drawPath(p);
|
Chris@53
|
124 paint->restore();
|
Chris@46
|
125 }
|
Chris@46
|
126
|
Chris@46
|
127
|