Mercurial > hg > easyhg
comparison changesetitem.cpp @ 53:3c46b2ac45d3
* Put proper labels &c in changeset items; colour branches and users; etc
author | Chris Cannam |
---|---|
date | Fri, 12 Nov 2010 16:48:18 +0000 |
parents | bd3accba9b3f |
children | 0e5fba6750c2 |
comparison
equal
deleted
inserted
replaced
52:384420567575 | 53:3c46b2ac45d3 |
---|---|
1 #include "changesetitem.h" | 1 #include "changesetitem.h" |
2 #include "changeset.h" | 2 #include "changeset.h" |
3 #include "textabbrev.h" | |
4 #include "colourset.h" | |
3 | 5 |
4 #include <QPainter> | 6 #include <QPainter> |
7 | |
8 ChangesetItem::ChangesetItem(Changeset *cs) : | |
9 m_changeset(cs), m_column(0), m_row(0) | |
10 { | |
11 m_font = QFont(); | |
12 m_font.setPixelSize(11); | |
13 m_font.setBold(false); | |
14 m_font.setItalic(false); | |
15 } | |
5 | 16 |
6 QRectF | 17 QRectF |
7 ChangesetItem::boundingRect() const | 18 ChangesetItem::boundingRect() const |
8 { | 19 { |
9 return QRectF(0, 0, 250, 50); | 20 return QRectF(-24, -30, 97, 79); |
10 } | 21 } |
11 | 22 |
12 void | 23 void |
13 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, | 24 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, |
14 QWidget *w) | 25 QWidget *w) |
15 { | 26 { |
16 // paint->drawText(50, 0, m_changeset->comment()); | 27 QTransform t = paint->worldTransform(); |
17 paint->drawText(5, 15, m_changeset->authorName()); | |
18 paint->drawText(5, 30, m_changeset->branch()); | |
19 paint->drawRect(QRectF(0, 0, 50, 50)); | |
20 | 28 |
21 // paint->drawRect(QRectF(0, 0, 50, 50)); | 29 paint->save(); |
30 | |
31 ColourSet *colourSet = ColourSet::instance(); | |
32 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); | |
33 QColor userColour = colourSet->getColourFor(m_changeset->author()); | |
34 | |
35 paint->setPen(QPen(branchColour, 2)); | |
36 | |
37 QFont f(m_font); | |
38 | |
39 float scale = std::min(t.m11(), t.m22()); | |
40 if (scale > 1.0) { | |
41 int ps = int((f.pixelSize() / scale) + 0.5); | |
42 if (ps < 8) ps = 8; | |
43 f.setPixelSize(ps); | |
44 } | |
45 | |
46 paint->setFont(f); | |
47 QFontMetrics fm(f); | |
48 int fh = fm.height(); | |
49 | |
50 QRectF r(-24, 0, 97, 49); | |
51 paint->drawRect(r); | |
52 | |
53 if (scale < 0.1) { | |
54 paint->restore(); | |
55 return; | |
56 } | |
57 | |
58 if (m_changeset->children().empty()) { | |
59 f.setBold(true); | |
60 paint->setFont(f); | |
61 paint->drawText(-24, -fh + fm.ascent() - 4, m_changeset->branch()); | |
62 f.setBold(false); | |
63 } | |
64 | |
65 paint->fillRect(QRectF(-23.5, 0.5, 96, fh - 0.5), QBrush(userColour)); | |
66 | |
67 paint->setPen(QPen(Qt::white)); | |
68 | |
69 int wid = 95; | |
70 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid); | |
71 paint->drawText(-21, fm.ascent(), person); | |
72 | |
73 paint->setPen(QPen(Qt::black)); | |
74 | |
75 f.setItalic(true); | |
76 fm = QFontMetrics(f); | |
77 fh = fm.height(); | |
78 paint->setFont(f); | |
79 | |
80 QString comment = m_changeset->comment().trimmed(); | |
81 comment = comment.replace("\\n", "\n"); | |
82 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), ""); | |
83 comment = comment.replace(QRegExp("\"$"), ""); | |
84 comment = comment.replace("\\\"", "\""); | |
85 comment = comment.split('\n')[0]; | |
86 | |
87 wid = 95; | |
88 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd, | |
89 "...", 2); | |
90 | |
91 QStringList lines = comment.split('\n'); | |
92 for (int i = 0; i < lines.size(); ++i) { | |
93 paint->drawText(-21, i * fh + fh + fm.ascent(), lines[i].trimmed()); | |
94 } | |
95 | |
96 paint->restore(); | |
22 } | 97 } |