annotate 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
rev   line source
Chris@46 1
Chris@46 2
Chris@46 3 #include "connectionitem.h"
Chris@46 4
Chris@46 5 #include "changesetitem.h"
Chris@46 6
Chris@46 7 #include <QPainter>
Chris@46 8
Chris@46 9 QRectF
Chris@46 10 ConnectionItem::boundingRect() const
Chris@46 11 {
Chris@46 12 if (!m_parent || !m_child) return QRectF();
Chris@46 13 float scale = 100;
Chris@46 14 float size = 50;
Chris@46 15 return QRectF(scale * m_child->column() + size/2 - 2,
Chris@46 16 scale * m_child->row() + size - 2,
Chris@46 17 scale * m_parent->column() - scale * m_child->column() + 4,
Chris@46 18 scale * m_parent->row() - scale * m_child->row() - size + 4)
Chris@46 19 .normalized();
Chris@46 20 }
Chris@46 21
Chris@46 22 void
Chris@46 23 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
Chris@46 24 {
Chris@46 25 QPainterPath p;
Chris@46 26 float scale = 100;
Chris@46 27 float size = 50;
Chris@46 28 p.moveTo(scale * m_child->column() + size/2,
Chris@46 29 scale * m_child->row() + size);
Chris@46 30 if (m_parent->column() == m_child->column()) {
Chris@46 31 p.lineTo(scale * m_parent->column() + size/2,
Chris@46 32 scale * m_parent->row());
Chris@46 33 } else {
Chris@46 34 p.cubicTo(scale * m_child->column() + size/2,
Chris@46 35 scale * m_child->row() + size + size,
Chris@46 36 scale * m_parent->column() + size/2,
Chris@46 37 scale * m_child->row() + size,
Chris@46 38 scale * m_parent->column() + size/2,
Chris@46 39 scale * m_child->row() + scale);
Chris@46 40 if (abs(m_parent->row() - m_child->row()) > 1) {
Chris@46 41 p.lineTo(scale * m_parent->column() + size/2,
Chris@46 42 scale * m_parent->row());
Chris@46 43 }
Chris@46 44 }
Chris@46 45 paint->drawPath(p);
Chris@46 46 }
Chris@46 47
Chris@46 48