Ejemplo n.º 1
0
    def paint_pixmap(self):
        progress = self.progress
        status = self.status
        self.progress = 0
        self.status = ActionStatus.IDLE
        rect = self.boundingRect()
        pixmap = QPixmap(rect.size().toSize())
        pixmap.fill(Qt.transparent)

        painter = QPainter(pixmap)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.translate(-rect.topLeft())

        for child in self.childItems():
            if child.flags() & QGraphicsItem.ItemStacksBehindParent:
                painter.save()
                painter.translate(child.mapToParent(self.pos()))
                child.paint(painter, QStyleOptionGraphicsItem(), None)
                painter.restore()

        self.paint(painter, QStyleOptionGraphicsItem())
        for child in self.childItems():
            if not child.flags() & QGraphicsItem.ItemStacksBehindParent:
                painter.save()
                painter.translate(child.mapToParent(self.pos()))
                child.paint(painter, QStyleOptionGraphicsItem(), None)
                painter.restore()

        painter.end()
        self.progress = progress
        self.status = status
        return pixmap
Ejemplo n.º 2
0
    def paint(self, painter, option, widget=None):
        """Overload QGraphicsPathItem method."""

        new_option = QStyleOptionGraphicsItem(option)
        # suppress the "selected" state
        # this avoids the dashed rectangle surrounding the ray when selected
        new_option.state = QStyle.State_None
        QGraphicsPathItem.paint(self, painter, new_option, widget)
Ejemplo n.º 3
0
 def paintEvent(self, event):
     global All_Cells
     qp = QPainter(self)
     qp.setRenderHint(QPainter.Antialiasing, True)
     gone_circle = Circle(self.res_x, self.res_y, self.gone - cell_radius)
     gone_circle.paint(qp, QStyleOptionGraphicsItem())
     qp.setPen(QColor(Qt.red))
     qp.setBrush(QColor(Qt.blue))
     self.resource.paint(qp, QStyleOptionGraphicsItem())
     for cell in All_Cells:
         qp.setBrush(cell.color)
         cell.paint(qp, QStyleOptionGraphicsItem())
     qp.setPen(QColor(Qt.blue))
Ejemplo n.º 4
0
    def createImage(self, transform):
        if self.type == DemoTextItem.DYNAMIC_TEXT:
            return None

        sx = min(transform.m11(), transform.m22())
        sy = max(transform.m22(), sx)

        textItem = QGraphicsTextItem()
        textItem.setHtml(self.text)
        textItem.setTextWidth(self.textWidth)
        textItem.setFont(self.font)
        textItem.setDefaultTextColor(self.textColor)
        textItem.document().setDocumentMargin(2)

        w = textItem.boundingRect().width()
        h = textItem.boundingRect().height()
        image = QImage(int(w * sx), int(h * sy),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.scale(sx, sy)
        style = QStyleOptionGraphicsItem()
        textItem.paint(painter, style, None)

        return image
Ejemplo n.º 5
0
    def get_icons(size: int, border: int = 2):

        # names and example items
        roi_names = []
        roi_items = []
        extent = border + size
        roi_names.append('point')
        roi_items.append(PointRoi(border, border, size=size / 4))
        roi_names.append('path')
        roi_items.append(
            PathRoi([border, border], [extent, extent], is_anchored=False))
        roi_names.append('rectangle')
        roi_items.append(RectangleRoi(border, border, size, size))
        roi_names.append('ellipse')
        roi_items.append(EllipseRoi(border, border, size, size))
        # icons
        roi_icons = []
        pix_map = QPixmap(size + border * 2, size + border * 2)
        pix_map.fill(Qt.transparent)
        pix_painter = QPainter(pix_map)
        pix_painter.setRenderHint(QPainter.Antialiasing)
        opt = QStyleOptionGraphicsItem()
        for roi in roi_items:
            #roi.setPos(border, border)
            pix_map.fill(Qt.transparent)
            roi.paint(pix_painter, opt)
            roi_icons.append(QIcon(pix_map))

        pix_painter.end()
        return roi_names, roi_icons
Ejemplo n.º 6
0
	def paintEvent(self, event):
		painter = QPainter()
		painter.begin(self)
		option = QStyleOptionGraphicsItem()
		for vertex in self.graph.vertices:
			vertex.circle.paint(painter, option, self.view)
		for edge in self.graph.edges:
			edge.paint(painter, option, self.view)
		painter.end()
Ejemplo n.º 7
0
def fix_legend_box_size(cfg, legend):
    # adjustBoxSize() does not work without
    # call of the paint() function
    w, h = cfg['img_size']
    dpi = cfg['dpi']

    image = QImage(w, h, QImage.Format_ARGB32)
    image.setDevicePixelRatio(dpi)
    p = QPainter(image)
    s = QStyleOptionGraphicsItem()
    legend.paint(p, s, None)
    p.end()

    # Now we can adjust box size
    legend.adjustBoxSize()
Ejemplo n.º 8
0
    def paint(self,
              painter: QPainter,
              option: QStyleOptionGraphicsItem,
              widget: Optional[QWidget] = ...) -> None:
        """
        Paint component

        Returns:
            None
        """
        level_of_detail = option.levelOfDetailFromTransform(
            painter.worldTransform())

        self._paint_rect(painter)
        self._paint_text(level_of_detail, painter)

        self.scene().update()
Ejemplo n.º 9
0
    def paint(self, painter, options, widget=None):
        """
        Reimplementation for the paint function of the QGraphicsItemGroup.
        The Reimplementation is needed to print a proper border when the item is selected

        :param painter: The painter, which draws the node
        :param options: options for the paint job
        :param widget: widget of the Item
        """
        myOption = QStyleOptionGraphicsItem(options)
        myOption.state &= ~QStyle.State_Selected

        if options.state & QStyle.State_Selected:
            painter.setPen(QPen(Qt.black, 2, Qt.DotLine))
            rect = QRect(self.boundingRect().x() - 1.5, self.boundingRect().y() - 1.5,
                         self.boundingRect().x() + self.boundingRect().width() + 23.5,
                         self.boundingRect().y() + self.boundingRect().height() + 3.5)
            painter.drawRect(rect)

        super().paint(painter, myOption, widget=None)
Ejemplo n.º 10
0
    def zoomCanvas(self, event):
        """Zoom view into sprite/tile canvas

        :param event:   Source event
        :type event:    QEvent
        """
        zoomFactor = 2
        oldPos = event.scenePos()

        detail = QStyleOptionGraphicsItem.levelOfDetailFromTransform(
            self.transform()
        )
        if detail < 100 and event.delta() > 0:
            self.scale(zoomFactor, zoomFactor)
        if detail > 10 and event.delta() < 0:
            self.scale((1 / zoomFactor), (1 / zoomFactor))

        newPos = event.scenePos()
        delta = newPos - oldPos
        self.translate(delta.x(), delta.y())
Ejemplo n.º 11
0
    def saveSVGDialogCallback(self, selected):
        if isinstance(selected, (list, tuple)):
            fname = selected[0]
        else:
            fname = selected
        print("da fname", fname)
        if fname is None or os.path.isdir(fname):
            return False
        if not fname.lower().endswith(".svg"):
            fname += ".svg"
        if self.svgsavedialog is not None:
            self.svgsavedialog.filesSelected.disconnect(
                self.saveSVGDialogCallback)
            del self.svgsavedialog  # prevents hang
            self.svgsavedialog = None

        generator = QSvgGenerator()
        generator.setFileName(fname)
        generator.setSize(QSize(200, 330))
        generator.setViewBox(QRect(0, 0, 2000, 2000))
        painter = QPainter()

        # Render through scene
        # painter.begin(generator)
        # self.win.pathscene.render(painter)
        # painter.end()

        # Render item-by-item
        painter = QPainter()
        style_option = QStyleOptionGraphicsItem()
        q = [self.win.pathroot]
        painter.begin(generator)
        while q:
            graphics_item = q.pop()
            transform = graphics_item.itemTransform(self.win.sliceroot)[0]
            painter.setTransform(transform)
            if graphics_item.isVisible():
                graphics_item.paint(painter, style_option, None)
                q.extend(graphics_item.childItems())
        painter.end()
Ejemplo n.º 12
0
    def testPaintDelay(self):
        t = Tiling((100, 100))
        assert len(t.tileRectFs) == 1

        delay = datetime.timedelta(milliseconds=300)
        # fudge should prevent hitting the delay time exactly
        # during the while loops below;
        # if your computer is verrry slow and the fudge too small
        # the test will fail...
        fudge = datetime.timedelta(milliseconds=50)
        d = DirtyIndicator(t, delay=delay)

        # make the image a little bit larger to accomodate the tile overlap
        img = QImage(110, 110, QImage.Format_ARGB32_Premultiplied)
        img.fill(0)
        img_saved = QImage(img)

        painter = QPainter()
        style = QStyleOptionGraphicsItem()
        style.exposedRect = t.tileRectFs[0]

        start = datetime.datetime.now()
        d.setTileProgress(0, 0)  # resets delay timer

        # 1. do not update the progress during the delay time
        actually_checked = False
        while datetime.datetime.now() - start < delay - fudge:
            # nothing should be painted
            self.assertEqual(img, img_saved)
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds() * 2)
        # after the delay, the pie chart is painted
        painter.begin(img)
        d.paint(painter, style, None)
        self.assertNotEqual(img, img_saved)
        painter.end()

        # 2. update the progress during delay (this exposed a bug:
        #    the delay was ignored in that case and the pie chart
        #    painted nevertheless)
        d = DirtyIndicator(t, delay=delay)
        img.fill(0)
        start = datetime.datetime.now()
        d.setTileProgress(0, 0)  # resets delay timer

        actually_checked = False
        self.assertEqual(img, img_saved)  # precondition
        while datetime.datetime.now() - start < delay - fudge:
            # the painted during the delay time should have no effect
            painter.begin(img)
            d.setTileProgress(0, 0.5)
            d.paint(painter, style, None)
            painter.end()
            self.assertEqual(img, img_saved)
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds() * 2)
        # now the pie should be painted
        painter.begin(img)
        d.paint(painter, style, None)
        self.assertNotEqual(img, img_saved)
        painter.end()
Ejemplo n.º 13
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget=None):
        fillColor = self.color.darker(150) if (option.state & QStyle.State_Selected) else self.color

        if option.state & QStyle.State_MouseOver:
            fillColor = fillColor.lighter(125)

        lod = option.levelOfDetailFromTransform(painter.worldTransform())
        if lod < 0.2:
            if lod < 0.125:
                painter.fillRect(QRectF(0, 0, 110, 70), fillColor)
                return

            b = painter.brush()
            painter.setBrush(fillColor)
            painter.drawRect(13, 13, 97, 57)
            painter.setBrush(b)
            return

        oldPen = painter.pen()
        pen = oldPen
        width = 0
        if option.state & QStyle.State_Selected:
            width += 2

        pen.setWidth(width)
        b = painter.brush()
        f = 120 if option.state & QStyle.State_Sunken else 100
        painter.setBrush(QBrush(fillColor.darker(f)))
        painter.drawRect(QRect(14, 14, 79, 39))
        painter.setBrush(b)

        if lod >= 1:
            painter.setPen(QPen(Qt.gray, 1))
            painter.drawLine(15, 54, 94, 54)
            painter.drawLine(94, 53, 94, 15)
            painter.setPen(QPen(Qt.black, 0))

        if lod >= 2:
            font = QFont("Times", 10)
            font.setStyleStrategy(QFont.ForceOutline)
            painter.setFont(font)
            painter.save()
            painter.scale(0.1, 0.1)
            painter.drawText(170, 180, "Model: VSC-2000 (Very Small Chip) at {}x{}".format(self.x, self.y))
            painter.drawText(170, 200, "Serial number: DLWR-WEER-123L-ZZ33-SDSJ")
            painter.drawText(170, 220, "Manufacturer: Chip Manufacturer")

        lines = []
        if lod >= 0.5:
            for i in np.arange(0, 10, 1 if lod > 0.5 else 2):
                lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5))
                lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62))

            for i in np.arange(0, 6, 1 if lod > 0.5 else 2):
                lines.append(QLineF(5,18 + 5 * i, 13, 18 + 5 * i))
                lines.append(QLineF(94, 18 + 5 * i, 102, 18 + 5 * i))

        if lod >= 0.4:
            lineData = [
                QLineF(25, 35, 35, 35),
                QLineF(35, 30, 35, 40),
                QLineF(35, 30, 45, 35),
                QLineF(35, 40, 45, 35),
                QLineF(45, 30, 45, 40),
                QLineF(45, 35, 55, 35),
            ]
            lines.extend(lineData)

        painter.drawLines(lines)

        if len(self.stuff) > 1:
            p = painter.pen()
            painter.setPen(QPen(Qt.red, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
            painter.setBrush(Qt.NoBrush)
            path = QPainterPath()
            path.moveTo(self.stuff[0])
            for i in np.arange(len(self.stuff)):
                path.lineTo(self.stuff[i])
            painter.drawPath(path)
            painter.setPen(p)
Ejemplo n.º 14
0
 async def exec_test():
     node = ExplorerNode(("A", metadata), QPointF(0, 0), nx_pos, 0, 1,
                         False)
     node.paint(painter, QStyleOptionGraphicsItem(), widget)