コード例 #1
0
ファイル: pipe.py プロジェクト: sol87/NodeGraphQt
 def highlight(self):
     self._highlight = True
     color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR)
     pen = QtGui.QPen(color, 2, PIPE_STYLES.get(PIPE_STYLE_DEFAULT))
     self.setPen(pen)
     self.__arrow.setBrush(QtGui.QBrush(color.darker(200)))
     self.__arrow.setPen(QtGui.QPen(color, 0.8))
コード例 #2
0
ファイル: pipe.py プロジェクト: sol87/NodeGraphQt
 def activate(self):
     self._active = True
     color = QtGui.QColor(*PIPE_ACTIVE_COLOR)
     pen = QtGui.QPen(color, 2, PIPE_STYLES.get(PIPE_STYLE_DEFAULT))
     self.setPen(pen)
     self.__arrow.setBrush(QtGui.QBrush(color.darker(200)))
     self.__arrow.setPen(QtGui.QPen(color, 0.8))
コード例 #3
0
ファイル: pipe.py プロジェクト: sol87/NodeGraphQt
 def reset(self):
     self._active = False
     self._highlight = False
     color = QtGui.QColor(*self.color)
     pen = QtGui.QPen(color, 2, PIPE_STYLES.get(self.style))
     self.setPen(pen)
     self.__arrow.setBrush(QtGui.QBrush(color.darker(130)))
     self.__arrow.setPen(QtGui.QPen(color, 0.6))
コード例 #4
0
ファイル: pipe.py プロジェクト: spider2449/NodeGraphQt
    def paint(self, painter, option, widget):
        """
        Draws the connection line between nodes.

        Args:
            painter (QtGui.QPainter): painter used for drawing the item.
            option (QtGui.QStyleOptionGraphicsItem):
                used to describe the parameters needed to draw.
            widget (QtWidgets.QWidget): not used.
        """
        color = QtGui.QColor(*self._color)
        pen_style = PIPE_STYLES.get(self.style)
        pen_width = PIPE_WIDTH
        if self._active:
            color = QtGui.QColor(*PIPE_ACTIVE_COLOR)
            if pen_style == QtCore.Qt.DashDotDotLine:
                pen_width += 1
            else:
                pen_width += 0.35
        elif self._highlight:
            color = QtGui.QColor(*PIPE_HIGHLIGHT_COLOR)
            pen_style = PIPE_STYLES.get(PIPE_STYLE_DEFAULT)

        if self.disabled():
            if not self._active:
                color = QtGui.QColor(*PIPE_DISABLED_COLOR)
            pen_width += 0.2
            pen_style = PIPE_STYLES.get(PIPE_STYLE_DOTTED)

        pen = QtGui.QPen(color, pen_width)
        pen.setStyle(pen_style)
        pen.setCapStyle(QtCore.Qt.RoundCap)

        painter.save()
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing, True)
        painter.drawPath(self.path())

        # draw arrow
        if self.input_port and self.output_port:
            cen_x = self.path().pointAtPercent(0.5).x()
            cen_y = self.path().pointAtPercent(0.5).y()
            loc_pt = self.path().pointAtPercent(0.49)
            tgt_pt = self.path().pointAtPercent(0.51)

            dist = math.hypot(tgt_pt.x() - cen_x, tgt_pt.y() - cen_y)
            if dist < 0.5:
                painter.restore()
                return

            color.setAlpha(255)
            if self._highlight:
                painter.setBrush(QtGui.QBrush(color.lighter(150)))
            elif self._active or self.disabled():
                painter.setBrush(QtGui.QBrush(color.darker(200)))
            else:
                painter.setBrush(QtGui.QBrush(color.darker(130)))

            pen_width = 0.6
            if dist < 1.0:
                pen_width *= (1.0 + dist)
            painter.setPen(QtGui.QPen(color, pen_width))

            transform = QtGui.QTransform()
            transform.translate(cen_x, cen_y)
            radians = math.atan2(tgt_pt.y() - loc_pt.y(),
                                 tgt_pt.x() - loc_pt.x())
            degrees = math.degrees(radians) - 90
            transform.rotate(degrees)
            if dist < 1.0:
                transform.scale(dist, dist)
            painter.drawPolygon(transform.map(self._arrow))

        painter.restore()  # QPaintDevice: Cannot destroy paint device that is being painted