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