comparison changesetitem.cpp @ 251:0689dada1419

Merge
author Chris Cannam
date Tue, 11 Jan 2011 20:19:19 +0000
parents be483734bde5
children f7cdd5b31aed 9162f14c5ab7
comparison
equal deleted inserted replaced
246:0fe81e1b26ce 251:0689dada1419
53 QRectF 53 QRectF
54 ChangesetItem::boundingRect() const 54 ChangesetItem::boundingRect() const
55 { 55 {
56 int w = 100; 56 int w = 100;
57 if (m_wide) w = 180; 57 if (m_wide) w = 180;
58 return QRectF(-((w-50)/2 - 1), -30, w - 3, 79); 58 return QRectF(-((w-50)/2 - 1), -30, w - 3, 90);
59 } 59 }
60 60
61 void 61 void
62 ChangesetItem::showDetail() 62 ChangesetItem::showDetail()
63 { 63 {
209 int ps = int((f.pixelSize() / scale) + 0.5); 209 int ps = int((f.pixelSize() / scale) + 0.5);
210 if (ps < 8) ps = 8; 210 if (ps < 8) ps = 8;
211 f.setPixelSize(ps); 211 f.setPixelSize(ps);
212 } 212 }
213 213
214 if (scale < 0.1) { 214 bool showText = (scale >= 0.2);
215 bool showProperLines = (scale >= 0.1);
216
217 if (!showProperLines) {
215 paint->setPen(QPen(branchColour, 0)); 218 paint->setPen(QPen(branchColour, 0));
216 } else { 219 } else {
217 paint->setPen(QPen(branchColour, 2)); 220 paint->setPen(QPen(branchColour, 2));
218 } 221 }
219 222
223 226
224 int width = 100; 227 int width = 100;
225 if (m_wide) width = 180; 228 if (m_wide) width = 180;
226 int x0 = -((width - 50) / 2 - 1); 229 int x0 = -((width - 50) / 2 - 1);
227 230
228 int height = 49; 231 int textwid = width - 7;
232
233 QString comment;
234 QStringList lines;
235 int lineCount = 3;
236
237 if (showText) {
238
239 comment = m_changeset->comment().trimmed();
240 comment = comment.replace("\\n", " ");
241 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
242 comment = comment.replace(QRegExp("\"$"), "");
243 comment = comment.replace("\\\"", "\"");
244
245 comment = TextAbbrev::abbreviate(comment, fm, textwid,
246 TextAbbrev::ElideEnd, "...", 3);
247 // abbreviate() changes this (ouch!), restore it
248 textwid = width - 5;
249
250 lines = comment.split('\n');
251 lineCount = lines.size();
252
253 if (lineCount < 2) lineCount = 2;
254 }
255
256 int height = (lineCount + 1) * fh + 2;
229 QRectF r(x0, 0, width - 3, height); 257 QRectF r(x0, 0, width - 3, height);
258
259 if (showProperLines) {
260
261 paint->setBrush(Qt::white);
262
263 if (m_current) {
264 paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8));
265 }
266
267 if (m_new) {
268 paint->save();
269 paint->setPen(Qt::yellow);
270 paint->setBrush(Qt::NoBrush);
271 paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4));
272 paint->restore();
273 }
274 }
275
230 paint->drawRect(r); 276 paint->drawRect(r);
231 277
232 if (m_new) { 278 if (!showText) {
233 paint->save();
234 paint->setPen(Qt::yellow);
235 paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4));
236 paint->restore();
237 }
238
239 if (m_current) {
240 paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8));
241 }
242
243 if (scale < 0.2) {
244 paint->restore(); 279 paint->restore();
245 return; 280 return;
246 } 281 }
247 282
248 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), 283 paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
249 QBrush(userColour)); 284 QBrush(userColour));
250 285
251 paint->setPen(QPen(Qt::white)); 286 paint->setPen(QPen(Qt::white));
252 287
253 int wid = width - 5; 288 QString person = TextAbbrev::abbreviate(m_changeset->authorName(),
254 QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid); 289 fm, textwid);
255 paint->drawText(x0 + 3, fm.ascent(), person); 290 paint->drawText(x0 + 3, fm.ascent(), person);
256 291
257 paint->setPen(QPen(Qt::black)); 292 paint->setPen(QPen(Qt::black));
258 293
259 QStringList tags = m_changeset->tags(); 294 QStringList tags = m_changeset->tags();
291 paint->drawText(x0, -fh + fm.ascent() - 4, branch); 326 paint->drawText(x0, -fh + fm.ascent() - 4, branch);
292 f.setBold(false); 327 f.setBold(false);
293 paint->restore(); 328 paint->restore();
294 } 329 }
295 330
296 fm = QFontMetrics(f);
297 fh = fm.height();
298 paint->setFont(f); 331 paint->setFont(f);
299 332
300 QString comment = m_changeset->comment().trimmed();
301 comment = comment.replace("\\n", " ");
302 comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
303 comment = comment.replace(QRegExp("\"$"), "");
304 comment = comment.replace("\\\"", "\"");
305
306 wid = width - 5;
307 int nlines = (height / fh) - 1;
308 if (nlines < 1) nlines = 1;
309 comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd,
310 "...", nlines);
311
312 QStringList lines = comment.split('\n');
313 for (int i = 0; i < lines.size(); ++i) { 333 for (int i = 0; i < lines.size(); ++i) {
314 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); 334 paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
315 } 335 }
316 336
317 paint->restore(); 337 paint->restore();