Skip to content

Commit bdeb335

Browse files
committed
updated draw logic in LivePipe
1 parent 13f4043 commit bdeb335

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

NodeGraphQt/qgraphics/pipe.py

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,72 @@ def delete(self):
301301

302302
class 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()

NodeGraphQt/widgets/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from NodeGraphQt import QtGui, QtCore, QtWidgets
66
from NodeGraphQt.constants import (IN_PORT, OUT_PORT,
77
PIPE_LAYOUT_CURVED,
8-
SCENE_AREA,)
8+
SCENE_AREA)
99
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
1010
from NodeGraphQt.qgraphics.node_backdrop import BackdropNodeItem
1111
from NodeGraphQt.qgraphics.pipe import Pipe, LivePipe

0 commit comments

Comments
 (0)