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