Skip to content

Commit da2d378

Browse files
committed
LivePipeItem optimizations.
1 parent 5c11b10 commit da2d378

File tree

1 file changed

+12
-68
lines changed

1 file changed

+12
-68
lines changed

NodeGraphQt/qgraphics/pipe.py

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -524,87 +524,31 @@ class LivePipeItem(PipeItem):
524524
def __init__(self):
525525
super(LivePipeItem, self).__init__()
526526
self.setZValue(Z_VAL_NODE_WIDGET + 1)
527+
527528
self.shift_selected = False
528529

529-
color = QtGui.QColor(*PipeEnum.ACTIVE_COLOR.value)
530-
pen = QtGui.QPen(color, PipeEnum.WIDTH.value + 0.35)
531-
pen.setJoinStyle(QtCore.Qt.MiterJoin)
532-
pen.setCapStyle(QtCore.Qt.RoundCap)
530+
self._color = PipeEnum.ACTIVE_COLOR.value
531+
self._style = PipeEnum.DRAW_TYPE_DASHED.value
532+
533+
self.set_pipe_styling(color=self.color, width=2.5, style=self.style)
533534

534535
self._idx_pointer = LivePipePolygonItem(self)
535536
self._idx_pointer.setPolygon(self._poly)
536-
self._idx_pointer.setBrush(color.darker(300))
537+
self._idx_pointer.setBrush(QtGui.QColor(*self.color).darker(300))
538+
pen = self._idx_pointer.pen()
539+
pen.setWidth(self.pen().width())
540+
pen.setColor(self.pen().color())
541+
pen.setJoinStyle(QtCore.Qt.MiterJoin)
537542
self._idx_pointer.setPen(pen)
538543

539-
color = QtGui.QColor(*PipeEnum.ACTIVE_COLOR.value)
540-
color.setAlpha(50)
544+
color = self.pen().color()
545+
color.setAlpha(80)
541546
self._idx_text = QtWidgets.QGraphicsTextItem(self)
542547
self._idx_text.setDefaultTextColor(color)
543548
font = self._idx_text.font()
544549
font.setPointSize(7)
545550
self._idx_text.setFont(font)
546551

547-
def paint(self, painter, option, widget):
548-
"""
549-
Draws the connection line.
550-
551-
Args:
552-
painter (QtGui.QPainter): painter used for drawing the item.
553-
option (QtGui.QStyleOptionGraphicsItem):
554-
used to describe the parameters needed to draw.
555-
widget (QtWidgets.QWidget): not used.
556-
"""
557-
color = QtGui.QColor(*PipeEnum.ACTIVE_COLOR.value)
558-
pen_style = PIPE_STYLES.get(PipeEnum.DRAW_TYPE_DASHED.value)
559-
pen_width = PipeEnum.WIDTH.value + 0.35
560-
561-
pen = QtGui.QPen(color, pen_width)
562-
pen.setStyle(pen_style)
563-
pen.setCapStyle(QtCore.Qt.RoundCap)
564-
565-
painter.save()
566-
painter.setPen(pen)
567-
painter.setRenderHint(painter.Antialiasing, True)
568-
painter.drawPath(self.path())
569-
570-
cen_x = self.path().pointAtPercent(0.5).x()
571-
cen_y = self.path().pointAtPercent(0.5).y()
572-
loc_pt = self.path().pointAtPercent(0.9)
573-
tgt_pt = self.path().pointAtPercent(1.0)
574-
575-
dist = math.hypot(tgt_pt.x() - cen_x, tgt_pt.y() - cen_y)
576-
if dist < 0.05:
577-
painter.restore()
578-
return
579-
580-
# draw middle circle
581-
size = 10.0
582-
if dist < 50.0:
583-
size *= (dist / 50.0)
584-
rect = QtCore.QRectF(cen_x-(size/2), cen_y-(size/2), size, size)
585-
painter.setBrush(color)
586-
painter.setPen(QtGui.QPen(color.darker(130), pen_width))
587-
painter.drawEllipse(rect)
588-
589-
# draw arrow
590-
color.setAlpha(255)
591-
painter.setBrush(color.darker(200))
592-
593-
pen_width = 0.6
594-
if dist < 1.0:
595-
pen_width *= 1.0 + dist
596-
painter.setPen(QtGui.QPen(color, pen_width))
597-
598-
transform = QtGui.QTransform()
599-
transform.translate(tgt_pt.x(), tgt_pt.y())
600-
601-
radians = math.atan2(tgt_pt.y() - loc_pt.y(),
602-
tgt_pt.x() - loc_pt.x())
603-
degrees = math.degrees(radians) + 90
604-
transform.rotate(degrees)
605-
606-
painter.restore()
607-
608552
def draw_path(self, start_port, end_port=None, cursor_pos=None,
609553
color_mode=None):
610554
"""

0 commit comments

Comments
 (0)