Beispiel #1
0
    def to_svg(self, path, scale=10, dpi=100, title='', description=''):
        """Render the scene to SVG"""

        from QtShim.QtSvg import QSvgGenerator

        generator = QSvgGenerator()
        generator.setFileName(str(path))

        generator.setTitle(str(title))
        generator.setDescription(str(description))
        generator.setResolution(dpi)

        # Fixme: scale
        # Scale applied to (x,y) and radius but not line with
        self._scale = scale

        bounding_box = self._scene.bounding_box
        size = QSize(*[x * self._scale for x in bounding_box.size])
        view_box = QRectF(*[x * self._scale for x in bounding_box.rect])
        generator.setSize(size)
        generator.setViewBox(view_box)

        painter = QPainter()
        painter.begin(generator)
        self.paint(painter)
        painter.end()

        self._scale = None
Beispiel #2
0
    def paint_ImageItem(self, item):

        vertices = self.cast_item_positions(item)
        rec = QRectF(vertices[0], vertices[1])

        image = item.image
        height, width, bytes_per_line = image.shape
        bytes_per_line *= width
        qimage = QImage(image, width, height, bytes_per_line,
                        QImage.Format_RGB888)

        self._painter.drawImage(rec, qimage)
Beispiel #3
0
    def _paint_arc(self, item, center, radius_x, radius_y):

        if item.is_closed:
            self._painter.drawEllipse(center, radius_x, radius_y)
        else:
            # drawArc cannot be filled !
            rectangle = QRectF(
                center + QPointF(-radius_x, radius_y),
                center + QPointF(radius_x, -radius_y),
            )
            start_angle, stop_angle = [
                int(angle * 16)
                for angle in (item.start_angle, item.stop_angle)
            ]
            span_angle = stop_angle - start_angle
            if span_angle < 0:
                span_angle = 5760 + span_angle
            self._painter.drawArc(rectangle, start_angle, span_angle)