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