示例#1
0
 def updatePath(self):
     axeSize = self.size
     yZero = self.yZero
     try:
         X = []
         for item in self.fixedPoints:
             X.extend([item.B.x() + item.x(), item.C.x() + item.x()])
         X = np.array(X)
         Y = np.array(
             [-(item.A.y() + item.y())
              for item in self.fixedPoints]) + yZero
         T = displacementSpline(X,
                                Y,
                                self.xCoords,
                                clippingInterval=[-self.scene().axeSize, 0],
                                period=self.period)
         self.spline = [
             QPointF(x, y + yZero) for x, y in zip(self.xCoords, -T)
         ]  # scene coord.
         # build path
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except ValueError:
         pass
示例#2
0
class Drawer(QWidget):
    newPoint = Signal(QPoint)

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.path = QPainterPath()

    def paintEvent(self, event):
        kist = QPen()
        kist.setColor(QColor('Yellow'))
        kist.setWidth(2)
        kist.setJoinStyle(Qt.RoundJoin)
        painter = QPainter(self)
        painter.setPen(kist)
        painter.drawPath(self.path)

    def mousePressEvent(self, event):
        self.path.moveTo(event.pos())
        self.update()

    def mouseMoveEvent(self, event):
        self.path.lineTo(event.pos())
        self.newPoint.emit(event.pos())
        self.update()

    def sizeHint(self):
        return QSize(self.size().width() * 2, self.size().height() // 3)
示例#3
0
 def group_object_pixmap(self, object_class_name):
     if object_class_name in self.group_obj_pixmap_cache:
         return self.group_obj_pixmap_cache[object_class_name]
     object_pixmap = self.object_pixmap(object_class_name)
     size = object_pixmap.size()
     width, height = size.width(), size.height()
     radius = width / 8
     pen_width = width / 32
     margin = width / 16
     pen = QPen(QApplication.palette().shadow().color())
     pen.setWidth(pen_width)
     path = QPainterPath()
     path.addRoundedRect(0, 0, width, height, radius, radius)
     pixmap = QPixmap(size)
     pixmap.fill(Qt.transparent)
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.fillPath(path, QApplication.palette().window())
     painter.setPen(pen)
     painter.drawRoundedRect(pixmap.rect().adjusted(pen_width, pen_width, -pen_width, -pen_width), radius, radius)
     painter.drawPixmap(
         pixmap.rect().adjusted(margin, margin, -width / 2, -height / 2), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(width / 2, margin, -margin, -height / 2), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(width / 2, height / 2, -margin, -margin), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(margin, height / 2, -width / 2, -margin), object_pixmap, object_pixmap.rect()
     )
     painter.end()
     self.group_obj_pixmap_cache[object_class_name] = pixmap
     return pixmap
示例#4
0
    def _create_block_item(self):
        """
        Create the block background and border.
        """

        self._block_item = QPainterPath()
        self._block_item.addRect(0, 0, self.width, self.height)
示例#5
0
 def paint(self, painter, *args, **kwargs):
     margin = QMarginsF(3, 0, 3, 0)
     box = self.boundingRect().marginsAdded(margin)
     path = QPainterPath()
     path.addRoundedRect(box, 5, 5)
     painter.fillPath(path, QColor(*self.background_color))
     super().paint(painter, *args, **kwargs)
示例#6
0
 def __init__(self,
              x,
              y,
              color=Qt.white,
              fillColor=None,
              persistent=False,
              rect=None,
              parentItem=None):
     super().__init__(parent=parentItem)
     self.color = color
     self.setAcceptHoverEvents(True)
     self.persistent = persistent
     self.rect = rect
     if self.rect is not None:
         self.xmin, self.xmax, self.ymin, self.ymax = rect.left(
         ), rect.right(), rect.top(), rect.bottom()
         x = min(max(x, self.xmin), self.xmax)
         y = min(max(y, self.ymin), self.ymax)
     self.setPos(QPointF(x, y))
     self.clicked = False
     self.setPen(QPen(color, 2))
     # filling brush
     if fillColor is not None:
         self.setBrush(QBrush(fillColor))
     qpp = QPainterPath()
     # coordinates are relative to activePoint
     qpp.addEllipse(-4, -4, 8, 8)
     self.setPath(qpp)
示例#7
0
 def _get_dst_offset(self, c1):
     if not self.dst_connector:
         guide_path = QPainterPath(self.src_center)
         guide_path.quadTo(c1, self.dst_center)
         line = self._get_joint_line(guide_path).unitVector()
         return QPointF(-line.dx(), -line.dy())
     return {"left": QPointF(-1, 0), "bottom": QPointF(0, 1), "right": QPointF(1, 0)}[self.dst_connector.position]
示例#8
0
 def __init__(self, size, fixedPoints=None, parentItem=None):
     """
     Inits a cubicSpline with an empty set of control points and
     an empty curve
     @param size: initial path size
     @type size: int
     @param parentItem:
     @type parentItem: object
     """
     self.curveChanged = baseSignal_No()  # TODO added 5/11/18 validate
     super().__init__()
     if fixedPoints is None:
         fixedPoints = []
     self.setParentItem(parentItem)
     qpp = QPainterPath()
     self.size = size
     # initial curve : diagonal
     qpp.lineTo(QPoint(size, -size))
     # stroke curve
     stroker = QPainterPathStroker()
     stroker.setWidth(self.strokeWidth)
     self.mboundingPath = stroker.createStroke(qpp)
     self.setPath(self.mboundingPath)
     self.clicked = False
     #self.selected = False
     self.setVisible(False)
     self.fixedPoints = fixedPoints
     # self.spline is the list of QPointF instances to plot (scene coordinates)
     self.spline = []
     # self.LUTXY is the 1D LUT : range 0..255 --> 0..255, type ndarray, dtype=int, size=256
     self.LUTXY = np.arange(256)
     self.channel = channelValues.RGB
     self.histImg = None
     # set item pen
     self.setPen(QPen(QBrush(self.brushColor), self.penWidth))
    def drawOverlay(self, painter: QPainter) -> None:
        if not self.__showOverlay: return

        radius: int = 80
        painter.save()
        painter.setPen(Qt.NoPen)

        smallCircle: QPainterPath = QPainterPath()
        bigCircle: QPainterPath = QPainterPath()
        radius -= 1
        smallCircle.addEllipse(-radius, -radius, radius * 2, radius * 2)
        radius *= 2
        bigCircle.addEllipse(-radius, -radius + 140, radius * 2, radius * 2)

        # 高光的形状为小圆扣掉大圆的部分
        highlight: QPainterPath = smallCircle - bigCircle

        linearGradient: QLinearGradient = QLinearGradient(0, -radius / 2, 0, 0)
        self.__overlayColor.setAlpha(100)
        linearGradient.setColorAt(0.0, self.__overlayColor)
        self.__overlayColor.setAlpha(30)
        linearGradient.setColorAt(1.0, self.__overlayColor)
        painter.setBrush(linearGradient)
        painter.rotate(-20)
        painter.drawPath(highlight)

        painter.restore()
示例#10
0
    def __init__(self):
        super(Edge, self).__init__()
        self.setZValue(-1)  # Draw edges behind nodes
        self.setFlag(self.ItemIsSelectable)

        self._source: Union[Output, None] = None
        """An edge is drawn from its source to its target. Node's output is edge's source.  
        This variable represents current source as a variable of type Output.
        """
        self._target: Union[Input, None] = None
        """An edge is drawn from its source to its target. Node's input is edge's target.  
        This variable represents current target as a variable of type Input.
        """

        self._source_pos: Union[QPointF, None] = None
        """An edge is drawn from its source to its target. Node's output is edge's source.  
        This variable represents current source coordinates in scene pixels.
        """
        self._target_pos: Union[QPointF, None] = None
        """An edge is drawn from its source to its target. Node's input is edge's target.  
        This variable represents current target coordinates in scene pixels.
        """

        self._path = QPainterPath()
        self._pen = QPen()

        self.styleChange()
        self.paletteChange()
示例#11
0
    def paint(self, painter, option, widget):  # pylint: disable=unused-argument
        lod = option.levelOfDetailFromTransform(painter.worldTransform())
        should_omit_text = lod < QGraphBlock.MINIMUM_DETAIL_LEVEL

        painter.setBrush(self._config.disasm_view_node_shadow_color)
        painter.setPen(self._config.disasm_view_node_shadow_color)
        shadow_path = QPainterPath(self._block_item)
        shadow_path.translate(self.SHADOW_OFFSET_X, self.SHADOW_OFFSET_Y)
        painter.drawPath(shadow_path)

        # background of the node
        painter.setBrush(self._calc_backcolor(should_omit_text))
        if self.infodock.is_block_selected(self.addr):
            painter.setPen(
                QPen(self._config.disasm_view_selected_node_border_color, 2.5))
        else:
            painter.setPen(
                QPen(self._config.disasm_view_node_border_color, 1.5))

        self._block_item_obj = painter.drawPath(self._block_item)

        # content drawing is handled by qt since children are actual child widgets

        # if we are too far zoomed out, do not draw the text
        if self._objects_are_hidden != should_omit_text:
            self._set_block_objects_visibility(not should_omit_text)
            view = self.scene.parent()
            if view.is_extra_render_pass:
                self._objects_are_temporarily_hidden = should_omit_text
            else:
                self._objects_are_hidden = should_omit_text

        # extra content
        self.workspace.plugins.draw_block(self, painter)
示例#12
0
    def draw_NI_minimalistic(painter, c, w, h, bounding_rect):
        """
        :param painter: painter from paint event
        :param c: color
        :param w: width
        :param h: height
        :param bounding_rect: NodeInstance's bounding rect
        """

        path = QPainterPath()
        path.moveTo(-w / 2, 0)

        path.cubicTo(-w / 2, -h / 2, -w / 2, -h / 2, 0, -h / 2)
        path.cubicTo(+w / 2, -h / 2, +w / 2, -h / 2, +w / 2, 0)
        path.cubicTo(+w / 2, +h / 2, +w / 2, +h / 2, 0, +h / 2)
        path.cubicTo(-w / 2, +h / 2, -w / 2, +h / 2, -w / 2, 0)
        path.closeSubpath()

        body_gradient = QLinearGradient(bounding_rect.bottomLeft(),
                                        bounding_rect.topRight())
        body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150))
        body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80))

        painter.setBrush(body_gradient)
        painter.setPen(QPen(QColor(30, 43, 48)))

        painter.drawPath(path)
示例#13
0
    def __init__(self, edge, parent=None):
        super().__init__(parent)

        self.edge = edge
        self.rect = None
        self._start = QPointF(*self.edge.coordinates[0])
        self.coords = [self.create_point(c) for c in self.edge.coordinates]
        self.end = self.coords[-1]

        if self.edge.sort == EdgeSort.BACK_EDGE:
            # it's a back edge
            # Honey
            self.color = QColor(0xf9, 0xd5, 0x77)
        elif self.edge.sort == EdgeSort.TRUE_BRANCH:
            # True branch
            # Aqar
            self.color = QColor(0x79, 0xcc, 0xcd)
        elif self.edge.sort == EdgeSort.FALSE_BRANCH:
            # False branch
            # Tomato
            self.color = QColor(0xf1, 0x66, 0x64)
        else:
            # Dark Gray
            self.color = QColor(0x56, 0x5a, 0x5c)
        self.arrow = [
            QPointF(self.end.x() - 3, self.end.y()),
            QPointF(self.end.x() + 3, self.end.y()),
            QPointF(self.end.x(),
                    self.end.y() + 6)
        ]
        #self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
        path = QPainterPath(self.coords[0])
        for c in self.coords[1:] + self.arrow:
            path.lineTo(c)
        self.path = path
示例#14
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.save()
        path = QPainterPath()

        painter.setFont(self.font)
        painter.setRenderHint(QPainter.Antialiasing)

        pen = QPen(QColor(0, 0, 0, 230))
        pen_width = 3
        pen.setWidth(pen_width)

        len = self.metrics.width(self.txt)
        w = self.width()
        px = (len - w) / 2
        if px < 0:
            px = -px
        py = (self.height() - self.metrics.height()) / 2 + self.metrics.ascent()
        if py < 0:
            py = -py

        path.addText(px + 2, py + 2, self.font, self.txt)
        painter.strokePath(path, pen)
        painter.drawPath(path)
        painter.fillPath(path, QBrush(self.color))
        painter.restore()
示例#15
0
 def __init__(self, x, y, persistent=False, rect=None, parentItem=None):
     """
     Interactive control point for the scene current spline.
     Persistent activePoints cannot be removed
     by mouse click (default is non persistent). If rect is not None,
     the moves of the point are restricted to rect.
     @param x: initial x-coordinate
     @type x: float
     @param y: initial y-coordinate
     @type y: float
     @param persistent: persistent flag
     @type persistent: boolean
     @param parentItem:
     @type parentItem: object
     """
     super(activePoint, self).__init__()
     self.tangent = None  # link to tangent : used only by qudratic spline
     self.setAcceptHoverEvents(True)
     self.setParentItem(parentItem)
     self.persistent = persistent
     self.rect = rect
     if self.rect is not None:
         self.xmin, self.xmax, self.ymin, self.ymax = rect.left(
         ), rect.right(), rect.top(), rect.bottom()
         x = min(max(x, self.xmin), self.xmax)
         y = min(max(y, self.ymin), self.ymax)
     self.setPos(QPointF(x, y))
     self.clicked = False
     self.setPen(QPen(QColor(255, 255, 255), 2))
     qpp = QPainterPath()
     # coordinates are relative to activePoint
     qpp.addEllipse(-4, -4, 8, 8)
     self.setPath(qpp)
示例#16
0
    def drawValue(self, p, baseRect, value, arcLength):
        # nothing to draw
        if value == self.min:
            return

        # for Line style
        if self.barStyle == self.StyleLine:
            p.setPen(
                QPen(self.palette().highlight().color(), self.dataPenWidth))
            p.setBrush(Qt.NoBrush)
            p.drawArc(
                baseRect.adjusted(self.outlinePenWidth / 2,
                                  self.outlinePenWidth / 2,
                                  -self.outlinePenWidth / 2,
                                  -self.outlinePenWidth / 2),
                self.nullPosition * 16, -arcLength * 16)
            return

        # for Pie and Donut styles
        dataPath = QPainterPath()
        dataPath.setFillRule(Qt.WindingFill)

        # pie segment outer
        dataPath.moveTo(baseRect.center())
        dataPath.arcTo(baseRect, self.nullPosition, -arcLength)
        dataPath.lineTo(baseRect.center())

        p.setBrush(self.palette().highlight())
        p.setBrush(QColor(255, 255, 255, 255 * 0.3))

        # pen = QtGui.QPen(self.palette().shadow().color(), self.dataPenWidth)
        pen = QPen(self.palette().shadow().color(), -1)
        p.setPen(pen)
        p.drawPath(dataPath)
示例#17
0
    def paintEvent(self, event: QPaintEvent):
        super().paintEvent(event)

        if self._viewport_anchoring_scheduled:
            self._anchor_viewport()
            self._viewport_anchoring_scheduled = False

        painter = QPainter(self.viewport())
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QColor(123, 184, 234))
        painter.setPen(QPen(Qt.white, 0.5))

        scale_text = f'{self._cur_scale * 100:.0f}%'
        scale_text_bounding_rect = self._scale_font_metrics.boundingRect(
            scale_text)
        viewport_rect = self.viewport().rect()
        # Align the scale text to (Qt.AlignHCenter | Qt.AlignBottom)
        pad = 2
        self._scale_text_rect = QRect(viewport_rect.width() / 2 - scale_text_bounding_rect.width() / 2,
                                      viewport_rect.height() - scale_text_bounding_rect.height() - 6,
                                      scale_text_bounding_rect.width(), scale_text_bounding_rect.height())\
            .adjusted(-pad, -pad, pad, pad)  # add pads to update when scrolling without artifacts

        # Use QPainterPath to draw text with outline
        path = QPainterPath()
        path.addText(self._scale_text_rect.bottomLeft(), self._scale_font,
                     scale_text)
        painter.drawPath(path)
    def __init__(self, edge, disasm_view, infodock, parent=None):
        super().__init__(parent)

        self.edge = edge
        self.disasm_view = disasm_view
        self.infodock = infodock
        self.rect = None
        self._start = QPointF(*self.edge.coordinates[0])
        self.coords = [self.create_point(c) for c in self.edge.coordinates]
        self.end = self.coords[-1]

        self.color = EDGE_COLORS.get(self.edge.sort,
                                     EDGE_COLORS[EdgeSort.DIRECT_JUMP])
        self.arrow = [
            QPointF(self.end.x() - 3, self.end.y()),
            QPointF(self.end.x() + 3, self.end.y()),
            QPointF(self.end.x(),
                    self.end.y() + 6)
        ]
        self.style = EDGE_STYLES.get(self.edge.sort,
                                     EDGE_STYLES[EdgeSort.DIRECT_JUMP])
        #self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
        path = QPainterPath(self.coords[0])
        for c in self.coords[1:] + self.arrow:
            path.lineTo(c)
        self.path = path

        self._hovered = False

        self.setAcceptHoverEvents(True)
示例#19
0
    def paint(self, painter, option, widget):
        path = QPainterPath()

        path.addRoundedRect(self.rect, 5, 5)

        painter.setBrush(QColor(255, 255, 255))
        painter.drawPath(path)
        painter.drawText(self.text_rect, self.text)
示例#20
0
 def update(self):
     qpp = QPainterPath()
     trans = QPointF(-4, -4)
     # coordinates are relative to activeTriangle
     for p in [self.A, self.B, self.C]:
         qpp.addEllipse(p + trans, 4, 4)
     self.setPath(qpp)
     super().update()
    def test_text(self, p, opd):
        font = QFont()
        path = QPainterPath()
        path.addText(0, 0, font, "T")
        p.drawPath(path)

        lines = opd.getOutlines()
        assert len(lines) == 1
示例#22
0
def _generate_path(coord):
    path = QPainterPath()
    path.moveTo(*coord[0])
    path.lineTo(*coord[1])
    path.lineTo(*coord[2])
    path.lineTo(*coord[3])
    path.closeSubpath()
    return path
示例#23
0
    def shape(self):
        frame_corner_radius = self.style().pixelMetric(
            Style.NodeFrameCornerRadius)

        path = QPainterPath()
        path.addRoundedRect(QRectF(QPointF(0, 0), self.size()),
                            frame_corner_radius, frame_corner_radius)

        return path
示例#24
0
 def _draw_wire(self, painter, line):
     p = QPen(Qt.black, 8, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)
     path = QPainterPath(line.p1())
     path.lineTo(line.p2())
     stroker = QPainterPathStroker(p)
     stroke = stroker.createStroke(path)
     painter.setPen(QPen(Qt.black, 2))
     painter.fillPath(stroke, Qt.white)
     painter.drawPath(stroke)
示例#25
0
 def updatePath(self, calculate=True):
     """
     Calculates (if calculate=true) and displays the spline.
     Called by activePoint and activeTangent mouse event
     @param calculate:
     @type calculate: bool
     """
     # calculate the array of slopes
     d = [
         item.controlPoint - item.contactPoint
         for item in self.fixedTangents
     ]
     d1 = -np.array(list(map(lambda a: a.y(), d)))
     d2 = np.array(list(map(lambda a: a.x(), d)))
     d = d1 / d2
     # add boundary points if needed
     X = [item.x() for item in self.fixedPoints]
     Y = [item.y() for item in self.fixedPoints]
     X0, X1 = X[0], X[-1]
     Y0, Y1 = Y[0], Y[-1]
     t = (Y1 - Y0) / (X1 - X0)
     Y2 = Y0 - X0 * t
     Y3 = Y0 + (self.size - X0) * t
     d = d.tolist()
     if X[0] > 0.0:
         X.insert(0, 0.0)
         Y.insert(0, Y2)
         d.insert(0, t)
     if X[-1] < self.size:
         X.append(self.size)
         Y.append(Y3)
         d.append(t)
     d = np.array(d)
     try:
         if calculate:
             T = interpolationQuadSpline(
                 np.array(X) / self.size, -np.array(Y) / self.size,
                 d) * self.size
             self.spline = [
                 QPointF(x, y)
                 for x, y in zip(np.arange(256) * (self.size / 255.0), -T)
             ]
         for P in self.spline:
             if P.x() < X0:
                 P.setY(Y0)
             elif P.x() > X1:
                 P.setY(Y1)
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except Exception as e:
         print(str(e))
示例#26
0
 def paint(self, painter, *args, **kwargs):
     if self.hovered:
         margin = QMarginsF(7, 5, 7, 5)
     else:
         margin = QMarginsF(3, 0, 3, 0)
     box = self.boundingRect().marginsAdded(margin)
     path = QPainterPath()
     path.addRoundedRect(box, 5, 5)
     painter.fillPath(path, self.background_color)
     super().paint(painter, *args, **kwargs)
示例#27
0
    def addArrow(self, p1, p2, color=BLACK):
        p5.stroke(color)

        self.addLine(p1, p2)

        to_int = (int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]))
        if to_int in ARROW_CACHE:
            arrow = ARROW_CACHE[to_int]

        else:
            p1 = QPoint(*p1)
            p2 = QPoint(*p2)

            path = QPainterPath()
            path.moveTo(p1)
            path.lineTo(p2)

            line = QLineF(p1, p2)

            end = p2
            pathlen = path.length()
            leng = min(10, pathlen / 4.0)
            arrowbase = path.pointAtPercent(path.percentAtLength(pathlen - leng))
            l1 = QLineF(arrowbase, end)
            l2 = QLineF(arrowbase, end)
            l1.setAngle(line.angle() - 150)
            l2.setAngle(line.angle() + 150)
            l1.setLength(l1.length() / 2.0)
            l2.setLength(l2.length() / 2.0)

            arrow = (arrowbase.toTuple(), l1.p2().toTuple(), end.toTuple(), l2.p2().toTuple())
            ARROW_CACHE[to_int] = arrow

        p5.fill(color)
        p5.quad(*arrow)
    def shape(self):
        """
		Returns the shape of this item as a QPainterPath in local coordinates.
		The shape could be used for many things, like collision detection.

		:return: Returns the shape of this item as a QPainterPath in local coordinates.
		:rtype: QPainterPath
		"""
        path = QPainterPath()
        path.addRect(self.boundingRect())
        return path
示例#29
0
    def _make_ellipse_path(self):
        """Returns an ellipse path for the link's base.

        Returns:
            QPainterPath
        """
        ellipse_path = QPainterPath()
        rect = QRectF(0, 0, 1.6 * self.magic_number, 1.6 * self.magic_number)
        rect.moveCenter(self.src_center)
        ellipse_path.addEllipse(rect)
        return ellipse_path
示例#30
0
def _draw_chromosone(painter, chromosone, total_triangles, size=(250, 250)):
    brush = _create_brush(0, 0, 0, 0)
    painter_path = QPainterPath()
    for i in range(total_triangles):
        _draw_triangle(brush,
                       painter_path,
                       painter,
                       chromosone,
                       offset=i,
                       size=size)
        painter_path.clear()
示例#31
0
    def paintEvent(self, event):
        rect = QRect(10, 20, 80, 60)

        path = QPainterPath()
        path.moveTo(20, 80)
        path.lineTo(20, 30)
        path.cubicTo(80, 0, 50, 50, 80, 80)

        startAngle = 30 * 16
        arcLength = 120 * 16

        painter = QPainter(self)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        if self.antialiased:
            painter.setRenderHint(QPainter.Antialiasing)

        for x in range(0, self.width(), 100):
            for y in range(0, self.height(), 100):
                painter.save()
                painter.translate(x, y)
                if self.transformed:
                    painter.translate(50, 50)
                    painter.rotate(60.0)
                    painter.scale(0.6, 0.9)
                    painter.translate(-50, -50)

                if self.shape == RenderArea.Line:
                    painter.drawLine(rect.bottomLeft(), rect.topRight())
                elif self.shape == RenderArea.Points:
                    painter.drawPoints(RenderArea.points)
                elif self.shape == RenderArea.Polyline:
                    painter.drawPolyline(RenderArea.points)
                elif self.shape == RenderArea.Polygon:
                    painter.drawPolygon(RenderArea.points)
                elif self.shape == RenderArea.Rect:
                    painter.drawRect(rect)
                elif self.shape == RenderArea.RoundedRect:
                    painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize)
                elif self.shape == RenderArea.Ellipse:
                    painter.drawEllipse(rect)
                elif self.shape == RenderArea.Arc:
                    painter.drawArc(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Chord:
                    painter.drawChord(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Pie:
                    painter.drawPie(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Path:
                    painter.drawPath(path)
                elif self.shape == RenderArea.Text:
                    painter.drawText(rect, Qt.AlignCenter,
                                     "PySide 2\nQt %s" % qVersion())
                elif self.shape == RenderArea.Pixmap:
                    painter.drawPixmap(10, 10, self.pixmap)

                painter.restore()

        painter.setPen(self.palette().dark().color())
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
示例#32
0
    def paint(self, painter, option, widget):
        path = QPainterPath()
        path.addRoundedRect(self._rect, 5, 5)
        anchor = self.mapFromParent(self._chart.mapToPosition(self._anchor))
        if not self._rect.contains(anchor) and not self._anchor.isNull():
            point1 = QPointF()
            point2 = QPointF()

            # establish the position of the anchor point in relation to _rect
            above = anchor.y() <= self._rect.top()
            aboveCenter = (anchor.y() > self._rect.top() and
                anchor.y() <= self._rect.center().y())
            belowCenter = (anchor.y() > self._rect.center().y() and
                anchor.y() <= self._rect.bottom())
            below = anchor.y() > self._rect.bottom()

            onLeft = anchor.x() <= self._rect.left()
            leftOfCenter = (anchor.x() > self._rect.left() and
                anchor.x() <= self._rect.center().x())
            rightOfCenter = (anchor.x() > self._rect.center().x() and
                anchor.x() <= self._rect.right())
            onRight = anchor.x() > self._rect.right()

            # get the nearest _rect corner.
            x = (onRight + rightOfCenter) * self._rect.width()
            y = (below + belowCenter) * self._rect.height()
            cornerCase = ((above and onLeft) or (above and onRight) or
                (below and onLeft) or (below and onRight))
            vertical = abs(anchor.x() - x) > abs(anchor.y() - y)

            x1 = (x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase *
                int(not vertical) * (onLeft * 10 - onRight * 20))
            y1 = (y + aboveCenter * 10 - belowCenter * 20 + cornerCase *
                vertical * (above * 10 - below * 20))
            point1.setX(x1)
            point1.setY(y1)

            x2 = (x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase *
                int(not vertical) * (onLeft * 20 - onRight * 10))
            y2 = (y + aboveCenter * 20 - belowCenter * 10 + cornerCase *
                vertical * (above * 20 - below * 10))
            point2.setX(x2)
            point2.setY(y2)

            path.moveTo(point1)
            path.lineTo(anchor)
            path.lineTo(point2)
            path = path.simplified()

        painter.setBrush(QColor(255, 255, 255))
        painter.drawPath(path)
        painter.drawText(self._textRect, self._text)