Chris@43
|
1 #include "changesetitem.h"
|
Chris@43
|
2 #include "changeset.h"
|
Chris@53
|
3 #include "textabbrev.h"
|
Chris@53
|
4 #include "colourset.h"
|
Chris@43
|
5
|
Chris@43
|
6 #include <QPainter>
|
Chris@43
|
7
|
Chris@53
|
8 ChangesetItem::ChangesetItem(Changeset *cs) :
|
Chris@55
|
9 m_changeset(cs), m_column(0), m_row(0), m_wide(false)
|
Chris@53
|
10 {
|
Chris@53
|
11 m_font = QFont();
|
Chris@53
|
12 m_font.setPixelSize(11);
|
Chris@53
|
13 m_font.setBold(false);
|
Chris@53
|
14 m_font.setItalic(false);
|
Chris@53
|
15 }
|
Chris@53
|
16
|
Chris@43
|
17 QRectF
|
Chris@43
|
18 ChangesetItem::boundingRect() const
|
Chris@43
|
19 {
|
Chris@55
|
20 int w = 100;
|
Chris@55
|
21 if (m_wide) w = 180;
|
Chris@55
|
22 return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
|
Chris@43
|
23 }
|
Chris@43
|
24
|
Chris@43
|
25 void
|
Chris@43
|
26 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
|
Chris@43
|
27 QWidget *w)
|
Chris@43
|
28 {
|
Chris@53
|
29 paint->save();
|
Chris@53
|
30
|
Chris@53
|
31 ColourSet *colourSet = ColourSet::instance();
|
Chris@53
|
32 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
|
Chris@53
|
33 QColor userColour = colourSet->getColourFor(m_changeset->author());
|
Chris@53
|
34
|
Chris@53
|
35 QFont f(m_font);
|
Chris@53
|
36
|
Chris@54
|
37 QTransform t = paint->worldTransform();
|
Chris@53
|
38 float scale = std::min(t.m11(), t.m22());
|
Chris@53
|
39 if (scale > 1.0) {
|
Chris@53
|
40 int ps = int((f.pixelSize() / scale) + 0.5);
|
Chris@53
|
41 if (ps < 8) ps = 8;
|
Chris@53
|
42 f.setPixelSize(ps);
|
Chris@53
|
43 }
|
Chris@54
|
44
|
Chris@54
|
45 if (scale < 0.1) {
|
Chris@54
|
46 paint->setPen(QPen(branchColour, 0));
|
Chris@54
|
47 } else {
|
Chris@54
|
48 paint->setPen(QPen(branchColour, 2));
|
Chris@54
|
49 }
|
Chris@53
|
50
|
Chris@53
|
51 paint->setFont(f);
|
Chris@53
|
52 QFontMetrics fm(f);
|
Chris@53
|
53 int fh = fm.height();
|
Chris@55
|
54
|
Chris@55
|
55 int width = 100;
|
Chris@55
|
56 if (m_wide) width = 180;
|
Chris@55
|
57 int x0 = -((width - 50) / 2 - 1);
|
Chris@55
|
58
|
Chris@56
|
59 int height = 49;
|
Chris@56
|
60 QRectF r(x0, 0, width - 3, height);
|
Chris@53
|
61 paint->drawRect(r);
|
Chris@53
|
62
|
Chris@53
|
63 if (scale < 0.1) {
|
Chris@53
|
64 paint->restore();
|
Chris@53
|
65 return;
|
Chris@53
|
66 }
|
Chris@53
|
67
|
Chris@55
|
68 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
|
Chris@55
|
69 QBrush(userColour));
|
Chris@53
|
70
|
Chris@53
|
71 paint->setPen(QPen(Qt::white));
|
Chris@53
|
72
|
Chris@55
|
73 int wid = width - 5;
|
Chris@53
|
74 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
|
Chris@55
|
75 paint->drawText(x0 + 3, fm.ascent(), person);
|
Chris@53
|
76
|
Chris@53
|
77 paint->setPen(QPen(Qt::black));
|
Chris@53
|
78
|
Chris@56
|
79 if (m_changeset->children().empty()) {
|
Chris@56
|
80 // write branch name
|
Chris@56
|
81 f.setBold(true);
|
Chris@56
|
82 paint->setFont(f);
|
Chris@56
|
83 QString branch = m_changeset->branch();
|
Chris@56
|
84 int wid = width - 3;
|
Chris@56
|
85 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
|
Chris@56
|
86 paint->drawText(x0, -fh + fm.ascent() - 4, branch);
|
Chris@56
|
87 f.setBold(false);
|
Chris@56
|
88 }
|
Chris@56
|
89
|
Chris@56
|
90 // f.setItalic(true);
|
Chris@53
|
91 fm = QFontMetrics(f);
|
Chris@53
|
92 fh = fm.height();
|
Chris@53
|
93 paint->setFont(f);
|
Chris@53
|
94
|
Chris@53
|
95 QString comment = m_changeset->comment().trimmed();
|
Chris@53
|
96 comment = comment.replace("\\n", "\n");
|
Chris@53
|
97 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
|
Chris@53
|
98 comment = comment.replace(QRegExp("\"$"), "");
|
Chris@53
|
99 comment = comment.replace("\\\"", "\"");
|
Chris@53
|
100 comment = comment.split('\n')[0];
|
Chris@53
|
101
|
Chris@55
|
102 wid = width - 5;
|
Chris@56
|
103 int nlines = (height / fh) - 1;
|
Chris@56
|
104 if (nlines < 1) nlines = 1;
|
Chris@53
|
105 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
|
Chris@56
|
106 "...", nlines);
|
Chris@53
|
107
|
Chris@53
|
108 QStringList lines = comment.split('\n');
|
Chris@53
|
109 for (int i = 0; i < lines.size(); ++i) {
|
Chris@55
|
110 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
|
Chris@53
|
111 }
|
Chris@53
|
112
|
Chris@53
|
113 paint->restore();
|
Chris@43
|
114 }
|