def paint_clip(self, painter, option, widget): # Clip the node to make it round. clip = _qt.QPainterPath() clip.addRoundedRect( self.x, self.y, UI.node.width, self.height, UI.node.roundness, UI.node.roundness, ) painter.setClipping(True) painter.setClipPath(clip) painter.setPen(_qtcore.Qt.NoPen)
def paint_highlight(self, painter, option, widget): """Highlight the node. Called when the node is selected. """ path = _qt.QPainterPath() path.addRoundedRect( self.x, self.y, UI.node.width, self.height, UI.node.roundness, UI.node.roundness, ) self.highlighter.setWidth(UI.node.highlight.padding * 2) outline = self.highlighter.createStroke(path) color = _qt.QColor(*UI.node.highlight.brush) painter.fillPath(outline, _qt.QBrush(color))
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))