Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@57
|
17
|
Chris@43
|
18 #include "changesetitem.h"
|
Chris@281
|
19 #include "changesetscene.h"
|
Chris@117
|
20 #include "changesetdetailitem.h"
|
Chris@43
|
21 #include "changeset.h"
|
Chris@53
|
22 #include "textabbrev.h"
|
Chris@53
|
23 #include "colourset.h"
|
Chris@117
|
24 #include "debug.h"
|
Chris@43
|
25
|
Chris@43
|
26 #include <QPainter>
|
Chris@117
|
27 #include <QGraphicsScene>
|
Chris@132
|
28 #include <QGraphicsSceneMouseEvent>
|
Chris@140
|
29 #include <QMenu>
|
Chris@140
|
30 #include <QAction>
|
Chris@140
|
31 #include <QLabel>
|
Chris@140
|
32 #include <QWidgetAction>
|
Chris@153
|
33 #include <QApplication>
|
Chris@153
|
34 #include <QClipboard>
|
Chris@43
|
35
|
Chris@390
|
36 QImage *ChangesetItem::m_star = 0;
|
Chris@390
|
37
|
Chris@53
|
38 ChangesetItem::ChangesetItem(Changeset *cs) :
|
Chris@117
|
39 m_changeset(cs), m_detail(0),
|
Chris@133
|
40 m_showBranch(false), m_column(0), m_row(0), m_wide(false),
|
Chris@510
|
41 m_current(false), m_closing(false), m_new(false)
|
Chris@53
|
42 {
|
Chris@53
|
43 m_font = QFont();
|
Chris@53
|
44 m_font.setPixelSize(11);
|
Chris@53
|
45 m_font.setBold(false);
|
Chris@53
|
46 m_font.setItalic(false);
|
Chris@168
|
47 setCursor(Qt::ArrowCursor);
|
Chris@390
|
48
|
Chris@390
|
49 if (!m_star) m_star = new QImage(":images/star.png");
|
Chris@53
|
50 }
|
Chris@53
|
51
|
Chris@141
|
52 QString
|
Chris@141
|
53 ChangesetItem::getId()
|
Chris@141
|
54 {
|
Chris@141
|
55 return m_changeset->id();
|
Chris@141
|
56 }
|
Chris@141
|
57
|
Chris@43
|
58 QRectF
|
Chris@43
|
59 ChangesetItem::boundingRect() const
|
Chris@43
|
60 {
|
Chris@55
|
61 int w = 100;
|
Chris@55
|
62 if (m_wide) w = 180;
|
Chris@250
|
63 return QRectF(-((w-50)/2 - 1), -30, w - 3, 90);
|
Chris@43
|
64 }
|
Chris@43
|
65
|
Chris@43
|
66 void
|
Chris@119
|
67 ChangesetItem::showDetail()
|
Chris@117
|
68 {
|
Chris@119
|
69 if (m_detail) return;
|
Chris@117
|
70 m_detail = new ChangesetDetailItem(m_changeset);
|
Chris@117
|
71 m_detail->setZValue(zValue() + 1);
|
Chris@117
|
72 scene()->addItem(m_detail);
|
Chris@117
|
73 int w = 100;
|
Chris@117
|
74 if (m_wide) w = 180;
|
Chris@508
|
75 if (isMerge() || isClosingCommit()) w = 60;
|
Chris@124
|
76 int h = 80;
|
Chris@124
|
77 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2,
|
Chris@124
|
78 // y() + 60);
|
Chris@124
|
79 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5,
|
Chris@430
|
80 y() - (m_detail->boundingRect().height() - h) / 3 + 0.5);
|
Chris@119
|
81 emit detailShown();
|
Chris@119
|
82 }
|
Chris@119
|
83
|
Chris@119
|
84 void
|
Chris@119
|
85 ChangesetItem::hideDetail()
|
Chris@119
|
86 {
|
Chris@124
|
87 if (!m_detail) return;
|
Chris@124
|
88 scene()->removeItem(m_detail);
|
Chris@119
|
89 delete m_detail;
|
Chris@119
|
90 m_detail = 0;
|
Chris@119
|
91 emit detailHidden();
|
Chris@119
|
92 }
|
Chris@119
|
93
|
Chris@119
|
94 void
|
Chris@119
|
95 ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
Chris@119
|
96 {
|
Chris@119
|
97 DEBUG << "ChangesetItem::mousePressEvent" << endl;
|
Chris@132
|
98 if (e->button() == Qt::LeftButton) {
|
Chris@132
|
99 if (m_detail) {
|
Chris@132
|
100 hideDetail();
|
Chris@132
|
101 } else {
|
Chris@132
|
102 showDetail();
|
Chris@132
|
103 }
|
Chris@119
|
104 }
|
Chris@117
|
105 }
|
Chris@117
|
106
|
Chris@117
|
107 void
|
Chris@474
|
108 ChangesetItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
|
Chris@140
|
109 {
|
Chris@474
|
110 if (m_detail) {
|
Chris@474
|
111 hideDetail();
|
Chris@474
|
112 }
|
Chris@474
|
113
|
Chris@153
|
114 m_parentDiffActions.clear();
|
Chris@288
|
115 m_summaryActions.clear();
|
Chris@153
|
116
|
Chris@140
|
117 QMenu *menu = new QMenu;
|
Chris@165
|
118 QLabel *label = new QLabel(tr("<qt><b> Revision: </b>%1</qt>")
|
Chris@165
|
119 .arg(Changeset::hashOf(m_changeset->id())));
|
Chris@141
|
120 QWidgetAction *wa = new QWidgetAction(menu);
|
Chris@140
|
121 wa->setDefaultWidget(label);
|
Chris@140
|
122 menu->addAction(wa);
|
Chris@140
|
123 menu->addSeparator();
|
Chris@141
|
124
|
Chris@153
|
125 QAction *copyId = menu->addAction(tr("Copy identifier to clipboard"));
|
Chris@153
|
126 connect(copyId, SIGNAL(triggered()), this, SLOT(copyIdActivated()));
|
Chris@141
|
127
|
Chris@289
|
128 QAction *stat = menu->addAction(tr("Summarise changes"));
|
Chris@289
|
129 connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryActivated()));
|
Chris@289
|
130
|
Chris@289
|
131 menu->addSeparator();
|
Chris@289
|
132
|
Chris@281
|
133 QStringList parents = m_changeset->parents();
|
Chris@153
|
134
|
Chris@288
|
135 QString leftId, rightId;
|
Chris@288
|
136 bool havePositions = false;
|
Chris@288
|
137
|
Chris@281
|
138 if (parents.size() > 1) {
|
Chris@281
|
139 ChangesetScene *cs = dynamic_cast<ChangesetScene *>(scene());
|
Chris@281
|
140 if (cs && parents.size() == 2) {
|
Chris@281
|
141 ChangesetItem *i0 = cs->getItemById(parents[0]);
|
Chris@281
|
142 ChangesetItem *i1 = cs->getItemById(parents[1]);
|
Chris@281
|
143 if (i0 && i1) {
|
Chris@281
|
144 if (i0->x() < i1->x()) {
|
Chris@281
|
145 leftId = parents[0];
|
Chris@281
|
146 rightId = parents[1];
|
Chris@281
|
147 } else {
|
Chris@281
|
148 leftId = parents[1];
|
Chris@281
|
149 rightId = parents[0];
|
Chris@281
|
150 }
|
Chris@281
|
151 havePositions = true;
|
Chris@281
|
152 }
|
Chris@281
|
153 }
|
Chris@288
|
154 }
|
Chris@281
|
155
|
Chris@288
|
156 if (parents.size() > 1) {
|
Chris@288
|
157 if (havePositions) {
|
Chris@281
|
158
|
Chris@288
|
159 QAction *diff = menu->addAction(tr("Diff to left parent"));
|
Chris@288
|
160 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
|
Chris@288
|
161 m_parentDiffActions[diff] = leftId;
|
Chris@281
|
162
|
Chris@288
|
163 diff = menu->addAction(tr("Diff to right parent"));
|
Chris@288
|
164 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
|
Chris@288
|
165 m_parentDiffActions[diff] = rightId;
|
Chris@281
|
166
|
Chris@281
|
167 } else {
|
Chris@281
|
168
|
Chris@281
|
169 foreach (QString parentId, parents) {
|
Chris@288
|
170 QString text = tr("Diff to parent %1").arg(Changeset::hashOf(parentId));
|
Chris@288
|
171 QAction *diff = menu->addAction(text);
|
Chris@288
|
172 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
|
Chris@288
|
173 m_parentDiffActions[diff] = parentId;
|
Chris@281
|
174 }
|
Chris@153
|
175 }
|
Chris@153
|
176
|
Chris@153
|
177 } else {
|
Chris@153
|
178
|
Chris@288
|
179 QAction *diff = menu->addAction(tr("Diff to parent"));
|
Chris@288
|
180 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
|
Chris@153
|
181 }
|
Chris@153
|
182
|
Chris@153
|
183 QAction *diffCurrent = menu->addAction(tr("Diff to current working folder"));
|
Chris@141
|
184 connect(diffCurrent, SIGNAL(triggered()), this, SLOT(diffToCurrentActivated()));
|
Chris@141
|
185
|
Chris@140
|
186 menu->addSeparator();
|
Chris@141
|
187
|
Chris@153
|
188 QAction *update = menu->addAction(tr("Update to this revision"));
|
Chris@153
|
189 connect(update, SIGNAL(triggered()), this, SLOT(updateActivated()));
|
Chris@153
|
190
|
Chris@140
|
191 QAction *merge = menu->addAction(tr("Merge from here to current"));
|
Chris@141
|
192 connect(merge, SIGNAL(triggered()), this, SLOT(mergeActivated()));
|
Chris@153
|
193
|
Chris@153
|
194 menu->addSeparator();
|
Chris@153
|
195
|
Chris@278
|
196 QAction *branch = menu->addAction(tr("Start new branch..."));
|
Chris@278
|
197 branch->setEnabled(m_current);
|
Chris@278
|
198 connect(branch, SIGNAL(triggered()), this, SLOT(newBranchActivated()));
|
Chris@278
|
199
|
Chris@153
|
200 QAction *tag = menu->addAction(tr("Add tag..."));
|
Chris@141
|
201 connect(tag, SIGNAL(triggered()), this, SLOT(tagActivated()));
|
Chris@141
|
202
|
Chris@474
|
203 ungrabMouse();
|
Chris@474
|
204
|
Chris@148
|
205 menu->exec(QCursor::pos());
|
Chris@140
|
206 }
|
Chris@140
|
207
|
Chris@153
|
208 void
|
Chris@153
|
209 ChangesetItem::copyIdActivated()
|
Chris@153
|
210 {
|
Chris@153
|
211 QClipboard *clipboard = QApplication::clipboard();
|
Chris@153
|
212 clipboard->setText(Changeset::hashOf(m_changeset->id()));
|
Chris@153
|
213 }
|
Chris@153
|
214
|
Chris@153
|
215 void ChangesetItem::diffToParentActivated()
|
Chris@153
|
216 {
|
Chris@153
|
217 QAction *a = qobject_cast<QAction *>(sender());
|
Chris@153
|
218 QString parentId;
|
Chris@153
|
219 if (m_parentDiffActions.contains(a)) {
|
Chris@153
|
220 parentId = m_parentDiffActions[a];
|
Chris@153
|
221 DEBUG << "ChangesetItem::diffToParentActivated: specific parent "
|
Chris@153
|
222 << parentId << " selected" << endl;
|
Chris@153
|
223 } else {
|
Chris@153
|
224 parentId = m_changeset->parents()[0];
|
Chris@153
|
225 DEBUG << "ChangesetItem::diffToParentActivated: "
|
Chris@153
|
226 << "no specific parent selected, using first parent "
|
Chris@153
|
227 << parentId << endl;
|
Chris@153
|
228 }
|
Chris@153
|
229
|
Chris@153
|
230 emit diffToParent(getId(), parentId);
|
Chris@153
|
231 }
|
Chris@153
|
232
|
Chris@289
|
233 void ChangesetItem::showSummaryActivated()
|
Chris@288
|
234 {
|
Chris@289
|
235 emit showSummary(m_changeset);
|
Chris@288
|
236 }
|
Chris@288
|
237
|
Chris@141
|
238 void ChangesetItem::updateActivated() { emit updateTo(getId()); }
|
Chris@141
|
239 void ChangesetItem::diffToCurrentActivated() { emit diffToCurrent(getId()); }
|
Chris@141
|
240 void ChangesetItem::mergeActivated() { emit mergeFrom(getId()); }
|
Chris@141
|
241 void ChangesetItem::tagActivated() { emit tag(getId()); }
|
Chris@278
|
242 void ChangesetItem::newBranchActivated() { emit newBranch(getId()); }
|
Chris@141
|
243
|
Chris@140
|
244 void
|
Chris@288
|
245 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
|
Chris@43
|
246 {
|
Chris@508
|
247 if (isClosingCommit() || isMerge()) {
|
Chris@508
|
248 paintSimple(paint);
|
Chris@387
|
249 } else {
|
Chris@387
|
250 paintNormal(paint);
|
Chris@387
|
251 }
|
Chris@387
|
252 }
|
Chris@387
|
253
|
Chris@387
|
254 bool
|
Chris@387
|
255 ChangesetItem::isMerge() const
|
Chris@387
|
256 {
|
Chris@387
|
257 return (m_changeset && m_changeset->parents().size() > 1);
|
Chris@387
|
258 }
|
Chris@387
|
259
|
Chris@510
|
260 bool
|
Chris@510
|
261 ChangesetItem::isClosed() const
|
Chris@510
|
262 {
|
Chris@510
|
263 return (m_changeset && m_changeset->closed());
|
Chris@510
|
264 }
|
Chris@510
|
265
|
Chris@387
|
266 void
|
Chris@387
|
267 ChangesetItem::paintNormal(QPainter *paint)
|
Chris@387
|
268 {
|
Chris@53
|
269 paint->save();
|
Chris@53
|
270
|
Chris@506
|
271 int alpha = 255;
|
Chris@510
|
272 if (isClosed()) alpha = 90;
|
Chris@506
|
273
|
Chris@53
|
274 ColourSet *colourSet = ColourSet::instance();
|
Chris@53
|
275 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
|
Chris@128
|
276 QColor userColour = colourSet->getColourFor(m_changeset->author());
|
Chris@53
|
277
|
Chris@506
|
278 branchColour.setAlpha(alpha);
|
Chris@506
|
279 userColour.setAlpha(alpha);
|
Chris@506
|
280
|
Chris@53
|
281 QFont f(m_font);
|
Chris@53
|
282
|
Chris@54
|
283 QTransform t = paint->worldTransform();
|
Chris@53
|
284 float scale = std::min(t.m11(), t.m22());
|
Chris@53
|
285 if (scale > 1.0) {
|
Chris@53
|
286 int ps = int((f.pixelSize() / scale) + 0.5);
|
Chris@53
|
287 if (ps < 8) ps = 8;
|
Chris@53
|
288 f.setPixelSize(ps);
|
Chris@53
|
289 }
|
Chris@54
|
290
|
Chris@250
|
291 bool showText = (scale >= 0.2);
|
Chris@250
|
292 bool showProperLines = (scale >= 0.1);
|
Chris@250
|
293
|
Chris@250
|
294 if (!showProperLines) {
|
Chris@54
|
295 paint->setPen(QPen(branchColour, 0));
|
Chris@54
|
296 } else {
|
Chris@54
|
297 paint->setPen(QPen(branchColour, 2));
|
Chris@54
|
298 }
|
Chris@53
|
299
|
Chris@53
|
300 paint->setFont(f);
|
Chris@53
|
301 QFontMetrics fm(f);
|
Chris@53
|
302 int fh = fm.height();
|
Chris@55
|
303
|
Chris@55
|
304 int width = 100;
|
Chris@55
|
305 if (m_wide) width = 180;
|
Chris@55
|
306 int x0 = -((width - 50) / 2 - 1);
|
Chris@55
|
307
|
Chris@250
|
308 int textwid = width - 7;
|
Chris@250
|
309
|
Chris@250
|
310 QString comment;
|
Chris@250
|
311 QStringList lines;
|
Chris@250
|
312 int lineCount = 3;
|
Chris@250
|
313
|
Chris@250
|
314 if (showText) {
|
Chris@250
|
315
|
Chris@250
|
316 comment = m_changeset->comment().trimmed();
|
Chris@250
|
317 comment = comment.replace("\\n", " ");
|
Chris@250
|
318 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
|
Chris@250
|
319 comment = comment.replace(QRegExp("\"$"), "");
|
Chris@250
|
320 comment = comment.replace("\\\"", "\"");
|
Chris@250
|
321
|
Chris@250
|
322 comment = TextAbbrev::abbreviate(comment, fm, textwid,
|
Chris@250
|
323 TextAbbrev::ElideEnd, "...", 3);
|
Chris@250
|
324 // abbreviate() changes this (ouch!), restore it
|
Chris@250
|
325 textwid = width - 5;
|
Chris@250
|
326
|
Chris@250
|
327 lines = comment.split('\n');
|
Chris@250
|
328 lineCount = lines.size();
|
Chris@250
|
329
|
Chris@250
|
330 if (lineCount < 2) lineCount = 2;
|
Chris@250
|
331 }
|
Chris@250
|
332
|
Chris@250
|
333 int height = (lineCount + 1) * fh + 2;
|
Chris@56
|
334 QRectF r(x0, 0, width - 3, height);
|
Chris@250
|
335
|
Chris@250
|
336 if (showProperLines) {
|
Chris@250
|
337
|
Chris@393
|
338 if (m_new) {
|
Chris@396
|
339 paint->setBrush(QColor(255, 255, 220));
|
Chris@393
|
340 } else {
|
Chris@393
|
341 paint->setBrush(Qt::white);
|
Chris@393
|
342 }
|
Chris@250
|
343
|
Chris@250
|
344 if (m_current) {
|
Chris@386
|
345 paint->drawRoundedRect(QRectF(x0 - 4, -4, width + 5, height + 8),
|
Chris@386
|
346 10, 10);
|
Chris@393
|
347 if (m_new) {
|
Chris@393
|
348 paint->save();
|
Chris@393
|
349 paint->setPen(Qt::yellow);
|
Chris@393
|
350 paint->setBrush(Qt::NoBrush);
|
Chris@393
|
351 paint->drawRoundedRect(QRectF(x0 - 2, -2, width + 1, height + 4),
|
Chris@393
|
352 10, 10);
|
Chris@393
|
353 paint->restore();
|
Chris@393
|
354 }
|
Chris@250
|
355 }
|
Chris@250
|
356 }
|
Chris@250
|
357
|
Chris@250
|
358 if (!showText) {
|
Chris@386
|
359 paint->drawRoundedRect(r, 7, 7);
|
Chris@53
|
360 paint->restore();
|
Chris@53
|
361 return;
|
Chris@53
|
362 }
|
Chris@53
|
363
|
Chris@386
|
364 paint->save();
|
Chris@386
|
365 paint->setPen(Qt::NoPen);
|
Chris@386
|
366 paint->drawRoundedRect(r, 7, 7);
|
Chris@386
|
367 paint->setBrush(QBrush(userColour));
|
Chris@386
|
368 paint->drawRoundedRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), 7, 7);
|
chris@391
|
369 paint->drawRect(QRectF(x0 + 0.5, fh/2.0, width - 4, fh/2.0));
|
Chris@386
|
370 paint->restore();
|
Chris@53
|
371
|
Chris@53
|
372 paint->setPen(QPen(Qt::white));
|
Chris@53
|
373
|
Chris@250
|
374 QString person = TextAbbrev::abbreviate(m_changeset->authorName(),
|
Chris@250
|
375 fm, textwid);
|
Chris@55
|
376 paint->drawText(x0 + 3, fm.ascent(), person);
|
Chris@53
|
377
|
Chris@506
|
378 QColor textColour = Qt::black;
|
Chris@506
|
379 textColour.setAlpha(alpha);
|
Chris@506
|
380
|
Chris@506
|
381 paint->setPen(QPen(textColour));
|
Chris@53
|
382
|
Chris@147
|
383 QStringList tags = m_changeset->tags();
|
Chris@147
|
384 if (!tags.empty()) {
|
Chris@147
|
385 QStringList nonTipTags;
|
Chris@147
|
386 foreach (QString t, tags) {
|
Chris@147
|
387 // I'm not convinced that showing the tip tag really
|
Chris@147
|
388 // works; I think perhaps it confuses as much as it
|
Chris@147
|
389 // illuminates. But also, our current implementation
|
Chris@147
|
390 // doesn't interact well with it because it moves -- it's
|
Chris@147
|
391 // the one thing that can actually (in normal use) change
|
Chris@147
|
392 // inside an existing changeset record even during an
|
Chris@147
|
393 // incremental update
|
Chris@147
|
394 if (t != "tip") nonTipTags.push_back(t);
|
Chris@147
|
395 }
|
Chris@147
|
396 if (!nonTipTags.empty()) {
|
Chris@147
|
397 QString tagText = nonTipTags.join(" ").trimmed();
|
Chris@147
|
398 int tw = fm.width(tagText);
|
Chris@147
|
399 paint->fillRect(QRectF(x0 + width - 8 - tw, 1, tw + 4, fh - 1),
|
Chris@147
|
400 QBrush(Qt::yellow));
|
Chris@147
|
401 paint->drawText(x0 + width - 6 - tw, fm.ascent(), tagText);
|
Chris@147
|
402 }
|
Chris@128
|
403 }
|
Chris@128
|
404
|
Chris@386
|
405 paint->setPen(QPen(branchColour, 2));
|
Chris@386
|
406 paint->setBrush(Qt::NoBrush);
|
Chris@386
|
407 paint->drawRoundedRect(r, 7, 7);
|
Chris@386
|
408
|
Chris@74
|
409 if (m_showBranch) {
|
Chris@56
|
410 // write branch name
|
Chris@153
|
411 paint->save();
|
Chris@56
|
412 f.setBold(true);
|
Chris@56
|
413 paint->setFont(f);
|
Chris@153
|
414 paint->setPen(QPen(branchColour));
|
Chris@56
|
415 QString branch = m_changeset->branch();
|
Chris@74
|
416 if (branch == "") branch = "default";
|
Chris@56
|
417 int wid = width - 3;
|
Chris@56
|
418 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
|
Chris@56
|
419 paint->drawText(x0, -fh + fm.ascent() - 4, branch);
|
Chris@56
|
420 f.setBold(false);
|
Chris@153
|
421 paint->restore();
|
Chris@56
|
422 }
|
Chris@56
|
423
|
chris@392
|
424 if (m_current && showProperLines) {
|
chris@392
|
425 paint->setRenderHint(QPainter::SmoothPixmapTransform, true);
|
chris@392
|
426 int starSize = fh * 1.5;
|
chris@392
|
427 paint->drawImage(QRectF(x0 + width - starSize,
|
chris@392
|
428 -fh, starSize, starSize),
|
chris@392
|
429 *m_star);
|
chris@392
|
430 }
|
chris@392
|
431
|
Chris@53
|
432 paint->setFont(f);
|
Chris@53
|
433
|
Chris@53
|
434 for (int i = 0; i < lines.size(); ++i) {
|
Chris@55
|
435 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
|
Chris@53
|
436 }
|
Chris@53
|
437
|
Chris@53
|
438 paint->restore();
|
Chris@43
|
439 }
|
Chris@387
|
440
|
Chris@387
|
441 void
|
Chris@508
|
442 ChangesetItem::paintSimple(QPainter *paint)
|
Chris@387
|
443 {
|
Chris@387
|
444 paint->save();
|
Chris@506
|
445
|
Chris@506
|
446 int alpha = 255;
|
Chris@510
|
447 if (isClosed()) alpha = 90;
|
Chris@387
|
448
|
Chris@387
|
449 ColourSet *colourSet = ColourSet::instance();
|
Chris@387
|
450 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
|
Chris@387
|
451 QColor userColour = colourSet->getColourFor(m_changeset->author());
|
Chris@387
|
452
|
Chris@506
|
453 branchColour.setAlpha(alpha);
|
Chris@506
|
454 userColour.setAlpha(alpha);
|
Chris@506
|
455
|
Chris@387
|
456 QFont f(m_font);
|
Chris@387
|
457
|
Chris@387
|
458 QTransform t = paint->worldTransform();
|
Chris@387
|
459 float scale = std::min(t.m11(), t.m22());
|
Chris@387
|
460 if (scale > 1.0) {
|
Chris@387
|
461 int ps = int((f.pixelSize() / scale) + 0.5);
|
Chris@387
|
462 if (ps < 8) ps = 8;
|
Chris@387
|
463 f.setPixelSize(ps);
|
Chris@387
|
464 }
|
Chris@387
|
465
|
Chris@387
|
466 bool showText = (scale >= 0.2);
|
Chris@387
|
467 bool showProperLines = (scale >= 0.1);
|
Chris@387
|
468
|
Chris@387
|
469 if (!showProperLines) {
|
Chris@387
|
470 paint->setPen(QPen(branchColour, 0));
|
Chris@387
|
471 } else {
|
Chris@387
|
472 paint->setPen(QPen(branchColour, 2));
|
Chris@387
|
473 }
|
Chris@387
|
474
|
Chris@387
|
475 paint->setFont(f);
|
Chris@387
|
476 QFontMetrics fm(f);
|
Chris@387
|
477 int fh = fm.height();
|
Chris@387
|
478 int size = fh * 2;
|
Chris@387
|
479 int x0 = -size/2 + 25;
|
Chris@387
|
480
|
Chris@393
|
481 if (m_new) {
|
Chris@396
|
482 paint->setBrush(QColor(255, 255, 220));
|
Chris@393
|
483 } else {
|
Chris@393
|
484 paint->setBrush(Qt::white);
|
Chris@393
|
485 }
|
Chris@390
|
486
|
Chris@390
|
487 if (showProperLines) {
|
Chris@390
|
488
|
Chris@390
|
489 if (m_current) {
|
Chris@508
|
490 if (isClosingCommit()) {
|
Chris@508
|
491 paint->drawRect(QRectF(x0 - 4, fh - 4, size + 8, size + 8));
|
Chris@508
|
492 } else {
|
Chris@508
|
493 paint->drawEllipse(QRectF(x0 - 4, fh - 4, size + 8, size + 8));
|
Chris@508
|
494 }
|
Chris@508
|
495
|
Chris@393
|
496 if (m_new) {
|
Chris@393
|
497 paint->save();
|
Chris@393
|
498 paint->setPen(Qt::yellow);
|
Chris@393
|
499 paint->setBrush(Qt::NoBrush);
|
Chris@508
|
500 if (isClosingCommit()) {
|
Chris@508
|
501 paint->drawRect(QRectF(x0 - 2, fh - 2, size + 4, size + 4));
|
Chris@508
|
502 } else {
|
Chris@508
|
503 paint->drawEllipse(QRectF(x0 - 2, fh - 2, size + 4, size + 4));
|
Chris@508
|
504 }
|
Chris@393
|
505 paint->restore();
|
Chris@393
|
506 }
|
Chris@390
|
507 }
|
Chris@390
|
508 }
|
Chris@390
|
509
|
Chris@508
|
510 if (isClosingCommit()) {
|
Chris@508
|
511 paint->drawRect(QRectF(x0, fh, size, size));
|
Chris@508
|
512 } else {
|
Chris@508
|
513 paint->drawEllipse(QRectF(x0, fh, size, size));
|
Chris@508
|
514 }
|
Chris@387
|
515
|
Chris@387
|
516 if (m_showBranch) {
|
Chris@387
|
517 // write branch name
|
Chris@387
|
518 paint->save();
|
Chris@387
|
519 f.setBold(true);
|
Chris@387
|
520 paint->setFont(f);
|
Chris@387
|
521 paint->setPen(QPen(branchColour));
|
Chris@387
|
522 QString branch = m_changeset->branch();
|
Chris@387
|
523 if (branch == "") branch = "default";
|
Chris@387
|
524 int wid = size * 3;
|
Chris@387
|
525 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
|
Chris@387
|
526 paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch);
|
Chris@387
|
527 f.setBold(false);
|
Chris@387
|
528 paint->restore();
|
Chris@387
|
529 }
|
Chris@387
|
530
|
Chris@390
|
531 if (m_current && showProperLines) {
|
Chris@390
|
532 paint->setRenderHint(QPainter::SmoothPixmapTransform, true);
|
Chris@390
|
533 int starSize = fh * 1.5;
|
Chris@390
|
534 paint->drawImage(QRectF(x0 + size - starSize/2,
|
Chris@390
|
535 0, starSize, starSize),
|
Chris@390
|
536 *m_star);
|
Chris@390
|
537 }
|
Chris@390
|
538
|
Chris@387
|
539 paint->restore();
|
Chris@387
|
540 }
|
Chris@387
|
541
|