Mercurial > hg > easyhg
comparison changesetitem.cpp @ 55:261bfb9481fe
* Make changeset item boxes wider if they have no neighbours.
Changeset item code is horrible -- items generally need
refactoring to take out hardcoded dimensions.
author | Chris Cannam |
---|---|
date | Fri, 12 Nov 2010 17:30:53 +0000 |
parents | 0e5fba6750c2 |
children | 1394c8cbf991 |
comparison
equal
deleted
inserted
replaced
54:0e5fba6750c2 | 55:261bfb9481fe |
---|---|
4 #include "colourset.h" | 4 #include "colourset.h" |
5 | 5 |
6 #include <QPainter> | 6 #include <QPainter> |
7 | 7 |
8 ChangesetItem::ChangesetItem(Changeset *cs) : | 8 ChangesetItem::ChangesetItem(Changeset *cs) : |
9 m_changeset(cs), m_column(0), m_row(0) | 9 m_changeset(cs), m_column(0), m_row(0), m_wide(false) |
10 { | 10 { |
11 m_font = QFont(); | 11 m_font = QFont(); |
12 m_font.setPixelSize(11); | 12 m_font.setPixelSize(11); |
13 m_font.setBold(false); | 13 m_font.setBold(false); |
14 m_font.setItalic(false); | 14 m_font.setItalic(false); |
15 } | 15 } |
16 | 16 |
17 QRectF | 17 QRectF |
18 ChangesetItem::boundingRect() const | 18 ChangesetItem::boundingRect() const |
19 { | 19 { |
20 return QRectF(-24, -30, 97, 79); | 20 int w = 100; |
21 if (m_wide) w = 180; | |
22 return QRectF(-((w-50)/2 - 1), -30, w - 3, 79); | |
21 } | 23 } |
22 | 24 |
23 void | 25 void |
24 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, | 26 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, |
25 QWidget *w) | 27 QWidget *w) |
47 } | 49 } |
48 | 50 |
49 paint->setFont(f); | 51 paint->setFont(f); |
50 QFontMetrics fm(f); | 52 QFontMetrics fm(f); |
51 int fh = fm.height(); | 53 int fh = fm.height(); |
52 | 54 |
53 QRectF r(-24, 0, 97, 49); | 55 int width = 100; |
56 if (m_wide) width = 180; | |
57 int x0 = -((width - 50) / 2 - 1); | |
58 | |
59 QRectF r(x0, 0, width - 3, 49); | |
54 paint->drawRect(r); | 60 paint->drawRect(r); |
55 | 61 |
56 if (scale < 0.1) { | 62 if (scale < 0.1) { |
57 paint->restore(); | 63 paint->restore(); |
58 return; | 64 return; |
60 | 66 |
61 if (m_changeset->children().empty()) { | 67 if (m_changeset->children().empty()) { |
62 f.setBold(true); | 68 f.setBold(true); |
63 paint->setFont(f); | 69 paint->setFont(f); |
64 QString branch = m_changeset->branch(); | 70 QString branch = m_changeset->branch(); |
65 int wid = 97; | 71 int wid = width - 3; |
66 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); | 72 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); |
67 paint->drawText(-24, -fh + fm.ascent() - 4, branch); | 73 paint->drawText(x0, -fh + fm.ascent() - 4, branch); |
68 f.setBold(false); | 74 f.setBold(false); |
69 } | 75 } |
70 | 76 |
71 paint->fillRect(QRectF(-23.5, 0.5, 96, fh - 0.5), QBrush(userColour)); | 77 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), |
78 QBrush(userColour)); | |
72 | 79 |
73 paint->setPen(QPen(Qt::white)); | 80 paint->setPen(QPen(Qt::white)); |
74 | 81 |
75 int wid = 95; | 82 int wid = width - 5; |
76 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid); | 83 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid); |
77 paint->drawText(-21, fm.ascent(), person); | 84 paint->drawText(x0 + 3, fm.ascent(), person); |
78 | 85 |
79 paint->setPen(QPen(Qt::black)); | 86 paint->setPen(QPen(Qt::black)); |
80 | 87 |
81 f.setItalic(true); | 88 f.setItalic(true); |
82 fm = QFontMetrics(f); | 89 fm = QFontMetrics(f); |
88 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), ""); | 95 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), ""); |
89 comment = comment.replace(QRegExp("\"$"), ""); | 96 comment = comment.replace(QRegExp("\"$"), ""); |
90 comment = comment.replace("\\\"", "\""); | 97 comment = comment.replace("\\\"", "\""); |
91 comment = comment.split('\n')[0]; | 98 comment = comment.split('\n')[0]; |
92 | 99 |
93 wid = 95; | 100 wid = width - 5; |
94 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd, | 101 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd, |
95 "...", 2); | 102 "...", 2); |
96 | 103 |
97 QStringList lines = comment.split('\n'); | 104 QStringList lines = comment.split('\n'); |
98 for (int i = 0; i < lines.size(); ++i) { | 105 for (int i = 0; i < lines.size(); ++i) { |
99 paint->drawText(-21, i * fh + fh + fm.ascent(), lines[i].trimmed()); | 106 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); |
100 } | 107 } |
101 | 108 |
102 paint->restore(); | 109 paint->restore(); |
103 } | 110 } |