Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

repomodel: move graph painting to its own function

Changeset eaf4322ea695

Parent 99818f5502dd

by Steve Borho

Changes to one file · Browse files at eaf4322ea695 Showing diff from parent 99818f5502dd Diff from another changeset...

 
276
277
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
280
281
 
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
 
389
390
391
 
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
 
386
387
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
390
391
392
@@ -276,6 +276,93 @@
  def col2x(self, col):   return 2 * self.dot_radius * col + self.dot_radius/2 + 8   + def graphctx(self, ctx, gnode): + w = self.col2x(gnode.cols) + 10 + h = self.rowheight + + dot_y = h / 2 + + pix = QPixmap(w, h) + pix.fill(QColor(0,0,0,0)) + painter = QPainter(pix) + painter.setRenderHint(QPainter.Antialiasing) + + pen = QPen(Qt.blue) + pen.setWidth(2) + painter.setPen(pen) + + lpen = QPen(pen) + lpen.setColor(Qt.black) + painter.setPen(lpen) + for y1, y4, lines in ((dot_y, dot_y + h, gnode.bottomlines), + (dot_y - h, dot_y, gnode.toplines)): + y2 = y1 + 1 * (y4 - y1)/4 + ymid = (y1 + y4)/2 + y3 = y1 + 3 * (y4 - y1)/4 + + for start, end, color in lines: + lpen = QPen(pen) + lpen.setColor(QColor(get_color(color))) + lpen.setWidth(2) + painter.setPen(lpen) + x1 = self.col2x(start) + x2 = self.col2x(end) + path = QPainterPath() + path.moveTo(x1, y1) + path.cubicTo(x1, y2, + x1, y2, + (x1 + x2)/2, ymid) + path.cubicTo(x2, y3, + x2, y3, + x2, y4) + painter.drawPath(path) + + # Draw node + dot_color = QColor(self.namedbranch_color(ctx.branch())) + dotcolor = dot_color.lighter() + pencolor = dot_color.darker() + white = QColor("white") + fillcolor = gnode.rev is None and white or dotcolor + + pen = QPen(pencolor) + pen.setWidthF(1.5) + painter.setPen(pen) + + radius = self.dot_radius + centre_x = self.col2x(gnode.x) + centre_y = h/2 + + def circle(r): + rect = QRectF(centre_x - r, + centre_y - r, + 2 * r, 2 * r) + painter.drawEllipse(rect) + + def diamond(r): + poly = QPolygonF([QPointF(centre_x - r, centre_y), + QPointF(centre_x, centre_y - r), + QPointF(centre_x + r, centre_y), + QPointF(centre_x, centre_y + r), + QPointF(centre_x - r, centre_y),]) + painter.drawPolygon(poly) + + tags = set(ctx.tags()) + if tags.intersection(self.mqueues): # diamonds for patches + if gnode.rev in self.wd_revs: + painter.setBrush(white) + diamond(2 * 0.9 * radius / 1.5) + painter.setBrush(fillcolor) + diamond(radius / 1.5) + else: # circles for normal revisions + if gnode.rev in self.wd_revs: + painter.setBrush(white) + circle(0.9 * radius) + painter.setBrush(fillcolor) + circle(0.5 * radius) + + painter.end() + return QVariant(pix) +   @datacached   def data(self, index, role):   if not index.isValid(): @@ -299,93 +386,7 @@
  return QVariant(QColor(self.namedbranch_color(ctx.branch())))   elif role == Qt.DecorationRole:   if column == 'Graph': - w = self.col2x(gnode.cols) + 10 - h = self.rowheight - - dot_y = h / 2 - - pix = QPixmap(w, h) - pix.fill(QColor(0,0,0,0)) - painter = QPainter(pix) - painter.setRenderHint(QPainter.Antialiasing) - - pen = QPen(Qt.blue) - pen.setWidth(2) - painter.setPen(pen) - - lpen = QPen(pen) - lpen.setColor(Qt.black) - painter.setPen(lpen) - for y1, y4, lines in ((dot_y, dot_y + h, gnode.bottomlines), - (dot_y - h, dot_y, gnode.toplines)): - y2 = y1 + 1 * (y4 - y1)/4 - ymid = (y1 + y4)/2 - y3 = y1 + 3 * (y4 - y1)/4 - - for start, end, color in lines: - lpen = QPen(pen) - lpen.setColor(QColor(get_color(color))) - lpen.setWidth(2) - painter.setPen(lpen) - x1 = self.col2x(start) - x2 = self.col2x(end) - path = QPainterPath() - path.moveTo(x1, y1) - path.cubicTo(x1, y2, - x1, y2, - (x1 + x2)/2, ymid) - path.cubicTo(x2, y3, - x2, y3, - x2, y4) - painter.drawPath(path) - - # Draw node - dot_color = QColor(self.namedbranch_color(ctx.branch())) - dotcolor = dot_color.lighter() - pencolor = dot_color.darker() - white = QColor("white") - fillcolor = gnode.rev is None and white or dotcolor - - pen = QPen(pencolor) - pen.setWidthF(1.5) - painter.setPen(pen) - - radius = self.dot_radius - centre_x = self.col2x(gnode.x) - centre_y = h/2 - - def circle(r): - rect = QRectF(centre_x - r, - centre_y - r, - 2 * r, 2 * r) - painter.drawEllipse(rect) - - def diamond(r): - poly = QPolygonF([QPointF(centre_x - r, centre_y), - QPointF(centre_x, centre_y - r), - QPointF(centre_x + r, centre_y), - QPointF(centre_x, centre_y + r), - QPointF(centre_x - r, centre_y),]) - painter.drawPolygon(poly) - - tags = set(ctx.tags()) - if tags.intersection(self.mqueues): # diamonds for patches - if gnode.rev in self.wd_revs: - painter.setBrush(white) - diamond(2 * 0.9 * radius / 1.5) - painter.setBrush(fillcolor) - diamond(radius / 1.5) - else: # circles for normal revisions - if gnode.rev in self.wd_revs: - painter.setBrush(white) - circle(0.9 * radius) - painter.setBrush(fillcolor) - circle(0.5 * radius) - - painter.end() - - ret = QVariant(pix) - return ret + return self.graphctx(ctx, gnode)   return nullvariant     def headerData(self, section, orientation, role):