Пример #1
0
    def reset(self):
        """Reset the graphic state to its initial value."""
        self.setFlag(_qt.QGraphicsItem.ItemIsMovable)
        self.setFlag(_qt.QGraphicsItem.ItemIsSelectable)
        self.setFlag(_qt.QGraphicsItem.ItemIsFocusable)

        self.resizing = False

        self.x = 0
        self.y = 0

        self.highlighter = _qt.QPainterPathStroker()
        self.highlighter.setCapStyle(_qtcore.Qt.RoundCap)
        self.resize_handle_size = 10
Пример #2
0
    def compute_path(self):
        """Compute the path of this connection.

        The computed path will be drawn between the source_pos and
        destination_pos of this connection.

        This method requires `BaseConnection.source_pos` and
        `BaseConnection.destination_pos` attributes to be set.
        Both must be `PySide.QtCore.QPointF` attributes or present
        a similar interface (`PySide.QtCore.QPointF.x` and
        `PySide.QtCore.QPointF.y` are used in particular).
        """
        path = _qt.QPainterPath()
        path.moveTo(self.source_pos)

        control_x = self.destination_pos.x() - self.source_pos.x()
        control_y = self.destination_pos.y() - self.source_pos.y()

        control_source = _qtcore.QPointF(
            self.source_pos.x() + control_x * .4,
            self.source_pos.y() + control_y * 0,
        )

        control_destination = _qtcore.QPointF(
            self.source_pos.x() + control_x * .6,
            self.source_pos.y() + control_y * 1,
        )

        path.cubicTo(
            control_source,
            control_destination,
            self.destination_pos,
        )

        stroker = _qt.QPainterPathStroker()
        stroker.setWidth(UI.connection.thickness)
        stroker.setCapStyle(_qtcore.Qt.RoundCap)

        self.setPath(stroker.createStroke(path))