Mercurial > hg > easyhg
comparison src/changesetitem.cpp @ 400:07eaf4e6003a
Merge from branch "item_appearance_adjustments"
author | Chris Cannam |
---|---|
date | Wed, 25 May 2011 14:59:09 +0100 |
parents | 1e73b5911631 |
children | c3276f8998ee |
comparison
equal
deleted
inserted
replaced
385:5cc0d897eb26 | 400:07eaf4e6003a |
---|---|
31 #include <QLabel> | 31 #include <QLabel> |
32 #include <QWidgetAction> | 32 #include <QWidgetAction> |
33 #include <QApplication> | 33 #include <QApplication> |
34 #include <QClipboard> | 34 #include <QClipboard> |
35 | 35 |
36 QImage *ChangesetItem::m_star = 0; | |
37 | |
36 ChangesetItem::ChangesetItem(Changeset *cs) : | 38 ChangesetItem::ChangesetItem(Changeset *cs) : |
37 m_changeset(cs), m_detail(0), | 39 m_changeset(cs), m_detail(0), |
38 m_showBranch(false), m_column(0), m_row(0), m_wide(false), | 40 m_showBranch(false), m_column(0), m_row(0), m_wide(false), |
39 m_current(false), m_new(false) | 41 m_current(false), m_new(false) |
40 { | 42 { |
41 m_font = QFont(); | 43 m_font = QFont(); |
42 m_font.setPixelSize(11); | 44 m_font.setPixelSize(11); |
43 m_font.setBold(false); | 45 m_font.setBold(false); |
44 m_font.setItalic(false); | 46 m_font.setItalic(false); |
45 setCursor(Qt::ArrowCursor); | 47 setCursor(Qt::ArrowCursor); |
48 | |
49 if (!m_star) m_star = new QImage(":images/star.png"); | |
46 } | 50 } |
47 | 51 |
48 QString | 52 QString |
49 ChangesetItem::getId() | 53 ChangesetItem::getId() |
50 { | 54 { |
66 m_detail = new ChangesetDetailItem(m_changeset); | 70 m_detail = new ChangesetDetailItem(m_changeset); |
67 m_detail->setZValue(zValue() + 1); | 71 m_detail->setZValue(zValue() + 1); |
68 scene()->addItem(m_detail); | 72 scene()->addItem(m_detail); |
69 int w = 100; | 73 int w = 100; |
70 if (m_wide) w = 180; | 74 if (m_wide) w = 180; |
75 if (isMerge()) w = 60; | |
71 int h = 80; | 76 int h = 80; |
72 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, | 77 // m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, |
73 // y() + 60); | 78 // y() + 60); |
74 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5, | 79 m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5, |
75 y() - (m_detail->boundingRect().height() - h) / 2 + 0.5); | 80 y() - (m_detail->boundingRect().height() - h) / 2 + 0.5); |
238 void ChangesetItem::newBranchActivated() { emit newBranch(getId()); } | 243 void ChangesetItem::newBranchActivated() { emit newBranch(getId()); } |
239 | 244 |
240 void | 245 void |
241 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) | 246 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) |
242 { | 247 { |
248 if (isMerge()) { | |
249 paintMerge(paint); | |
250 } else { | |
251 paintNormal(paint); | |
252 } | |
253 } | |
254 | |
255 bool | |
256 ChangesetItem::isMerge() const | |
257 { | |
258 return (m_changeset && m_changeset->parents().size() > 1); | |
259 } | |
260 | |
261 void | |
262 ChangesetItem::paintNormal(QPainter *paint) | |
263 { | |
243 paint->save(); | 264 paint->save(); |
244 | 265 |
245 ColourSet *colourSet = ColourSet::instance(); | 266 ColourSet *colourSet = ColourSet::instance(); |
246 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); | 267 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); |
247 QColor userColour = colourSet->getColourFor(m_changeset->author()); | 268 QColor userColour = colourSet->getColourFor(m_changeset->author()); |
301 int height = (lineCount + 1) * fh + 2; | 322 int height = (lineCount + 1) * fh + 2; |
302 QRectF r(x0, 0, width - 3, height); | 323 QRectF r(x0, 0, width - 3, height); |
303 | 324 |
304 if (showProperLines) { | 325 if (showProperLines) { |
305 | 326 |
306 paint->setBrush(Qt::white); | 327 if (m_new) { |
328 paint->setBrush(QColor(255, 255, 220)); | |
329 } else { | |
330 paint->setBrush(Qt::white); | |
331 } | |
307 | 332 |
308 if (m_current) { | 333 if (m_current) { |
309 paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8)); | 334 paint->drawRoundedRect(QRectF(x0 - 4, -4, width + 5, height + 8), |
310 } | 335 10, 10); |
311 | 336 if (m_new) { |
312 if (m_new) { | 337 paint->save(); |
313 paint->save(); | 338 paint->setPen(Qt::yellow); |
314 paint->setPen(Qt::yellow); | 339 paint->setBrush(Qt::NoBrush); |
315 paint->setBrush(Qt::NoBrush); | 340 paint->drawRoundedRect(QRectF(x0 - 2, -2, width + 1, height + 4), |
316 paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4)); | 341 10, 10); |
317 paint->restore(); | 342 paint->restore(); |
318 } | 343 } |
319 } | 344 } |
320 | 345 } |
321 paint->drawRect(r); | |
322 | 346 |
323 if (!showText) { | 347 if (!showText) { |
348 paint->drawRoundedRect(r, 7, 7); | |
324 paint->restore(); | 349 paint->restore(); |
325 return; | 350 return; |
326 } | 351 } |
327 | 352 |
328 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), | 353 paint->save(); |
329 QBrush(userColour)); | 354 paint->setPen(Qt::NoPen); |
355 paint->drawRoundedRect(r, 7, 7); | |
356 paint->setBrush(QBrush(userColour)); | |
357 paint->drawRoundedRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), 7, 7); | |
358 paint->drawRect(QRectF(x0 + 0.5, fh/2.0, width - 4, fh/2.0)); | |
359 paint->restore(); | |
330 | 360 |
331 paint->setPen(QPen(Qt::white)); | 361 paint->setPen(QPen(Qt::white)); |
332 | 362 |
333 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), | 363 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), |
334 fm, textwid); | 364 fm, textwid); |
355 paint->fillRect(QRectF(x0 + width - 8 - tw, 1, tw + 4, fh - 1), | 385 paint->fillRect(QRectF(x0 + width - 8 - tw, 1, tw + 4, fh - 1), |
356 QBrush(Qt::yellow)); | 386 QBrush(Qt::yellow)); |
357 paint->drawText(x0 + width - 6 - tw, fm.ascent(), tagText); | 387 paint->drawText(x0 + width - 6 - tw, fm.ascent(), tagText); |
358 } | 388 } |
359 } | 389 } |
390 | |
391 paint->setPen(QPen(branchColour, 2)); | |
392 paint->setBrush(Qt::NoBrush); | |
393 paint->drawRoundedRect(r, 7, 7); | |
360 | 394 |
361 if (m_showBranch) { | 395 if (m_showBranch) { |
362 // write branch name | 396 // write branch name |
363 paint->save(); | 397 paint->save(); |
364 f.setBold(true); | 398 f.setBold(true); |
371 paint->drawText(x0, -fh + fm.ascent() - 4, branch); | 405 paint->drawText(x0, -fh + fm.ascent() - 4, branch); |
372 f.setBold(false); | 406 f.setBold(false); |
373 paint->restore(); | 407 paint->restore(); |
374 } | 408 } |
375 | 409 |
410 if (m_current && showProperLines) { | |
411 paint->setRenderHint(QPainter::SmoothPixmapTransform, true); | |
412 int starSize = fh * 1.5; | |
413 paint->drawImage(QRectF(x0 + width - starSize, | |
414 -fh, starSize, starSize), | |
415 *m_star); | |
416 } | |
417 | |
376 paint->setFont(f); | 418 paint->setFont(f); |
377 | 419 |
378 for (int i = 0; i < lines.size(); ++i) { | 420 for (int i = 0; i < lines.size(); ++i) { |
379 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); | 421 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); |
380 } | 422 } |
381 | 423 |
382 paint->restore(); | 424 paint->restore(); |
383 } | 425 } |
426 | |
427 void | |
428 ChangesetItem::paintMerge(QPainter *paint) | |
429 { | |
430 paint->save(); | |
431 | |
432 ColourSet *colourSet = ColourSet::instance(); | |
433 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); | |
434 QColor userColour = colourSet->getColourFor(m_changeset->author()); | |
435 | |
436 QFont f(m_font); | |
437 | |
438 QTransform t = paint->worldTransform(); | |
439 float scale = std::min(t.m11(), t.m22()); | |
440 if (scale > 1.0) { | |
441 int ps = int((f.pixelSize() / scale) + 0.5); | |
442 if (ps < 8) ps = 8; | |
443 f.setPixelSize(ps); | |
444 } | |
445 | |
446 bool showText = (scale >= 0.2); | |
447 bool showProperLines = (scale >= 0.1); | |
448 | |
449 if (!showProperLines) { | |
450 paint->setPen(QPen(branchColour, 0)); | |
451 } else { | |
452 paint->setPen(QPen(branchColour, 2)); | |
453 } | |
454 | |
455 paint->setFont(f); | |
456 QFontMetrics fm(f); | |
457 int fh = fm.height(); | |
458 int size = fh * 2; | |
459 int x0 = -size/2 + 25; | |
460 | |
461 if (m_new) { | |
462 paint->setBrush(QColor(255, 255, 220)); | |
463 } else { | |
464 paint->setBrush(Qt::white); | |
465 } | |
466 | |
467 if (showProperLines) { | |
468 | |
469 if (m_current) { | |
470 paint->drawEllipse(QRectF(x0 - 4, fh - 4, size + 8, size + 8)); | |
471 | |
472 if (m_new) { | |
473 paint->save(); | |
474 paint->setPen(Qt::yellow); | |
475 paint->setBrush(Qt::NoBrush); | |
476 paint->drawEllipse(QRectF(x0 - 2, fh - 2, size + 4, size + 4)); | |
477 paint->restore(); | |
478 } | |
479 } | |
480 } | |
481 | |
482 paint->drawEllipse(QRectF(x0, fh, size, size)); | |
483 | |
484 if (m_showBranch) { | |
485 // write branch name | |
486 paint->save(); | |
487 f.setBold(true); | |
488 paint->setFont(f); | |
489 paint->setPen(QPen(branchColour)); | |
490 QString branch = m_changeset->branch(); | |
491 if (branch == "") branch = "default"; | |
492 int wid = size * 3; | |
493 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); | |
494 paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch); | |
495 f.setBold(false); | |
496 paint->restore(); | |
497 } | |
498 | |
499 if (m_current && showProperLines) { | |
500 paint->setRenderHint(QPainter::SmoothPixmapTransform, true); | |
501 int starSize = fh * 1.5; | |
502 paint->drawImage(QRectF(x0 + size - starSize/2, | |
503 0, starSize, starSize), | |
504 *m_star); | |
505 } | |
506 | |
507 paint->restore(); | |
508 } | |
509 |