comparison connectionitem.cpp @ 145:644bd31e8301

* Include the uncommitted item in general graph layout (in case it is not at the head, when other items will need to avoid it)
author Chris Cannam
date Wed, 01 Dec 2010 17:41:14 +0000
parents f583e44d9d31
children 70fe12873106
comparison
equal deleted inserted replaced
143:f61f032b06f9 145:644bd31e8301
14 License, or (at your option) any later version. See the file 14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information. 15 COPYING included with this distribution for more information.
16 */ 16 */
17 17
18 #include "connectionitem.h" 18 #include "connectionitem.h"
19 #include "uncommitteditem.h"
19 20
20 #include "changesetitem.h" 21 #include "changesetitem.h"
21 #include "changeset.h" 22 #include "changeset.h"
22 #include "colourset.h" 23 #include "colourset.h"
23 24
24 #include <QPainter> 25 #include <QPainter>
25 26
26 QRectF 27 QRectF
27 ConnectionItem::boundingRect() const 28 ConnectionItem::boundingRect() const
28 { 29 {
29 if (!m_parent || !m_child) return QRectF(); 30 if (!m_parent || !(m_child || m_uncommitted)) return QRectF();
30 float xscale = 100; 31 float xscale = 100;
31 float yscale = 90; 32 float yscale = 90;
32 float size = 50; 33 float size = 50;
33 return QRectF(xscale * m_child->column() + size/2 - 2, 34
34 yscale * m_child->row() + size - 2, 35 int p_col = m_parent->column(), p_row = m_parent->row();
35 xscale * m_parent->column() - xscale * m_child->column() + 4, 36 int c_col, c_row;
36 yscale * m_parent->row() - yscale * m_child->row() - size + 4) 37 if (m_child) {
38 c_col = m_child->column(); c_row = m_child->row();
39 } else {
40 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
41 }
42
43 return QRectF(xscale * c_col + size/2 - 2,
44 yscale * c_row + size - 2,
45 xscale * p_col - xscale * c_col + 4,
46 yscale * p_row - yscale * c_row - size + 4)
37 .normalized(); 47 .normalized();
38 } 48 }
39 49
40 void 50 void
41 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) 51 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
42 { 52 {
53 if (!m_parent || !(m_child || m_uncommitted)) return;
43 QPainterPath p; 54 QPainterPath p;
44 55
45 paint->save(); 56 paint->save();
46 57
47 ColourSet *colourSet = ColourSet::instance(); 58 ColourSet *colourSet = ColourSet::instance();
48 QColor branchColour = colourSet->getColourFor(m_child->getChangeset()->branch()); 59 QString branch;
60 if (m_child) branch = m_child->getChangeset()->branch();
61 else branch = m_uncommitted->branch();
62 QColor branchColour = colourSet->getColourFor(branch);
63
64 Qt::PenStyle ls = Qt::SolidLine;
65 if (!m_child) ls = Qt::DashLine;
49 66
50 QTransform t = paint->worldTransform(); 67 QTransform t = paint->worldTransform();
51 float scale = std::min(t.m11(), t.m22()); 68 float scale = std::min(t.m11(), t.m22());
52 if (scale < 0.1) { 69 if (scale < 0.2) {
53 paint->setPen(QPen(branchColour, 0)); 70 paint->setPen(QPen(branchColour, 0, ls));
54 } else { 71 } else {
55 paint->setPen(QPen(branchColour, 2)); 72 paint->setPen(QPen(branchColour, 2, ls));
56 } 73 }
57 74
58 float xscale = 100; 75 float xscale = 100;
59 76
60 float yscale = 90; 77 float yscale = 90;
61 float size = 50; 78 float size = 50;
62 float ygap = yscale - size; 79 float ygap = yscale - size;
63 80
64 int c_col = m_child->column(), c_row = m_child->row();
65 int p_col = m_parent->column(), p_row = m_parent->row(); 81 int p_col = m_parent->column(), p_row = m_parent->row();
82 int c_col, c_row;
83 if (m_child) {
84 c_col = m_child->column(); c_row = m_child->row();
85 } else {
86 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
87 }
66 88
67 float c_x = xscale * c_col + size/2; 89 float c_x = xscale * c_col + size/2;
68 float p_x = xscale * p_col + size/2; 90 float p_x = xscale * p_col + size/2;
69 91
70 p.moveTo(c_x, yscale * c_row + size); 92 p.moveTo(c_x, yscale * c_row + size);