comparison src/connectionitem.cpp @ 516:2981d2defa61

Introduce a graphical representation for merge from a closed to an open branch (half a connection item)
author Chris Cannam
date Thu, 20 Oct 2011 12:04:47 +0100
parents 470829a21f98
children 533519ebc0cb
comparison
equal deleted inserted replaced
515:fc35aa6d433e 516:2981d2defa61
19 #include "uncommitteditem.h" 19 #include "uncommitteditem.h"
20 20
21 #include "changesetitem.h" 21 #include "changesetitem.h"
22 #include "changeset.h" 22 #include "changeset.h"
23 #include "colourset.h" 23 #include "colourset.h"
24 #include "textabbrev.h"
24 25
25 #include <QPainter> 26 #include <QPainter>
27 #include <QFont>
26 28
27 QRectF 29 QRectF
28 ConnectionItem::boundingRect() const 30 ConnectionItem::boundingRect() const
29 { 31 {
30 if (!m_parent || !(m_child || m_uncommitted)) return QRectF(); 32 if (!(m_child || m_uncommitted)) return QRectF();
31 float xscale = 100; 33 float xscale = 100;
32 float yscale = 90; 34 float yscale = 90;
33 float size = 50; 35 float size = 50;
34 36
35 int p_col = m_parent->column(), p_row = m_parent->row();
36 int c_col, c_row; 37 int c_col, c_row;
37 if (m_child) { 38 if (m_child) {
38 c_col = m_child->column(); c_row = m_child->row(); 39 c_col = m_child->column(); c_row = m_child->row();
39 } else { 40 } else {
40 c_col = m_uncommitted->column(); c_row = m_uncommitted->row(); 41 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
42 }
43
44 int p_col, p_row;
45 if (m_parent) {
46 p_col = m_parent->column(); p_row = m_parent->row();
47 } else {
48 p_col = c_col - 1; p_row = c_row + 1;
41 } 49 }
42 50
43 return QRectF(xscale * c_col + size/2 - 2, 51 return QRectF(xscale * c_col + size/2 - 2,
44 yscale * c_row + size - 22, 52 yscale * c_row + size - 22,
45 xscale * p_col - xscale * c_col + 6, 53 xscale * p_col - xscale * c_col + 6,
48 } 56 }
49 57
50 void 58 void
51 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) 59 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
52 { 60 {
53 if (!m_parent || !(m_child || m_uncommitted)) return; 61 if (!(m_child || m_uncommitted)) return;
54 QPainterPath p; 62 QPainterPath p;
55 63
56 paint->save(); 64 paint->save();
57 65
58 int alpha = 255; 66 int alpha = 255;
81 89
82 float yscale = 90; 90 float yscale = 90;
83 float size = 50; 91 float size = 50;
84 float ygap = yscale - size - 2; 92 float ygap = yscale - size - 2;
85 93
86 int p_col = m_parent->column(), p_row = m_parent->row();
87 int c_col, c_row; 94 int c_col, c_row;
88 if (m_child) { 95 if (m_child) {
89 c_col = m_child->column(); c_row = m_child->row(); 96 c_col = m_child->column(); c_row = m_child->row();
90 } else { 97 } else {
91 c_col = m_uncommitted->column(); c_row = m_uncommitted->row(); 98 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
99 }
100
101 int p_col, p_row;
102 if (m_parent) {
103 p_col = m_parent->column(); p_row = m_parent->row();
104 } else {
105 p_col = c_col - 1; p_row = c_row + 1;
92 } 106 }
93 107
94 float c_x = xscale * c_col + size/2; 108 float c_x = xscale * c_col + size/2;
95 float p_x = xscale * p_col + size/2; 109 float p_x = xscale * p_col + size/2;
96 110
128 if (abs(p_row - c_row) > 1) { 142 if (abs(p_row - c_row) > 1) {
129 p.lineTo(p_x, yscale * p_row); 143 p.lineTo(p_x, yscale * p_row);
130 } 144 }
131 } 145 }
132 146
133 // ensure line reaches the node -- again doesn't matter if we 147 if (m_parent) {
134 // overshoot
135 p.lineTo(p_x, yscale * p_row + 20);
136 148
149 // ensure line reaches the node -- again doesn't matter if we
150 // overshoot
151 p.lineTo(p_x, yscale * p_row + 20);
152
153 } else {
154
155 // no parent: merge from closed branch: draw only half the line
156 paint->setClipRect(QRectF((c_x + p_x)/2, yscale * c_row + size - 22,
157 xscale, yscale));
158 }
159
137 paint->drawPath(p); 160 paint->drawPath(p);
161
162 if (!m_parent) {
163
164 // merge from closed branch: draw branch name
165
166 paint->setClipping(false);
167
168 QFont f;
169 f.setPixelSize(11);
170 f.setBold(true);
171 f.setItalic(false);
172 paint->setFont(f);
173
174 QString branch = m_mergedBranch;
175 if (branch == "") branch = "default";
176 int wid = xscale;
177 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
178 paint->drawText((c_x + p_x)/2 - wid - 2,
179 yscale * c_row + size + ygap/2 + 2,
180 branch);
181 }
182
138 paint->restore(); 183 paint->restore();
139 } 184 }
140 185
141 186