annotate changesetitem.cpp @ 64:794db9353c7f

* Start rejigging the settings/repo-path dialog setup: startup dialog now asks for user name and email only
author Chris Cannam
date Wed, 17 Nov 2010 17:49:16 +0000
parents f583e44d9d31
children 5616a814c58b
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@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 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@43 19 #include "changeset.h"
Chris@53 20 #include "textabbrev.h"
Chris@53 21 #include "colourset.h"
Chris@43 22
Chris@43 23 #include <QPainter>
Chris@43 24
Chris@53 25 ChangesetItem::ChangesetItem(Changeset *cs) :
Chris@55 26 m_changeset(cs), m_column(0), m_row(0), m_wide(false)
Chris@53 27 {
Chris@53 28 m_font = QFont();
Chris@53 29 m_font.setPixelSize(11);
Chris@53 30 m_font.setBold(false);
Chris@53 31 m_font.setItalic(false);
Chris@53 32 }
Chris@53 33
Chris@43 34 QRectF
Chris@43 35 ChangesetItem::boundingRect() const
Chris@43 36 {
Chris@55 37 int w = 100;
Chris@55 38 if (m_wide) w = 180;
Chris@55 39 return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
Chris@43 40 }
Chris@43 41
Chris@43 42 void
Chris@43 43 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
Chris@43 44 QWidget *w)
Chris@43 45 {
Chris@53 46 paint->save();
Chris@53 47
Chris@53 48 ColourSet *colourSet = ColourSet::instance();
Chris@53 49 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
Chris@53 50 QColor userColour = colourSet->getColourFor(m_changeset->author());
Chris@53 51
Chris@53 52 QFont f(m_font);
Chris@53 53
Chris@54 54 QTransform t = paint->worldTransform();
Chris@53 55 float scale = std::min(t.m11(), t.m22());
Chris@53 56 if (scale > 1.0) {
Chris@53 57 int ps = int((f.pixelSize() / scale) + 0.5);
Chris@53 58 if (ps < 8) ps = 8;
Chris@53 59 f.setPixelSize(ps);
Chris@53 60 }
Chris@54 61
Chris@54 62 if (scale < 0.1) {
Chris@54 63 paint->setPen(QPen(branchColour, 0));
Chris@54 64 } else {
Chris@54 65 paint->setPen(QPen(branchColour, 2));
Chris@54 66 }
Chris@53 67
Chris@53 68 paint->setFont(f);
Chris@53 69 QFontMetrics fm(f);
Chris@53 70 int fh = fm.height();
Chris@55 71
Chris@55 72 int width = 100;
Chris@55 73 if (m_wide) width = 180;
Chris@55 74 int x0 = -((width - 50) / 2 - 1);
Chris@55 75
Chris@56 76 int height = 49;
Chris@56 77 QRectF r(x0, 0, width - 3, height);
Chris@53 78 paint->drawRect(r);
Chris@53 79
Chris@53 80 if (scale < 0.1) {
Chris@53 81 paint->restore();
Chris@53 82 return;
Chris@53 83 }
Chris@53 84
Chris@55 85 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
Chris@55 86 QBrush(userColour));
Chris@53 87
Chris@53 88 paint->setPen(QPen(Qt::white));
Chris@53 89
Chris@55 90 int wid = width - 5;
Chris@53 91 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
Chris@55 92 paint->drawText(x0 + 3, fm.ascent(), person);
Chris@53 93
Chris@53 94 paint->setPen(QPen(Qt::black));
Chris@53 95
Chris@56 96 if (m_changeset->children().empty()) {
Chris@56 97 // write branch name
Chris@56 98 f.setBold(true);
Chris@56 99 paint->setFont(f);
Chris@56 100 QString branch = m_changeset->branch();
Chris@56 101 int wid = width - 3;
Chris@56 102 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
Chris@56 103 paint->drawText(x0, -fh + fm.ascent() - 4, branch);
Chris@56 104 f.setBold(false);
Chris@56 105 }
Chris@56 106
Chris@56 107 // f.setItalic(true);
Chris@53 108 fm = QFontMetrics(f);
Chris@53 109 fh = fm.height();
Chris@53 110 paint->setFont(f);
Chris@53 111
Chris@53 112 QString comment = m_changeset->comment().trimmed();
Chris@53 113 comment = comment.replace("\\n", "\n");
Chris@53 114 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
Chris@53 115 comment = comment.replace(QRegExp("\"$"), "");
Chris@53 116 comment = comment.replace("\\\"", "\"");
Chris@53 117 comment = comment.split('\n')[0];
Chris@53 118
Chris@55 119 wid = width - 5;
Chris@56 120 int nlines = (height / fh) - 1;
Chris@56 121 if (nlines < 1) nlines = 1;
Chris@53 122 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
Chris@56 123 "...", nlines);
Chris@53 124
Chris@53 125 QStringList lines = comment.split('\n');
Chris@53 126 for (int i = 0; i < lines.size(); ++i) {
Chris@55 127 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
Chris@53 128 }
Chris@53 129
Chris@53 130 paint->restore();
Chris@43 131 }