Exemplo n.º 1
0
    def __init__(self, source, dest):
        super().__init__()
        self.setAcceptedMouseButtons(Qt.LeftButton)
        self.setCacheMode(self.DeviceCoordinateCache)  # Without this, burn thy CPU
        self.setZValue(1)
        pen = QPen(Edge.Color.DEFAULT[0], 1)
        pen.setJoinStyle(Qt.MiterJoin)
        self.setPen(pen)
        self.arrowHead = QPolygonF()
        self._selected = False
        self._weights = []
        self._labels = []
        self.squares = GroupOfSquares(self)

        self.source = source
        self.dest = dest
        if source is dest:
            source.edges.append(self)
        else:
            source.edges.insert(0, self)
            dest.edges.insert(0, self)

        # Add text labels
        label = self.label = TextItem('', self)
        label.setFont(Edge.Font.DEFAULT)
        label.setZValue(3)
        self.adjust()
Exemplo n.º 2
0
    def __init__(self, source, dest):
        super().__init__()
        self.setAcceptedMouseButtons(Qt.LeftButton)
        self.setCacheMode(
            self.DeviceCoordinateCache)  # Without this, burn thy CPU
        self.setZValue(1)
        pen = QPen(Edge.Color.DEFAULT[0], 1)
        pen.setJoinStyle(Qt.MiterJoin)
        self.setPen(pen)
        self.arrowHead = QPolygonF()
        self._selected = False
        self._weights = []
        self._labels = []
        self.squares = GroupOfSquares(self)

        self.source = source
        self.dest = dest
        if source is dest:
            source.edges.append(self)
        else:
            source.edges.insert(0, self)
            dest.edges.insert(0, self)

        # Add text labels
        label = self.label = TextItem('', self)
        label.setFont(Edge.Font.DEFAULT)
        label.setZValue(3)
        self.adjust()
def make_pen(brush=Qt.black, width=1, style=Qt.SolidLine,
             cap_style=Qt.SquareCap, join_style=Qt.BevelJoin,
             cosmetic=False):
    pen = QPen(brush)
    pen.setWidth(width)
    pen.setStyle(style)
    pen.setCapStyle(cap_style)
    pen.setJoinStyle(join_style)
    pen.setCosmetic(cosmetic)
    return pen
Exemplo n.º 4
0
 def paint(self, painter, option, widget=None):
     # Override the default selected appearance
     if self.isSelected():
         option.state ^= QStyle.State_Selected
         rect = self.rect()
         # this must render before overlay due to order in which it's drawn
         super().paint(painter, option, widget)
         painter.save()
         pen = QPen(QColor(Qt.black))
         pen.setWidth(4)
         pen.setJoinStyle(Qt.MiterJoin)
         painter.setPen(pen)
         painter.drawRect(rect.adjusted(2, 2, -2, -2))
         painter.restore()
     else:
         super().paint(painter, option, widget)
Exemplo n.º 5
0
 def paint(self, painter, option, widget=None):
     # Override the default selected appearance
     if self.isSelected():
         option.state ^= QStyle.State_Selected
         rect = self.rect()
         # this must render before overlay due to order in which it's drawn
         super().paint(painter, option, widget)
         painter.save()
         pen = QPen(QColor(Qt.black))
         pen.setWidth(4)
         pen.setJoinStyle(Qt.MiterJoin)
         painter.setPen(pen)
         painter.drawRect(rect.adjusted(2, 2, -2, -2))
         painter.restore()
     else:
         super().paint(painter, option, widget)
 def paint(self, painter, option, widget=None):
     if self.__editing:
         option.state |= QStyle.State_Editing
     # Disable base QGraphicsItem selected/focused outline
     state = option.state
     option = QStyleOptionGraphicsItem(option)
     option.palette = self.palette().resolve(option.palette)
     option.state &= ~(QStyle.State_Selected | QStyle.State_HasFocus)
     super().paint(painter, option, widget)
     if state & QStyle.State_Editing:
         brect = self.boundingRect()
         width = 3.
         color = qgraphicsitem_accent_color(self, option.palette)
         color.setAlpha(230)
         pen = QPen(color, width, Qt.SolidLine)
         painter.setPen(pen)
         adjust = width / 2.
         pen.setJoinStyle(Qt.RoundJoin)
         painter.drawRect(brect.adjusted(adjust, adjust, -adjust,
                                         -adjust), )
Exemplo n.º 7
0
def update_pen(pen,
               brush=None,
               width=None,
               style=None,
               cap_style=None,
               join_style=None,
               cosmetic=None):
    pen = QPen(pen)
    if brush is not None:
        pen.setBrush(QBrush(brush))
    if width is not None:
        pen.setWidth(width)
    if style is not None:
        pen.setStyle(style)
    if cap_style is not None:
        pen.setCapStyle(cap_style)
    if join_style is not None:
        pen.setJoinStyle(join_style)
    if cosmetic is not None:
        pen.setCosmetic(cosmetic)
    return pen