1616}
1717
1818
19- class PipeArrow (QtWidgets .QGraphicsPolygonItem ):
20- """
21- Base pipe arrow item for indicating pipe direction.
22- """
23-
24- def __init__ (self , parent = None , size = 5.0 ):
25- super (PipeArrow , self ).__init__ (parent )
26- self .set_size (size )
27-
28- def set_size (self , size = 5.0 ):
29- triangle = QtGui .QPolygonF ()
30- triangle .append (QtCore .QPointF (- size , size ))
31- triangle .append (QtCore .QPointF (0.0 , - size * 2 ))
32- triangle .append (QtCore .QPointF (size , size ))
33- self .setPolygon (triangle )
34-
35-
3619class Pipe (QtWidgets .QGraphicsPathItem ):
3720 """
3821 Base Pipe item used for drawing node connections.
@@ -48,8 +31,11 @@ def __init__(self, input_port=None, output_port=None):
4831 self ._highlight = False
4932 self ._input_port = input_port
5033 self ._output_port = output_port
51- self .__arrow = PipeArrow (self )
52- self .reset ()
34+ size = 5.0
35+ self ._arrow = QtGui .QPolygonF ()
36+ self ._arrow .append (QtCore .QPointF (- size , size ))
37+ self ._arrow .append (QtCore .QPointF (0.0 , - size * 2 ))
38+ self ._arrow .append (QtCore .QPointF (size , size ))
5339
5440 def __str__ (self ):
5541 in_name = self ._input_port .name if self ._input_port else ''
@@ -88,6 +74,10 @@ def paint(self, painter, option, widget):
8874 pen_width = PIPE_WIDTH
8975 if self ._active :
9076 color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
77+ if pen_style == QtCore .Qt .DashDotDotLine :
78+ pen_width += 1
79+ else :
80+ pen_width += 0.35
9181 elif self ._highlight :
9282 color = QtGui .QColor (* PIPE_HIGHLIGHT_COLOR )
9383 pen_style = PIPE_STYLES .get (PIPE_STYLE_DEFAULT )
@@ -106,6 +96,28 @@ def paint(self, painter, option, widget):
10696 painter .setRenderHint (painter .Antialiasing , True )
10797 painter .drawPath (self .path ())
10898
99+ # draw arrow
100+ if self .input_port and self .output_port :
101+ transform = QtGui .QTransform ()
102+ transform .translate (self .path ().pointAtPercent (0.5 ).x (),
103+ self .path ().pointAtPercent (0.5 ).y ())
104+ loc_pt = self .path ().pointAtPercent (0.49 )
105+ tgt_pt = self .path ().pointAtPercent (0.51 )
106+ radians = math .atan2 (tgt_pt .y () - loc_pt .y (),
107+ tgt_pt .x () - loc_pt .x ())
108+ degrees = math .degrees (radians ) - 90
109+ transform .rotate (degrees )
110+
111+ color .setAlpha (255 )
112+ if self ._highlight :
113+ painter .setBrush (QtGui .QBrush (color .lighter (150 )))
114+ elif self ._active or self .disabled ():
115+ painter .setBrush (QtGui .QBrush (color .darker (200 )))
116+ else :
117+ painter .setBrush (QtGui .QBrush (color ))
118+ painter .setPen (QtGui .QPen (color , 0.6 ))
119+ painter .drawPolygon (transform .map (self ._arrow ))
120+
109121 painter .restore () # QPaintDevice: Cannot destroy paint device that is being painted
110122
111123 def draw_path (self , start_port , end_port , cursor_pos = None ):
@@ -162,19 +174,6 @@ def draw_path(self, start_port, end_port, cursor_pos=None):
162174 path .cubicTo (ctr_point1 , ctr_point2 , pos2 )
163175 self .setPath (path )
164176
165- # draw arrow
166- if start_port .port_type == IN_PORT :
167- loc_pt = self .path ().pointAtPercent (0.49 )
168- tgt_pt = self .path ().pointAtPercent (0.51 )
169- else :
170- loc_pt = self .path ().pointAtPercent (0.51 )
171- tgt_pt = self .path ().pointAtPercent (0.49 )
172-
173- radians = math .atan2 (tgt_pt .y () - loc_pt .y (), tgt_pt .x () - loc_pt .x ())
174- degrees = math .degrees (radians ) - 90
175- self .__arrow .setPos (self .path ().pointAtPercent (0.5 ))
176- self .__arrow .setRotation (degrees )
177-
178177 def calc_distance (self , p1 , p2 ):
179178 x = math .pow ((p2 .x () - p1 .x ()), 2 )
180179 y = math .pow ((p2 .y () - p1 .y ()), 2 )
@@ -199,10 +198,8 @@ def viewer_pipe_layout(self):
199198 def activate (self ):
200199 self ._active = True
201200 color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
202- pen = QtGui .QPen (color , 2 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
201+ pen = QtGui .QPen (color , 2.5 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
203202 self .setPen (pen )
204- self .__arrow .setBrush (QtGui .QBrush (color .darker (200 )))
205- self .__arrow .setPen (QtGui .QPen (color , 0.8 ))
206203
207204 def active (self ):
208205 return self ._active
@@ -212,8 +209,6 @@ def highlight(self):
212209 color = QtGui .QColor (* PIPE_HIGHLIGHT_COLOR )
213210 pen = QtGui .QPen (color , 2 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
214211 self .setPen (pen )
215- self .__arrow .setBrush (QtGui .QBrush (color .darker (200 )))
216- self .__arrow .setPen (QtGui .QPen (color , 0.8 ))
217212
218213 def highlighted (self ):
219214 return self ._highlight
@@ -224,8 +219,6 @@ def reset(self):
224219 color = QtGui .QColor (* self .color )
225220 pen = QtGui .QPen (color , 2 , PIPE_STYLES .get (self .style ))
226221 self .setPen (pen )
227- self .__arrow .setBrush (QtGui .QBrush (color .darker (130 )))
228- self .__arrow .setPen (QtGui .QPen (color , 0.6 ))
229222
230223 def set_connections (self , port1 , port2 ):
231224 ports = {
0 commit comments