Beispiel #1
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)
Beispiel #2
0
    def paintEvent(self, *args):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setBrush(Qt.black)
        painter.setPen(QPen(Qt.transparent))
        for block in self.blocks:
            painter.drawRect(block)

        if self.debug:
            lines = list()
            points = list()
            for p1 in self.graph:
                for p2 in self.graph[p1]:
                    lines.append(QLine(*p1, *p2))
                    points.append(QPoint(*p1))
                    points.append(QPoint(*p2))

            painter.setPen(QPen(Qt.black))
            painter.drawLines(lines)
            painter.setPen(QPen(Qt.red, 3))
            painter.drawPoints(points)

        if self.path:
            painter.setPen(QPen(Qt.green))
            painter.setBrush(Qt.transparent)
            p = QPainterPath()
            p.moveTo(*self.path[0])
            for point in self.path:
                p.lineTo(*point)
            painter.drawPath(p)
    def paint(self, painter):
        painter.setPen(QPen(self.sky_color))
        painter.setBrush(QBrush(self.sky_color))
        painter.drawRect(0, 0, self.width, self.height)

        hwidth = self.width / 2
        hheight = self.height / 2
        for star in self.stars:
            x = hwidth + star.pos.x() * star.pos.z() * hwidth * 2
            y = hheight + star.pos.y() * star.pos.z() * hheight * 2

            prev_x = hwidth + star.pos.x() * star.prev_z * hwidth * 2
            prev_y = hheight + star.pos.y() * star.prev_z * hheight * 2

            size = 3.0 * star.pos.z()
            c = star.pos.z() * star.max_star_white
            star_color = QColor(c, c, c)
            painter.setPen(QPen(star_color))
            painter.setBrush(QBrush(star_color))
            painter.drawEllipse(x - size / 2, y - size / 2, size, size)
            painter.drawLine(x, y, prev_x, prev_y)

            painter_path = QPainterPath()

            painter_path.moveTo(QPoint(x, y))
            for prev_i_z in star.prev_zs:
                prev_i_x = hwidth + star.pos.x() * prev_i_z * hwidth * 2
                prev_i_y = hheight + star.pos.y() * prev_i_z * hheight * 2
                painter_path.lineTo(QPoint(prev_i_x, prev_i_y))

            c = star.pos.z() * star.max_tail_white
            trail_color = QColor(c, c, c)
            painter.setPen(QPen(trail_color))
            painter.drawPath(painter_path)
 def updatePath(self):
     qpp = QPainterPath()
     # coordinates are relative to activeTangent object
     qpp.moveTo(0, 0)
     qpp.lineTo((self.controlPoint - self.contactPoint))
     qpp.addEllipse(self.controlPoint - self.contactPoint, 5.0, 5.0)
     self.setPath(qpp)
Beispiel #5
0
    def draw_border(self, painter):
        painter.save()
        painter.translate(0, self.t_height)

        if in_range(self.red_offset, self.l, self.r):
            # non-red zone
            path = QPainterPath()
            path.moveTo(self.red_offset, 0)
            path.lineTo(self.l, 0)
            path.lineTo(self.l, self.bar_height)
            path.lineTo(self.red_offset, self.bar_height)

            painter.drawPath(path)

            # red zone
            path = QPainterPath()
            path.moveTo(self.red_offset, 0)
            path.lineTo(self.r, 0)
            path.lineTo(self.r, self.bar_height)
            path.lineTo(self.red_offset, self.bar_height)

            painter.setPen(self.red_pen)
            painter.drawPath(path)

        else:
            painter.drawRect(QRect(
                self.l,
                self.l,
                self.r - self.l,
                self.bar_height,
            ))

        painter.restore()
Beispiel #6
0
    def paintEvent(self, event):
        super(BubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形
        triPath = QPainterPath()  # 底部三角形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        triPath.moveTo(x, height)  # 移动到底部横线4/5处
        # 画三角形
        triPath.lineTo(x + 6, height + 8)
        triPath.lineTo(x + 12, height)

        rectPath.addPath(triPath)  # 添加三角形到之前的矩形上

        # 边框画笔
        painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine,
                            Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
        # 三角形底边绘制一条线保证颜色与背景一样
        painter.setPen(QPen(self.BackgroundColor, 1,
                            Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(x, height, x + 12, height)
Beispiel #7
0
    def paintEvent(self, event):
        """
        custom paint event to draw horizontal line and handles at current y level
        """
        super().paintEvent(event)
        painter = QPainter(self)
        #painter.beginNativePainting()
        #painter.setRenderHint(QPainter.Antialiasing)
        x1,y1,x2,y2 = self.rect().getCoords()
        #painter.setPen(QPen(Qt.gray, 1))
        #painter.drawRect(self.rect())
        painter.setPen(QPen(COLOR, 1))
        painter.drawLine(QPoint(x1, y1+(y2-y1)/2), QPoint(x2, y1+(y2-y1)/2))
        path = QPainterPath()
        path.moveTo(x1, y1)
        path.lineTo(x1, y1 + y2)
        path.lineTo(10, y1 + y2/2)
        path.lineTo(x1, y1)
        painter.fillPath(path, QBrush(COLOR))
        path = QPainterPath()
        path.moveTo(x2+1, y1)
        path.lineTo(x2+1, y1 + y2)
        path.lineTo(x2 - 9, y1 + y2/2)
        path.lineTo(x2+1, y1)
        painter.fillPath(path, QBrush(COLOR))

        #painter.endNativePainting()
        painter.end()
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
0
    def draw_tron_minimalistic(self,
                               painter,
                               background_color=QColor('#36383B')):
        path = QPainterPath()
        path.moveTo(-self.width / 2, 0)

        corner_size = 10
        path.lineTo(-self.width / 2 + corner_size / 2,
                    -self.height / 2 + corner_size / 2)
        path.lineTo(0, -self.height / 2)
        path.lineTo(+self.width / 2 - corner_size / 2,
                    -self.height / 2 + corner_size / 2)
        path.lineTo(+self.width / 2, 0)
        path.lineTo(+self.width / 2 - corner_size / 2,
                    +self.height / 2 - corner_size / 2)
        path.lineTo(0, +self.height / 2)
        path.lineTo(-self.width / 2 + corner_size / 2,
                    +self.height / 2 - corner_size / 2)
        path.closeSubpath()

        painter.setBrush(background_color)
        pen = QPen(self.parent_node.color)
        pen.setWidth(2)
        painter.setPen(pen)

        painter.drawPath(path)
Beispiel #11
0
    def paint(self, painter, *args):
        super().paint(painter, *args)

        kind = self.desc.kind
        painter.setPen(QPen(Qt.black, 2))
        path = QPainterPath()
        r = self.rect()

        if kind == 'and':
            path.moveTo(r.topLeft())
            path.lineTo(r.center().x(), r.top())
            path.quadTo(r.topRight(), QPoint(r.right(), r.height() / 2))
            path.quadTo(r.bottomRight(), QPoint(r.width() / 2, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.closeSubpath()
        elif kind == 'or':
            path.moveTo(r.topLeft())
            path.lineTo(r.width() / 4, r.top())
            path.quadTo(QPoint(r.width() / 4 * 3, r.top()),
                        QPoint(r.right(),
                               r.height() / 2))
            path.quadTo(QPoint(r.width() / 4 * 3, r.bottom()),
                        QPoint(r.width() / 4, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.quadTo(r.center(), r.topLeft())

        painter.drawPath(path)
Beispiel #12
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))
    def paint(self,
              painter: QPainter,
              option: QStyleOptionGraphicsItem,
              widget: Optional[QWidget] = ...):
        painter.setPen(self.pen())
        brush = self.brush()
        painter.setBrush(brush)
        path = QPainterPath()
        path.moveTo(self.__sourcePoint)
        path.cubicTo(self._edge1, self._edge2, self.__destPoint)
        if self._isDigraph:
            painter.setBrush(Qt.gray)
            painter.drawPolygon(self.drawArrow())
            path.addPolygon(self.drawArrow())
        painter.setBrush(Qt.NoBrush)
        if self.isSelected():
            pen = painter.pen()
            pen.setColor(self.get_isSelectedPenColor())
        else:
            pen = painter.pen()
            pen.setColor(self.get_noSelectedPenColor())
        painter.setPen(pen)

        painter.drawPath(path)
        self.__path = path
    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))
Beispiel #15
0
    def connection_path(p1: QPointF, p2: QPointF):
        """Returns the nice looking QPainterPath of a connection for two given points."""

        path = QPainterPath()

        path.moveTo(p1)

        distance_x = abs(p1.x()) - abs(p2.x())
        distance_y = abs(p1.y()) - abs(p2.y())

        if ((p1.x() < p2.x() - 30)
                or math.sqrt((distance_x**2) +
                             (distance_y**2)) < 100) and (p1.x() < p2.x()):
            path.cubicTo(p1.x() + ((p2.x() - p1.x()) / 2), p1.y(),
                         p1.x() + ((p2.x() - p1.x()) / 2), p2.y(), p2.x(),
                         p2.y())
        elif p2.x() < p1.x() - 100 and abs(distance_x) / 2 > abs(distance_y):
            path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 10, p1.y(),
                         p1.x() + 100 + (p1.x() - p2.x()) / 10,
                         p1.y() - (distance_y / 2),
                         p1.x() - (distance_x / 2),
                         p1.y() - (distance_y / 2))
            path.cubicTo(p2.x() - 100 - (p1.x() - p2.x()) / 10,
                         p2.y() + (distance_y / 2),
                         p2.x() - 100 - (p1.x() - p2.x()) / 10, p2.y(), p2.x(),
                         p2.y())
        else:
            path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 3, p1.y(),
                         p2.x() - 100 - (p1.x() - p2.x()) / 3, p2.y(), p2.x(),
                         p2.y())
        return path
Beispiel #16
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)
Beispiel #17
0
    def draw_NI_minimalistic(painter,
                             c,
                             w,
                             h,
                             background_color=QColor('#36383B')):
        """
        :param painter: painter from paint event
        :param c_s: corner size/corner radius
        :param c: color
        :param w: width
        :param h: height
        :param background_color: (default) background color
        """

        c_s = 10

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

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

        painter.setBrush(background_color)
        pen = QPen(c)
        pen.setWidth(2)
        painter.setPen(pen)

        painter.drawPath(path)
Beispiel #18
0
    def draw_dark_minimalistic(self, painter):
        path = QPainterPath()
        path.moveTo(-self.width / 2, 0)

        path.cubicTo(-self.width / 2, -self.height / 2,
                     -self.width / 2, -self.height / 2,
                     0, -self.height / 2)
        path.cubicTo(+self.width / 2, -self.height / 2,
                     +self.width / 2, -self.height / 2,
                     +self.width / 2, 0)
        path.cubicTo(+self.width / 2, +self.height / 2,
                     +self.width / 2, +self.height / 2,
                     0, +self.height / 2)
        path.cubicTo(-self.width / 2, +self.height / 2,
                     -self.width / 2, +self.height / 2,
                     -self.width / 2, 0)
        path.closeSubpath()

        c = self.parent_node.color
        body_gradient = QLinearGradient(self.boundingRect().bottomLeft(),
                                        self.boundingRect().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)
Beispiel #19
0
    def drawBezierCurve(self, qp):

        path = QPainterPath()
        path.moveTo(30, 30)
        path.cubicTo(30, 30, 200, 350, 350, 30)     # 二阶贝塞尔曲线(cubic: 立方体)
                                                    # 起始点, 控制点, 终止点

        qp.drawPath(path)       # 让画家照着path描画
Beispiel #20
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
Beispiel #21
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):
            point1 = QPointF()
            point2 = QPointF()

            # establish the position of the anchor point in relation to m_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 m_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 = qAbs(anchor.x() - x) > qAbs(anchor.y() - y)

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

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

            point1.setX(x1)
            point1.setY(y1)
            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.text_rect, self.text)
    def test_simple_path(self, p, opd):
        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(10, 20)
        p.drawPath(path)

        assert opd.getOutlines() == [
            ((0.0, 0.0, 0.0, 1.0), 0.1, [(0.0, 0.0), (1.0, 2.0)]),
        ]
Beispiel #23
0
 def __paintOnlyOne(self, painter, color):
     path = QPainterPath()
     path.moveTo(0, 0)
     path.lineTo(self.__item_width, 0)
     path.lineTo(self.__item_width, self.__item_height)
     path.lineTo(0, self.__item_height)
     path.lineTo(0, 0)
     painter.fillPath(path, QBrush(color))
     painter.strokePath(path, self.__pen_line)
    def test_transformed_path(self, p, opd):
        p.scale(10, 10)
        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(1, 2)
        p.drawPath(path)

        assert opd.getOutlines() == [
            ((0.0, 0.0, 0.0, 1.0), 1.0, [(0.0, 0.0), (1.0, 2.0)]),
        ]
    def test_no_pen(self, p, opd):
        pen = QPen()
        pen.setStyle(Qt.PenStyle.NoPen)
        p.setPen(pen)

        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(10, 20)
        p.drawPath(path)

        assert opd.getOutlines() == []
    def test_no_brush(self, p, opd):
        brush = QBrush()
        brush.setStyle(Qt.BrushStyle.NoBrush)
        pen = QPen()
        pen.setBrush(brush)
        p.setPen(pen)

        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(10, 20)
        p.drawPath(path)
    def test_singular_transformed_path(self, p, opd):
        p.scale(10, 0)
        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(1, 2)
        p.drawPath(path)

        out = opd.getOutlines()
        assert len(out) == 1
        colour, width, lines = out[0]
        assert colour == (0.0, 0.0, 0.0, 1.0)
        assert lines == [(0.0, 0.0), (1.0, 0.0)]
Beispiel #28
0
 def get_extended_body_path_TRON_DESIGN(self, corner_size):
     path = QPainterPath()
     path.moveTo(+self.width/2, -self.height/2+corner_size)
     path.lineTo(+self.width/2-corner_size, -self.height/2)
     path.lineTo(-self.width/2+corner_size, -self.height/2)
     path.lineTo(-self.width/2, -self.height/2+corner_size)
     path.lineTo(-self.width/2, +self.height/2-corner_size)
     path.lineTo(-self.width/2+corner_size, +self.height/2)
     path.lineTo(+self.width/2-corner_size, +self.height/2)
     path.lineTo(+self.width/2, +self.height/2-corner_size)
     path.closeSubpath()
     return path
Beispiel #29
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)
Beispiel #30
0
    def path(self):
        """Compute and return QPainterPath that is used to draw the curved line.  
        Internal function use this to reset their path in response to external changes. 
        """
        if self._source_pos is None or self._target_pos is None:
            return QPainterPath()

        result = QPainterPath()
        result.moveTo(self._source_pos)
        result.cubicTo(self._bezier_point_1(), self._bezier_point_2(),
                       self._target_pos)

        return result
Beispiel #31
0
    def paint(self, painter):
        painter.setPen(QPen(Qt.black, 2))
        painter.setBrush(Qt.white)

        path = QPainterPath()
        s = self.SIZE
        path.moveTo(QPoint())
        path.lineTo(QPoint(s.width() - 5, s.height() / 2))
        path.lineTo(QPoint(0, s.height()))
        path.closeSubpath()
        painter.drawPath(path)

        painter.drawEllipse(QPoint(s.width() - 2, s.height() / 2), 3, 3)
Beispiel #32
0
    def build_path(self, points, scale=1):
        path = QPainterPath()

        if len(points) > 0:
            p0 = self.projectPointToCanvas(points[0], scale)
            path.moveTo(p0)

            for p in points[1:]:
                cp = self.projectPointToCanvas(p, scale)
                path.lineTo(cp)
            path.lineTo(p0)

        return path