comparison src/changesetdetailitem.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents changesetdetailitem.cpp@8fd71f570884
children 7ef46fb73b48
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on HgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "changesetdetailitem.h"
19 #include "changeset.h"
20 #include "textabbrev.h"
21 #include "colourset.h"
22 #include "debug.h"
23 #include "common.h"
24
25 #include <QTextDocument>
26 #include <QPainter>
27
28 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
29 m_changeset(cs), m_doc(0)
30 {
31 m_font = QFont();
32 m_font.setPixelSize(11);
33 m_font.setBold(false);
34 m_font.setItalic(false);
35
36 makeDocument();
37 }
38
39 ChangesetDetailItem::~ChangesetDetailItem()
40 {
41 delete m_doc;
42 }
43
44 QRectF
45 ChangesetDetailItem::boundingRect() const
46 {
47 int w = 350;
48 m_doc->setTextWidth(w);
49 return QRectF(-10, -10, w + 10, m_doc->size().height() + 10);
50 }
51
52 void
53 ChangesetDetailItem::paint(QPainter *paint,
54 const QStyleOptionGraphicsItem *option,
55 QWidget *w)
56 {
57 paint->save();
58
59 ColourSet *colourSet = ColourSet::instance();
60 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
61 QColor userColour = colourSet->getColourFor(m_changeset->author());
62
63 QFont f(m_font);
64
65 QTransform t = paint->worldTransform();
66 float scale = std::min(t.m11(), t.m22());
67 if (scale > 1.0) {
68 int ps = int((f.pixelSize() / scale) + 0.5);
69 if (ps < 8) ps = 8;
70 f.setPixelSize(ps);
71 }
72
73 if (scale < 0.1) {
74 paint->setPen(QPen(branchColour, 0));
75 } else {
76 paint->setPen(QPen(branchColour, 2));
77 }
78
79 paint->setFont(f);
80 QFontMetrics fm(f);
81 int fh = fm.height();
82
83 int width = 350;
84 m_doc->setTextWidth(width);
85 int height = m_doc->size().height();
86
87 QRectF r(0.5, 0.5, width - 1, height - 1);
88 paint->setBrush(Qt::white);
89 paint->drawRect(r);
90
91 if (scale < 0.1) {
92 paint->restore();
93 return;
94 }
95
96 // little triangle connecting to its "owning" changeset item
97 paint->setBrush(branchColour);
98 QVector<QPointF> pts;
99 pts.push_back(QPointF(0, height/3 - 5));
100 pts.push_back(QPointF(0, height/3 + 5));
101 pts.push_back(QPointF(-10, height/3));
102 pts.push_back(QPointF(0, height/3 - 5));
103 paint->drawPolygon(QPolygonF(pts));
104
105 /*
106 paint->setBrush(branchColour);
107 QVector<QPointF> pts;
108 pts.push_back(QPointF(width/2 - 5, 0));
109 pts.push_back(QPointF(width/2 + 5, 0));
110 pts.push_back(QPointF(width/2, -10));
111 pts.push_back(QPointF(width/2 - 5, 0));
112 paint->drawPolygon(QPolygonF(pts));
113 */
114 m_doc->drawContents(paint, r);
115
116 paint->restore();
117 }
118
119 void
120 ChangesetDetailItem::makeDocument()
121 {
122 delete m_doc;
123 m_doc = new QTextDocument;
124 m_doc->setHtml(m_changeset->formatHtml());
125 }
126