annotate src/changesetitem.cpp @ 678:c0b46d0514a7 scale

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