comparison connectionitem.cpp @ 46:bd3accba9b3f

* Better layout for branches; spline connection paths
author Chris Cannam
date Wed, 10 Nov 2010 17:11:41 +0000
parents
children 3c46b2ac45d3
comparison
equal deleted inserted replaced
45:4286836bb3c9 46:bd3accba9b3f
1
2
3 #include "connectionitem.h"
4
5 #include "changesetitem.h"
6
7 #include <QPainter>
8
9 QRectF
10 ConnectionItem::boundingRect() const
11 {
12 if (!m_parent || !m_child) return QRectF();
13 float scale = 100;
14 float size = 50;
15 return QRectF(scale * m_child->column() + size/2 - 2,
16 scale * m_child->row() + size - 2,
17 scale * m_parent->column() - scale * m_child->column() + 4,
18 scale * m_parent->row() - scale * m_child->row() - size + 4)
19 .normalized();
20 }
21
22 void
23 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
24 {
25 QPainterPath p;
26 float scale = 100;
27 float size = 50;
28 p.moveTo(scale * m_child->column() + size/2,
29 scale * m_child->row() + size);
30 if (m_parent->column() == m_child->column()) {
31 p.lineTo(scale * m_parent->column() + size/2,
32 scale * m_parent->row());
33 } else {
34 p.cubicTo(scale * m_child->column() + size/2,
35 scale * m_child->row() + size + size,
36 scale * m_parent->column() + size/2,
37 scale * m_child->row() + size,
38 scale * m_parent->column() + size/2,
39 scale * m_child->row() + scale);
40 if (abs(m_parent->row() - m_child->row()) > 1) {
41 p.lineTo(scale * m_parent->column() + size/2,
42 scale * m_parent->row());
43 }
44 }
45 paint->drawPath(p);
46 }
47
48