comparison src/changesetitem.cpp @ 387:ce6a70970808 item_appearance_adjustments

Use a plain small circle for merge commits
author Chris Cannam
date Tue, 24 May 2011 16:26:15 +0100
parents 7ef46fb73b48
children ef31a55c86b6
comparison
equal deleted inserted replaced
386:7ef46fb73b48 387:ce6a70970808
66 m_detail = new ChangesetDetailItem(m_changeset); 66 m_detail = new ChangesetDetailItem(m_changeset);
67 m_detail->setZValue(zValue() + 1); 67 m_detail->setZValue(zValue() + 1);
68 scene()->addItem(m_detail); 68 scene()->addItem(m_detail);
69 int w = 100; 69 int w = 100;
70 if (m_wide) w = 180; 70 if (m_wide) w = 180;
71 if (isMerge()) w = 60;
71 int h = 80; 72 int h = 80;
72 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, 73 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2,
73 // y() + 60); 74 // y() + 60);
74 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5, 75 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5,
75 y() - (m_detail->boundingRect().height() - h) / 2 + 0.5); 76 y() - (m_detail->boundingRect().height() - h) / 2 + 0.5);
238 void ChangesetItem::newBranchActivated() { emit newBranch(getId()); } 239 void ChangesetItem::newBranchActivated() { emit newBranch(getId()); }
239 240
240 void 241 void
241 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) 242 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
242 { 243 {
244 if (isMerge()) {
245 paintMerge(paint);
246 } else {
247 paintNormal(paint);
248 }
249 }
250
251 bool
252 ChangesetItem::isMerge() const
253 {
254 return (m_changeset && m_changeset->parents().size() > 1);
255 }
256
257 void
258 ChangesetItem::paintNormal(QPainter *paint)
259 {
243 paint->save(); 260 paint->save();
244 261
245 ColourSet *colourSet = ColourSet::instance(); 262 ColourSet *colourSet = ColourSet::instance();
246 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); 263 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
247 QColor userColour = colourSet->getColourFor(m_changeset->author()); 264 QColor userColour = colourSet->getColourFor(m_changeset->author());
389 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); 406 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
390 } 407 }
391 408
392 paint->restore(); 409 paint->restore();
393 } 410 }
411
412 void
413 ChangesetItem::paintMerge(QPainter *paint)
414 {
415 paint->save();
416
417 ColourSet *colourSet = ColourSet::instance();
418 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
419 QColor userColour = colourSet->getColourFor(m_changeset->author());
420
421 QFont f(m_font);
422
423 QTransform t = paint->worldTransform();
424 float scale = std::min(t.m11(), t.m22());
425 if (scale > 1.0) {
426 int ps = int((f.pixelSize() / scale) + 0.5);
427 if (ps < 8) ps = 8;
428 f.setPixelSize(ps);
429 }
430
431 bool showText = (scale >= 0.2);
432 bool showProperLines = (scale >= 0.1);
433
434 if (!showProperLines) {
435 paint->setPen(QPen(branchColour, 0));
436 } else {
437 paint->setPen(QPen(branchColour, 2));
438 }
439
440 paint->setFont(f);
441 QFontMetrics fm(f);
442 int fh = fm.height();
443 int size = fh * 2;
444 int x0 = -size/2 + 25;
445
446 paint->setBrush(Qt::white);
447 paint->drawEllipse(QRectF(x0, fh, size, size));
448
449 if (m_showBranch) {
450 // write branch name
451 paint->save();
452 f.setBold(true);
453 paint->setFont(f);
454 paint->setPen(QPen(branchColour));
455 QString branch = m_changeset->branch();
456 if (branch == "") branch = "default";
457 int wid = size * 3;
458 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
459 paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch);
460 f.setBold(false);
461 paint->restore();
462 }
463
464 paint->restore();
465 }
466