[qt] refactorize: split graph node drawing into one method per node symbol

authoralain leufroy <alain@leufroy.fr>
changesetc0ffd3ac12a9
branchdefault
phasepublic
hiddenno
parent revision#1de8dfd0d391 [qt] refactorize: move graph node drawing into a dedicated method
child revision#5c63ff427714 [qt] refactorize: move tree graph drawing into a dedicated mixin, #43520cb97501 [qt] fancier graph curved lines
files modified by this revision
hgviewlib/qt4/hgrepomodel.py
# HG changeset patch
# User alain leufroy <alain@leufroy.fr>
# Date 1365771931 -7200
# Fri Apr 12 15:05:31 2013 +0200
# Node ID c0ffd3ac12a9582d53dd880ba26a718db53796d6
# Parent 1de8dfd0d3918a177e4011d3345e7cdfc9cfc0cc
[qt] refactorize: split graph node drawing into one method per node symbol

diff --git a/hgviewlib/qt4/hgrepomodel.py b/hgviewlib/qt4/hgrepomodel.py
@@ -303,11 +303,30 @@
1                  self._draw_graph_line(painter, x1, x2, y1, y2, color, not fill)
2 
3          dot_color = QColor(self.namedbranch_color(ctx.branch()))
4          self._draw_graph_node(painter, dot_x, dot_y, radius, dot_color, ctx)
5 
6 -    def _draw_graph_node(self, painter, dot_x, dot_y, radius, dot_color, ctx):
7 +    def _draw_graph_node(self, painter, x, y, r, color, ctx):
8 +        y -= r / 2 # middle -> border
9 +
10 +        tags = set(ctx.tags())
11 +        phase = ctx.phase()
12 +
13 +        if ctx.rev() is None:
14 +            # WD is displayed only if there are local
15 +            # modifications, so let's use the modified icon
16 +            self._draw_graph_node_modified(painter, x, y)
17 +        elif tags.intersection(self.mqueues):
18 +            self._draw_graph_node_mqpatch(painter, x, y)
19 +        elif phase == phases.draft:
20 +            self._draw_graph_node_draft(painter, x, y, r, color, ctx)
21 +        elif phase == phases.secret:
22 +            self._draw_graph_node_secret(painter, x, y, r, color, ctx)
23 +        else:
24 +            self._draw_graph_node_public(painter, x, y, r, color, ctx)
25 +
26 +    def _set_graph_node_style(self, painter, dot_color, ctx):
27          rev = ctx.rev()
28          dotcolor = QColor(dot_color)
29          if ctx.obsolete():
30              penradius = 1
31              pencolor = dotcolor.setAlpha(150)
@@ -316,51 +335,46 @@
32              pencolor = dotcolor.darker()
33          else:
34              penradius = 1
35              pencolor = Qt.black
36 
37 -        dot_y -= radius / 2 # middle -> border
38 +        if rev in self.wd_revs:
39 +            pen = QPen(Qt.red)
40 +            pen.setWidth(2)
41 +        else:
42 +            pen = QPen(pencolor)
43 +            pen.setWidth(1)
44 +        painter.setPen(pen)
45 +        painter.setBrush(dotcolor)        
46 
47 -        painter.setBrush(dotcolor)
48 -        pen = QPen(pencolor)
49 -        pen.setWidth(penradius)
50 -        painter.setPen(pen)
51 -        tags = set(ctx.tags())
52 -        icn = None
53 +    @staticmethod
54 +    def _draw_graph_node_modified(painter, x, y):
55 +        geticon('modified').paint(painter, x - 5, y - 5, 17, 17)
56 
57 -        phase = ctx.phase()
58 +    @staticmethod
59 +    def _draw_graph_node_mqpatch(painter, x, y):
60 +        geticon('mqpatch').paint(painter, x - 5, y - 5, 17, 17)
61 
62 -        if rev is None:
63 -            # WD is displayed only if there are local
64 -            # modifications, so let's use the modified icon
65 -            icn = geticon('modified')
66 -        elif tags.intersection(self.mqueues):
67 -            icn = geticon('mqpatch')
68 -        elif rev in self.wd_revs:
69 -            if phase > phases.public:
70 -                pen_color = Qt.red
71 -                pen = QPen(pen_color)
72 -                pen.setWidth(penradius)
73 -                painter.setPen(pen)
74 -            else:
75 -                icn = geticon('clean')
76 +    def _draw_graph_node_public(self, painter, x, y, r, color, ctx):
77 +        if ctx.rev() in self.wd_revs:
78 +            geticon('clean').paint(painter, x - 5, y - 5, 17, 17)
79 +        else:
80 +            self._set_graph_node_style(painter, color, ctx)
81 +            painter.drawEllipse(x, y, r, r)
82 
83 +    def _draw_graph_node_draft(self, painter, x, y, r, color, ctx):
84 +        self._set_graph_node_style(painter, color, ctx)
85 +        painter.drawRect(x, y, r, r)
86 
87 -        if icn:
88 -            icn.paint(painter, dot_x-5, dot_y-5, 17, 17)
89 -        elif phase == phases.draft:
90 -            painter.drawRect(dot_x, dot_y, radius, radius)
91 -        elif phase == phases.secret:
92 -            P = QPointF
93 -            painter.drawPolygon(
94 -                P(dot_x + (radius//2), dot_y),
95 -                P(dot_x, dot_y + radius),
96 -                P(dot_x + radius, dot_y+radius)
97 -                )
98 -        else:
99 -            painter.drawEllipse(dot_x, dot_y, radius, radius)
100 -
101 +    def _draw_graph_node_secret(self, painter, x, y, r, color, ctx):
102 +        self._set_graph_node_style(painter, color, ctx)
103 +        painter.drawPolygon(
104 +            QPointF(x + (r // 2), y),
105 +            QPointF(x, y + r),
106 +            QPointF(x + r, y + r)
107 +        )
108 +        
109      @staticmethod
110      def _draw_graph_line(painter, x1, x2, y1, y2, color, isobsolete):
111          lpen = QPen(color)
112          if isobsolete:
113               lpen.setStyle(Qt.DotLine)