annotate changesetdetailitem.cpp @ 117:d5db15bf250c

* Start to sketch thing that shows the details of a changeset in the history view
author Chris Cannam
date Fri, 26 Nov 2010 22:46:29 +0000
parents
children 9734fb0d6fff
rev   line source
Chris@117 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@117 2
Chris@117 3 /*
Chris@117 4 EasyMercurial
Chris@117 5
Chris@117 6 Based on HgExplorer by Jari Korhonen
Chris@117 7 Copyright (c) 2010 Jari Korhonen
Chris@117 8 Copyright (c) 2010 Chris Cannam
Chris@117 9 Copyright (c) 2010 Queen Mary, University of London
Chris@117 10
Chris@117 11 This program is free software; you can redistribute it and/or
Chris@117 12 modify it under the terms of the GNU General Public License as
Chris@117 13 published by the Free Software Foundation; either version 2 of the
Chris@117 14 License, or (at your option) any later version. See the file
Chris@117 15 COPYING included with this distribution for more information.
Chris@117 16 */
Chris@117 17
Chris@117 18 #include "changesetdetailitem.h"
Chris@117 19 #include "changeset.h"
Chris@117 20 #include "textabbrev.h"
Chris@117 21 #include "colourset.h"
Chris@117 22 #include "debug.h"
Chris@117 23
Chris@117 24 #include <QPainter>
Chris@117 25
Chris@117 26 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
Chris@117 27 m_changeset(cs)
Chris@117 28 {
Chris@117 29 m_font = QFont();
Chris@117 30 m_font.setPixelSize(11);
Chris@117 31 m_font.setBold(false);
Chris@117 32 m_font.setItalic(false);
Chris@117 33 }
Chris@117 34
Chris@117 35 QRectF
Chris@117 36 ChangesetDetailItem::boundingRect() const
Chris@117 37 {
Chris@117 38 return QRectF(0, 0, 350, 200);
Chris@117 39 }
Chris@117 40
Chris@117 41 void
Chris@117 42 ChangesetDetailItem::paint(QPainter *paint,
Chris@117 43 const QStyleOptionGraphicsItem *option,
Chris@117 44 QWidget *w)
Chris@117 45 {
Chris@117 46 paint->save();
Chris@117 47
Chris@117 48 ColourSet *colourSet = ColourSet::instance();
Chris@117 49 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
Chris@117 50 QColor userColour = colourSet->getColourFor(m_changeset->author());
Chris@117 51
Chris@117 52 QFont f(m_font);
Chris@117 53
Chris@117 54 QTransform t = paint->worldTransform();
Chris@117 55 float scale = std::min(t.m11(), t.m22());
Chris@117 56 if (scale > 1.0) {
Chris@117 57 int ps = int((f.pixelSize() / scale) + 0.5);
Chris@117 58 if (ps < 8) ps = 8;
Chris@117 59 f.setPixelSize(ps);
Chris@117 60 }
Chris@117 61
Chris@117 62 if (scale < 0.1) {
Chris@117 63 paint->setPen(QPen(branchColour, 0));
Chris@117 64 } else {
Chris@117 65 paint->setPen(QPen(branchColour, 2));
Chris@117 66 }
Chris@117 67
Chris@117 68 paint->setFont(f);
Chris@117 69 QFontMetrics fm(f);
Chris@117 70 int fh = fm.height();
Chris@117 71
Chris@117 72 int width = 350;
Chris@117 73 int height = 200;
Chris@117 74
Chris@117 75 QRectF r(0.5, 0.5, width - 1, height - 1);
Chris@117 76 paint->setBrush(Qt::white);
Chris@117 77 paint->drawRect(r);
Chris@117 78
Chris@117 79 if (scale < 0.1) {
Chris@117 80 paint->restore();
Chris@117 81 return;
Chris@117 82 }
Chris@117 83 /*
Chris@117 84 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
Chris@117 85 QBrush(userColour));
Chris@117 86
Chris@117 87 paint->setPen(QPen(Qt::white));
Chris@117 88
Chris@117 89 int wid = width - 5;
Chris@117 90 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
Chris@117 91 paint->drawText(x0 + 3, fm.ascent(), person);
Chris@117 92
Chris@117 93 paint->setPen(QPen(Qt::black));
Chris@117 94
Chris@117 95 if (m_showBranch) {
Chris@117 96 // write branch name
Chris@117 97 f.setBold(true);
Chris@117 98 paint->setFont(f);
Chris@117 99 QString branch = m_changeset->branch();
Chris@117 100 if (branch == "") branch = "default";
Chris@117 101 int wid = width - 3;
Chris@117 102 branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
Chris@117 103 paint->drawText(x0, -fh + fm.ascent() - 4, branch);
Chris@117 104 f.setBold(false);
Chris@117 105 }
Chris@117 106
Chris@117 107 // f.setItalic(true);
Chris@117 108 fm = QFontMetrics(f);
Chris@117 109 fh = fm.height();
Chris@117 110 paint->setFont(f);
Chris@117 111
Chris@117 112 QString comment = m_changeset->comment().trimmed();
Chris@117 113 comment = comment.replace("\\n", " ");
Chris@117 114 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
Chris@117 115 comment = comment.replace(QRegExp("\"$"), "");
Chris@117 116 comment = comment.replace("\\\"", "\"");
Chris@117 117
Chris@117 118 wid = width - 5;
Chris@117 119 int nlines = (height / fh) - 1;
Chris@117 120 if (nlines < 1) nlines = 1;
Chris@117 121 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
Chris@117 122 "...", nlines);
Chris@117 123
Chris@117 124 QStringList lines = comment.split('\n');
Chris@117 125 for (int i = 0; i < lines.size(); ++i) {
Chris@117 126 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
Chris@117 127 }
Chris@117 128 */
Chris@117 129 paint->restore();
Chris@117 130 }