comparison src/connectionitem.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents connectionitem.cpp@be483734bde5
children ce6a70970808
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on HgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "connectionitem.h"
19 #include "uncommitteditem.h"
20
21 #include "changesetitem.h"
22 #include "changeset.h"
23 #include "colourset.h"
24
25 #include <QPainter>
26
27 QRectF
28 ConnectionItem::boundingRect() const
29 {
30 if (!m_parent || !(m_child || m_uncommitted)) return QRectF();
31 float xscale = 100;
32 float yscale = 90;
33 float size = 50;
34
35 int p_col = m_parent->column(), p_row = m_parent->row();
36 int c_col, c_row;
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)
47 .normalized();
48 }
49
50 void
51 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
52 {
53 if (!m_parent || !(m_child || m_uncommitted)) return;
54 QPainterPath p;
55
56 paint->save();
57
58 ColourSet *colourSet = ColourSet::instance();
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;
66
67 QTransform t = paint->worldTransform();
68 float scale = std::min(t.m11(), t.m22());
69 if (scale < 0.2) {
70 paint->setPen(QPen(branchColour, 0, ls));
71 } else {
72 paint->setPen(QPen(branchColour, 2, ls));
73 }
74
75 float xscale = 100;
76
77 float yscale = 90;
78 float size = 50;
79 float ygap = yscale - size - 2;
80
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 }
88
89 float c_x = xscale * c_col + size/2;
90 float p_x = xscale * p_col + size/2;
91
92 // ensure line reaches the box, even if it's in a small height --
93 // doesn't matter if we overshoot as the box is opaque and has a
94 // greater Z value
95 p.moveTo(c_x, yscale * c_row + size - 20);
96
97 p.lineTo(c_x, yscale * c_row + size);
98
99 if (p_col == c_col) {
100
101 p.lineTo(p_x, yscale * p_row);
102
103 } else if (m_type == Split || m_type == Normal) {
104
105 // place the bulk of the line on the child (i.e. branch) row
106
107 if (abs(p_row - c_row) > 1) {
108 p.lineTo(c_x, yscale * p_row - ygap);
109 }
110
111 p.cubicTo(c_x, yscale * p_row,
112 p_x, yscale * p_row - ygap,
113 p_x, yscale * p_row);
114
115 } else if (m_type == Merge) {
116
117 // place bulk of the line on the parent row
118
119 p.cubicTo(c_x, yscale * c_row + size + ygap,
120 p_x, yscale * c_row + size,
121 p_x, yscale * c_row + size + ygap);
122
123 if (abs(p_row - c_row) > 1) {
124 p.lineTo(p_x, yscale * p_row);
125 }
126 }
127
128 paint->drawPath(p);
129 paint->restore();
130 }
131
132