@@ -301,9 +301,72 @@ def delete(self):
301301
302302class LivePipe (Pipe ):
303303
304- def __init__ (self , input_port = None , output_port = None ):
305- super (LivePipe , self ).__init__ (input_port , output_port )
304+ def __init__ (self ):
305+ super (LivePipe , self ).__init__ ()
306306 self .setZValue (Z_VAL_NODE_WIDGET + 1 )
307- self .activate ()
308- self .style = PIPE_STYLE_DASHED
309- self .shift_selected = False
307+
308+ def paint (self , painter , option , widget ):
309+ """
310+ Draws the connection line.
311+
312+ Args:
313+ painter (QtGui.QPainter): painter used for drawing the item.
314+ option (QtGui.QStyleOptionGraphicsItem):
315+ used to describe the parameters needed to draw.
316+ widget (QtWidgets.QWidget): not used.
317+ """
318+ color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
319+ pen_style = PIPE_STYLES .get (PIPE_STYLE_DASHED )
320+ pen_width = PIPE_WIDTH + 0.35
321+
322+ pen = QtGui .QPen (color , pen_width )
323+ pen .setStyle (pen_style )
324+ pen .setCapStyle (QtCore .Qt .RoundCap )
325+
326+ painter .save ()
327+ painter .setPen (pen )
328+ painter .setRenderHint (painter .Antialiasing , True )
329+ painter .drawPath (self .path ())
330+
331+ cen_x = self .path ().pointAtPercent (0.5 ).x ()
332+ cen_y = self .path ().pointAtPercent (0.5 ).y ()
333+ loc_pt = self .path ().pointAtPercent (0.9 )
334+ tgt_pt = self .path ().pointAtPercent (1.0 )
335+
336+ dist = math .hypot (tgt_pt .x () - cen_x , tgt_pt .y () - cen_y )
337+ if dist < 0.05 :
338+ painter .restore ()
339+ return
340+
341+ # draw circle
342+ size = 10 * (dist / 100 )
343+ if size > 10.0 :
344+ size = 10.0
345+ elif size < 5.0 :
346+ size = 5.0
347+ rect = QtCore .QRectF (cen_x - (size / 2 ), cen_y - (size / 2 ), size , size )
348+ painter .setBrush (color )
349+ painter .setPen (QtGui .QPen (color .darker (130 ), pen_width ))
350+ painter .drawEllipse (rect )
351+
352+ # draw arrow
353+ color .setAlpha (255 )
354+ painter .setBrush (color .darker (200 ))
355+
356+ pen_width = 0.6
357+ if dist < 1.0 :
358+ pen_width *= (1.0 + dist )
359+ painter .setPen (QtGui .QPen (color , pen_width ))
360+
361+ transform = QtGui .QTransform ()
362+ transform .translate (tgt_pt .x (), tgt_pt .y ())
363+
364+ radians = math .atan2 (tgt_pt .y () - loc_pt .y (),
365+ tgt_pt .x () - loc_pt .x ())
366+ degrees = math .degrees (radians ) + 90
367+ transform .rotate (degrees )
368+
369+ if dist < 10.0 :
370+ transform .scale (0.5 , 0.5 )
371+ painter .drawPolygon (transform .map (self ._arrow ))
372+ painter .restore ()
0 commit comments