Exemplo n.º 1
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
Exemplo n.º 2
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 __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)
Exemplo n.º 4
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))
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
    def _make_connecting_path(self, guide_path):
        """Returns a 'thick' path connecting source and destination, by following the given 'guide' path.

        Args:
            guide_path (QPainterPath)

        Returns:
            QPainterPath
        """
        points, angles = self._points_and_angles_from_path(guide_path)
        outgoing_points = []
        incoming_points = []
        for point, angle in zip(points, angles):
            off = self._radius_from_point_and_angle(point, angle)
            outgoing_points.append(point + off)
            incoming_points.insert(0, point - off)
        p0 = guide_path.pointAtPercent(0)
        a0 = guide_path.angleAtPercent(0)
        off0 = self._radius_from_point_and_angle(p0, a0)
        curve_path = QPainterPath(p0 + off0)
        self._follow_points(curve_path, outgoing_points)
        curve_path.lineTo(incoming_points[0])
        self._follow_points(curve_path, incoming_points)
        curve_path.lineTo(p0 - off0)
        curve_path.closeSubpath()
        curve_path.setFillRule(Qt.WindingFill)
        return curve_path.simplified()
Exemplo n.º 10
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))
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
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
Exemplo n.º 15
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)
Exemplo n.º 16
0
    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)]),
        ]
Exemplo n.º 17
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)
Exemplo n.º 18
0
    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)]),
        ]
Exemplo n.º 19
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() == []
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    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)]
Exemplo n.º 22
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)
Exemplo n.º 23
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
Exemplo n.º 24
0
    def paint(self, painter, option, widget):
        painter.setPen(self.pen)
        painter.setRenderHint(QPainter.Antialiasing)

        path = QPainterPath()
        for i in range(len(self.data)):
            (x, y) = self.to_point(self.data[i][0], self.data[i][1])
            if i == 0:
                path.moveTo(0, y)
                continue
            path.lineTo(x, y)

        painter.drawPath(path)
Exemplo n.º 25
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)
Exemplo n.º 26
0
 def drawGrid(self):
     step = 4
     qpp = QPainterPath()
     for i in range(self.size):
         for j in range(self.size):
             node = self.gridNodes[i][j]
             if i % step == 0 and j % step == 0:
                 if i > 0:
                     qpp.moveTo(node.gridPos())
                     qpp.lineTo(self.gridNodes[i-step][j].gridPos())
                 if j > 0:
                     qpp.moveTo(node.gridPos())
                     qpp.lineTo(self.gridNodes[i][j-step].gridPos())
             if not node.isSelected():
                 continue
             # mark initial position
             qpp.moveTo(node.gridPos())
             qpp.lineTo(node.initialPos)
             qpp.addEllipse(node.initialPos, 5, 5)
             # mark visible neighbors
             for n in node.neighbors():
                 if n.isVisible():
                     qpp.moveTo(n.gridPos())
                     qpp.lineTo(node.gridPos())
     self.setPath(qpp)
Exemplo n.º 27
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)
Exemplo n.º 28
0
    def paint(self, painter):
        painther_path = QPainterPath()
        first = True
        top, bottom = self.light.get_top_bottom_worldspace()
        painther_path.moveTo(top.toPoint())
        for ray in self.rays:
            painther_path.lineTo((ray.pos + ray.dir * ray.length).toPoint())

        painther_path.lineTo(bottom.toPoint())
        painter.fillPath(painther_path, QColor(220, 220, 160))
        for ray in self.rays:
            if DEBUG:
                painter.setPen(QPen())
                ray.paint(painter)
Exemplo n.º 29
0
 def __paintStop(self, painter, start, color):
     path = QPainterPath()
     path.moveTo(start - self.__arrow_size / 2.0 + self.__arrow_space / 2.0,
                 0)
     path.lineTo(start + self.__item_width, 0)
     path.lineTo(start + self.__item_width, self.__item_height)
     path.lineTo(start - self.__arrow_size / 2.0 + self.__arrow_space / 2.0,
                 self.__item_height)
     path.lineTo(start + self.__arrow_size / 2.0 + self.__arrow_space / 2.0,
                 self.__item_height / 2.0)
     path.lineTo(start - self.__arrow_size / 2.0 + self.__arrow_space / 2.0,
                 0)
     painter.fillPath(path, QBrush(color))
     painter.strokePath(path, self.__pen_line)
Exemplo n.º 30
0
    def test_simple_dashes(self, p, opd):
        pen = QPen()
        pen.setDashPattern([2, 1])
        pen.setWidth(5)
        p.setPen(pen)

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

        assert opd.getOutlines() == [
            ((0.0, 0.0, 0.0, 1.0), 0.5, [(0.0, 0.0), (1.0, 0.0)]),
            ((0.0, 0.0, 0.0, 1.0), 0.5, [(1.5, 0.0), (2.5, 0.0)]),
        ]
Exemplo n.º 31
0
    def paint(self, painter):
        chunk_x = float(self.rect.width()) / self.resolution.width()
        chunk_y = float(self.rect.height()) / self.resolution.height()

        painter_path = QPainterPath()
        for i, pos in enumerate(self.path):
            x = pos.x() * chunk_x
            y = pos.y() * chunk_y
            p = QPoint(x, y)
            if i == 0:
                painter_path.moveTo(p)
            else:
                painter_path.lineTo(p)

        painter.drawPath(painter_path)
Exemplo n.º 32
0
    def paint(self, painter, *args):
        super().paint(painter, *args)

        painter.setPen(QPen(Qt.black, 2))
        painter.setBrush(Qt.white)

        path = QPainterPath()
        r = self.rect()
        path.moveTo(r.topLeft())
        path.lineTo(r.topRight() + QPointF(-5, r.height() / 2))
        path.lineTo(r.bottomLeft())
        path.closeSubpath()
        painter.drawPath(path)

        painter.drawEllipse(QPointF(r.right() - 5, r.height() / 2), 5, 5)