comparison changesetdetailitem.cpp @ 118:9734fb0d6fff

* Rudimentary version of the popup showing more information when you click on a changeset in history graph
author Chris Cannam
date Fri, 26 Nov 2010 23:49:48 +0000
parents d5db15bf250c
children 1f27f71a7034
comparison
equal deleted inserted replaced
117:d5db15bf250c 118:9734fb0d6fff
18 #include "changesetdetailitem.h" 18 #include "changesetdetailitem.h"
19 #include "changeset.h" 19 #include "changeset.h"
20 #include "textabbrev.h" 20 #include "textabbrev.h"
21 #include "colourset.h" 21 #include "colourset.h"
22 #include "debug.h" 22 #include "debug.h"
23 23 #include "common.h"
24
25 #include <QTextDocument>
24 #include <QPainter> 26 #include <QPainter>
25 27
26 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) : 28 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
27 m_changeset(cs) 29 m_changeset(cs), m_doc(0)
28 { 30 {
29 m_font = QFont(); 31 m_font = QFont();
30 m_font.setPixelSize(11); 32 m_font.setPixelSize(11);
31 m_font.setBold(false); 33 m_font.setBold(false);
32 m_font.setItalic(false); 34 m_font.setItalic(false);
35
36 makeDocument();
37 }
38
39 ChangesetDetailItem::~ChangesetDetailItem()
40 {
41 delete m_doc;
33 } 42 }
34 43
35 QRectF 44 QRectF
36 ChangesetDetailItem::boundingRect() const 45 ChangesetDetailItem::boundingRect() const
37 { 46 {
38 return QRectF(0, 0, 350, 200); 47 int w = 350;
48 m_doc->setTextWidth(w);
49 return QRectF(0, -10, w, m_doc->size().height() + 10);
39 } 50 }
40 51
41 void 52 void
42 ChangesetDetailItem::paint(QPainter *paint, 53 ChangesetDetailItem::paint(QPainter *paint,
43 const QStyleOptionGraphicsItem *option, 54 const QStyleOptionGraphicsItem *option,
68 paint->setFont(f); 79 paint->setFont(f);
69 QFontMetrics fm(f); 80 QFontMetrics fm(f);
70 int fh = fm.height(); 81 int fh = fm.height();
71 82
72 int width = 350; 83 int width = 350;
73 int height = 200; 84 m_doc->setTextWidth(width);
85 int height = m_doc->size().height();
74 86
75 QRectF r(0.5, 0.5, width - 1, height - 1); 87 QRectF r(0.5, 0.5, width - 1, height - 1);
76 paint->setBrush(Qt::white); 88 paint->setBrush(Qt::white);
77 paint->drawRect(r); 89 paint->drawRect(r);
78 90
79 if (scale < 0.1) { 91 if (scale < 0.1) {
80 paint->restore(); 92 paint->restore();
81 return; 93 return;
82 } 94 }
95
96 paint->setBrush(branchColour);
97 QVector<QPointF> pts;
98 pts.push_back(QPointF(width/2 - 5, 0));
99 pts.push_back(QPointF(width/2 + 5, 0));
100 pts.push_back(QPointF(width/2, -10));
101 pts.push_back(QPointF(width/2 - 5, 0));
102 paint->drawPolygon(QPolygonF(pts));
103
104 m_doc->drawContents(paint, r);
105
83 /* 106 /*
84 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), 107 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
85 QBrush(userColour)); 108 QBrush(userColour));
86 109
87 paint->setPen(QPen(Qt::white)); 110 paint->setPen(QPen(Qt::white));
107 // f.setItalic(true); 130 // f.setItalic(true);
108 fm = QFontMetrics(f); 131 fm = QFontMetrics(f);
109 fh = fm.height(); 132 fh = fm.height();
110 paint->setFont(f); 133 paint->setFont(f);
111 134
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; 135 wid = width - 5;
119 int nlines = (height / fh) - 1; 136 int nlines = (height / fh) - 1;
120 if (nlines < 1) nlines = 1; 137 if (nlines < 1) nlines = 1;
121 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd, 138 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
122 "...", nlines); 139 "...", nlines);
126 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); 143 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
127 } 144 }
128 */ 145 */
129 paint->restore(); 146 paint->restore();
130 } 147 }
148
149 void
150 ChangesetDetailItem::makeDocument()
151 {
152 delete m_doc;
153
154 QString description;
155 QString rowTemplate = "<tr><td><b>%1</b></td><td>%2</td></tr>";
156
157 description = "<qt><table border=0>";
158
159 QString comment = m_changeset->comment().trimmed();
160 comment = comment.replace(QRegExp("^\""), "");
161 comment = comment.replace(QRegExp("\"$"), "");
162 comment = comment.replace("\\\"", "\"");
163 comment = xmlEncode(comment);
164 comment = comment.replace("\\n", "<br>");
165
166 QStringList propNames, propTexts;
167
168 propNames << "id"
169 << "author"
170 << "datetime"
171 << "branch"
172 << "tag"
173 << "comment";
174
175 propTexts << QObject::tr("Identifier")
176 << QObject::tr("Author")
177 << QObject::tr("Date")
178 << QObject::tr("Branch")
179 << QObject::tr("Tag")
180 << QObject::tr("Comment");
181
182 for (int i = 0; i < propNames.size(); ++i) {
183 QString prop = propNames[i];
184 QString value;
185 if (prop == "comment") value = comment;
186 else {
187 value = xmlEncode(m_changeset->property
188 (prop.toLocal8Bit().data()).toString());
189 }
190 if (value != "") {
191 description += rowTemplate
192 .arg(xmlEncode(propTexts[i]))
193 .arg(value);
194 }
195 }
196
197 description += "</table></qt>";
198
199 DEBUG << "ChangesetDetailItem: description = " << description << endl;
200
201 m_doc = new QTextDocument;
202 m_doc->setHtml(description);
203 }
204