Example #1
0
    def paintEvent(self, event):
        painter = QPainter(self)
        area_color = self.palette().color(QPalette.Active, QPalette.Highlight)

        if self._full_area_drop:
            r = self.rect()
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
            return

        r = self.rect()
        drop_area = self.cursor_location()
        if drop_area == DropArea.TopDropArea:
            r.setHeight(r.height() * 0.5)
        elif drop_area == DropArea.RightDropArea:
            r.setX(r.width() * 0.5)
        elif drop_area == DropArea.BottomDropArea:
            r.setY(r.height() * 0.5)
        elif drop_area == DropArea.LeftDropArea:
            r.setWidth(r.width() * 0.5)
        elif drop_area == DropArea.CenterDropArea:
            r = self.rect()

        if not r.isNull():
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
Example #2
0
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setBrush(QColor(192, 192, 192))
     painter.setPen(QColor(64, 64, 64))
     painter.drawPolygon(self._arrow)
     painter.end()
Example #3
0
    def set_color(self, new_color, size=None):
        """
        Sets icon color
        :param new_color: QColor, new color for the icon
        :param size: QSize, size of the icon
        """

        if isinstance(new_color, str):
            new_color = color.Color.from_string(new_color)
        elif isinstance(new_color, (list, tuple)):
            new_color = color.Color(*new_color)

        if self.isNull():
            return

        icon = self
        size = size or icon.availableSizes()[0]
        pixmap = icon.pixmap(size)

        painter = QPainter(pixmap)
        painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
        painter.setBrush(new_color)
        painter.setPen(new_color)
        painter.drawRect(pixmap.rect())
        painter.end()

        icon = Icon(pixmap)
        self.swap(icon)
Example #4
0
    def _drag_pixmap(self, item, items):
        """
        Internal function that shows the pixmap for the given item during drag operation
        :param item: LibraryItem
        :param items: list(LibraryItem)
        :return: QPixmap
        """

        rect = self.visualRect(self.index_from_item(item))
        pixmap = QPixmap()
        pixmap = pixmap.grabWidget(self, rect)
        if len(items) > 1:
            custom_width = 35
            custom_padding = 5
            custom_text = str(len(items))
            custom_x = pixmap.rect().center().x() - float(custom_width * 0.5)
            custom_y = pixmap.rect().top() + custom_padding
            custom_rect = QRect(custom_x, custom_y, custom_width, custom_width)
            painter = QPainter(pixmap)
            painter.setRenderHint(QPainter.Antialiasing)
            painter.setPen(Qt.NoPen)
            painter.setBrush(self.viewer().background_selected_color())
            painter.drawEllipse(custom_rect.center(),
                                float(custom_width * 0.5),
                                float(custom_width * 0.5))
            font = QFont('Serif', 12, QFont.Light)
            painter.setFont(font)
            painter.setPen(self.viewer().text_selected_color())
            painter.drawText(custom_rect, Qt.AlignCenter, str(custom_text))

        return pixmap
Example #5
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        gradient = QRadialGradient(self._bounds.center(),
                                   self._bounds.width() * 0.5,
                                   self._bounds.center())
        gradient.setFocalRadius(self._bounds.width() * 0.3)
        gradient.setCenterRadius(self._bounds.width() * 0.7)
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, Qt.lightGray)

        painter.setPen(QPen(QBrush(Qt.gray), self._bounds.width() * 0.005))
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(self._bounds)

        painter.setPen(QPen(QBrush(Qt.gray), self._bounds.width() * 0.005))
        painter.drawLine(
            QPointF(self._bounds.left(),
                    self._bounds.center().y()),
            QPointF(self._bounds.center().x() - self._bounds.width() * 0.35,
                    self._bounds.center().y()))
        painter.drawLine(
            QPointF(self._bounds.center().x() + self._bounds.width() * 0.35,
                    self._bounds.center().y()),
            QPointF(self._bounds.right(),
                    self._bounds.center().y()))
        painter.drawLine(
            QPointF(self._bounds.center().x(), self._bounds.top()),
            QPointF(self._bounds.center().x(),
                    self._bounds.center().y() - self._bounds.width() * 0.35))
        painter.drawLine(
            QPointF(self._bounds.center().x(),
                    self._bounds.center().y() + self._bounds.width() * 0.35),
            QPointF(self._bounds.center().x(), self._bounds.bottom()))

        if not self.isEnabled():
            return

        gradient = QRadialGradient(self._knop_bounds.center(),
                                   self._knop_bounds.width() * 0.5,
                                   self._knop_bounds.center())
        gradient.setFocalRadius(self._knop_bounds.width() * 0.2)
        gradient.setCenterRadius(self._knop_bounds.width() * 0.5)
        gradient.setColorAt(0, Qt.gray)
        gradient.setColorAt(1, Qt.darkGray)

        painter.setPen(QPen(QBrush(Qt.darkGray), self._bounds.width() * 0.005))
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(self._knop_bounds)
Example #6
0
    def paintEvent(self, event):
        contents_y = self.editor.verticalScrollBar().value()
        page_bottom = contents_y + self.editor.viewport().height()
        font_metrics = self.fontMetrics()
        current_block = self.editor.document().findBlock(
            self.editor.textCursor().position())
        painter = QPainter(self)
        line_count = 0

        # Iterate over all text blocks in the document
        block = self.editor.document().begin()
        font_size = self.editor.font().pointSize()
        font = painter.font()
        font.setPixelSize(font_size)
        offset = font_metrics.ascent() + font_metrics.descent()
        color = painter.pen().color()
        painter.setFont(font)
        align = Qt.AlignRight
        while block.isValid():
            line_count += 1

            # Get top left position of the block in the document and check if the position of the block is
            # outside of the visible area
            position = self.editor.document().documentLayout(
            ).blockBoundingRect(block).topLeft()
            if position.y() == page_bottom:
                break

            rect = QRect(0,
                         round(position.y()) - contents_y,
                         self.width() - 5, font_size + offset)

            # Draw line rect
            if block == current_block:
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(self.bg))
                painter.drawRect(
                    QRect(0,
                          round(position.y()) - contents_y, self.width(),
                          font_size + (offset / 2)))
                painter.setPen(QPen(color))

            # Draw text
            painter.drawText(rect, align, str(line_count))
            block = block.next()

        self.highest_line = line_count
        painter.end()
        super(ScriptEditorNumberBar, self).paintEvent(event)
 def paintEvent(self, event):
     super(CommandButton, self).paintEvent(event)
     if self.has_menu:
         painter = QPainter()
         painter.begin(self)
         brush = QBrush(QColor(self.theme().accent_color))
         painter.setRenderHint(painter.Antialiasing)
         painter.setBrush(brush)
         painter.setPen(Qt.NoPen)
         w = self.rect().width() - 1
         h = self.rect().height() - 1
         polygon = QPolygon()
         polygon.append(QPoint(w - 1, h - 8))
         polygon.append(QPoint(w - 8, h - 1))
         polygon.append(QPoint(w - 1, h - 1))
         painter.drawPolygon(polygon)
Example #8
0
    def set_color(self, new_color):
        """
        Sets pixmap's color
        :param new_color: variant (str || QColor), color to apply to the pixmap
        """

        if isinstance(new_color, str):
            new_color = color.Color.from_string(new_color)

        if not self.isNull():
            painter = QPainter(self)
            painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            painter.setBrush(new_color)
            painter.setPen(new_color)
            painter.drawRect(self.rect())
            painter.end()

        self._color = new_color
Example #9
0
    def paintEvent(self, event):
        """
        Overrides base QToolButton paintEvent function
        Triggered on frame changed
        :param event: QEvent
        """

        super(ImageSequenceWidget, self).paintEvent(event)

        painter = QPainter()
        painter.begin(self)
        if self.current_filename() and self._image_sequence.frame_count() > 1:
            r = event.rect()
            playhead_height = self.playhead_height()
            playhead_pos = self._image_sequence.percent() * r.width() - 1
            x = r.x()
            y = self.height() - playhead_height
            painter.seten(Qt.NoPen)
            painter.setBrush(QBrush(self.DEFAULT_PLAYHEAD_COLOR))
            painter.drawRect(x, y, playhead_pos, playhead_height)

        painter.end()
Example #10
0
    def set_badge(self, x, y, w, h, color=None):
        """
        Set badge for the icon
        :param x: int
        :param y: int
        :param w: int
        :param h: int
        :param color: QColor or None
        """

        color = color or QColor(240, 100, 100)
        size = self.actualSize(QSize(256, 256))
        pixmap = self.pixmap(size)
        painter = QPainter(pixmap)
        pen = QPen(color)
        pen.setWidth(0)
        painter.setPen(pen)
        painter.setBrush(color)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.drawEllipse(x, y, w, h)
        painter.end()
        icon = Icon(pixmap)
        self.swap(icon)
Example #11
0
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(painter.Antialiasing)
     font = painter.font()
     font.setBold(True)
     painter.setFont(font)
     x = self.rect().x()
     y = self.rect().y()
     w = self.rect().width() - 1
     h = self.rect().height() - 1
     _rect = 8
     if self._rolloutStyle == ExpanderStyles.Rounded:
         painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         self.__drawTriangle(painter, x, y)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.6)
         painter.setPen(pen)
         painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, _rect, _rect)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRoundedRect(x, y, w - 1, h - 1, _rect, _rect)
     if self._rolloutStyle == ExpanderStyles.Square:
         painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         self.__drawTriangle(painter, x, y)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.2)
         painter.setPen(pen)
         painter.drawRect(x + 1, y + 1, w - 1, h - 1)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRect(x, y, w - 1, h - 1)
     if self._rolloutStyle == ExpanderStyles.Maya:
         painter.drawText(
             x + (45 if self.dragDropMode() == ExpanderDragDropModes.InternalMove else 25),
             y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         painter.setRenderHint(QPainter.Antialiasing, False)
         self.__drawTriangle(painter, x, y)
         header_height = 20
         header_rect = QRect(x + 1, y + 1, w - 1, header_height)
         header_rect_shadow = QRect(x - 1, y - 1, w + 1, header_height + 2)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.4)
         # painter.setPen(pen)
         painter.setPen(Qt.NoPen)
         painter.drawRect(header_rect)
         painter.fillRect(header_rect, QColor(255, 255, 255, 18))
         pen.setColor(self.palette().color(QPalette.Dark))
         painter.setPen(pen)
         painter.drawRect(header_rect_shadow)
         if not self.isCollapsed():
             # pen = QPen(self.palette().color(QPalette.Background))
             # painter.setPen(pen)
             offset = header_height + 3
             body_rect = QRect(x, y + offset, w, h - offset)
             # body_rect_shadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
             painter.drawRect(body_rect)
             # pen.setColor(self.palette().color(QPalette.Foreground))
             # pen.setWidthF(0.4)
             # painter.setPen(pen)
             # painter.drawRect(body_rect_shadow)
     elif self._rolloutStyle == ExpanderStyles.Boxed:
         if self.isCollapsed():
             arect = QRect(x + 1, y + 9, w - 1, 4)
             brect = QRect(x, y + 8, w - 1, 4)
             text = '+'
         else:
             arect = QRect(x + 1, y + 9, w - 1, h - 9)
             brect = QRect(x, y + 8, w - 1, h - 9)
             text = '-'
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.6)
         painter.setPen(pen)
         painter.drawRect(arect)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRect(brect)
         painter.setRenderHint(painter.Antialiasing, False)
         painter.setBrush(self.palette().color(QPalette.Window).darker(120))
         painter.drawRect(x + 10, y + 1, w - 20, 16)
         painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
         painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())
     if self.dragDropMode():
         rect = self.dragDropRect()
         _layout = rect.left()
         _rect = rect.right()
         center_y = rect.center().y()
         pen = QPen(self.palette().color(self.isCollapsed() and QPalette.Shadow or QPalette.Mid))
         painter.setPen(pen)
         for y in (center_y - 3, center_y, center_y + 3):
             painter.drawLine(_layout, y, _rect, y)
     painter.end()
Example #12
0
 def paintEvent(self, e):
     qp = QPainter(self)
     qp.setPen(QColor("#d4d4d4"))
     qp.setBrush(QColor(200, 0, 0))
     qp.drawRect(self.rect)
Example #13
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1
        _rect = 8

        if self.rollout_style == AccordionStyle.ROUNDED:
            painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16,
                             Qt.AlignLeft | Qt.AlignTop, self.title())
            self._draw_triangle(painter, x, y)
            self._draw_icon(painter, x + 22, y + 3)
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)
            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, _rect, _rect)
            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)
            painter.drawRoundedRect(x, y, w - 1, h - 1, _rect, _rect)
        elif self.rollout_style == AccordionStyle.SQUARE:
            painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16,
                             Qt.AlignLeft | Qt.AlignTop, self.title())
            self._draw_triangle(painter, x, y)
            self._draw_icon(painter, x + 22, y + 3)
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.3)
            painter.setPen(pen)
            painter.drawRect(x + 1, y + 1, w - 1, h - 1)
            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)
        elif self.rollout_style == AccordionStyle.MAYA:
            painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16,
                             Qt.AlignLeft | Qt.AlignTop, self.title())
            painter.setRenderHint(QPainter.Antialiasing, False)
            self._draw_triangle(painter, x, y)
            self._draw_icon(painter, x + 22, y + 3)
            header_height = 20
            header_rect = QRect(x + 1, y + 1, w - 1, header_height)
            header_rect_shadow = QRect(x - 1, y - 1, w + 1, header_height + 2)
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)
            painter.drawRect(header_rect)
            painter.fillRect(header_rect, QColor(255, 255, 255, 18))
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(header_rect_shadow)
            if not self.is_collapsed():
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)
                offset = header_height + 3
                body_rect = QRect(x, y + offset, w, h - offset)
                body_rect_shadow = QRect(x + 1, y + offset, w + 1,
                                         h - offset + 1)
                painter.drawRect(body_rect)
                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidth(0.4)
                painter.setPen(pen)
                painter.drawRect(body_rect_shadow)
        elif self.rollout_style == AccordionStyle.BOXED:
            if self.is_collapsed():
                a_rect = QRect(x + 1, y + 9, w - 1, 4)
                b_rect = QRect(x, y + 8, w - 1, 4)
                text = '+'
            else:
                a_rect = QRect(x + 1, y + 9, w - 1, h - 9)
                b_rect = QRect(x, y + 8, w - 1, h - 9)
                text = '-'

            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)
            painter.drawRect(a_rect)
            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)
            painter.drawRect(b_rect)
            painter.setRenderHint(painter.Antialiasing, False)
            painter.setBrush(self.palette().color(QPalette.Window).darker(120))
            painter.drawRect(x + 10, y + 1, w - 20, 16)
            painter.drawText(x + 16, y + 1, w - 32, 16,
                             Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter,
                             self.title())

        if self.drag_drop_mode:
            rect = self.get_drag_drop_rect()
            _layout = rect.left()
            _rect = rect.right()
            center_y = rect.center().y()
            for y in (center_y - 3, center_y, center_y + 3):
                painter.drawLine(_layout, y, _rect, y)

        painter.end()
Example #14
0
    def paintEvent( self, event ):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(x + 1, y + 1, w - 1, h - 1)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(x, y, w - 1, h - 1)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
            if self.isCollapsed():
                arect = QRect(x + 1, y + 9, w - 1, 4)
                brect = QRect(x, y + 8, w - 1, 4)
                text = '+'
            else:
                arect = QRect(x + 1, y + 9, w - 1, h - 9)
                brect = QRect(x, y + 8, w - 1, h - 9)
                text = '-'

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(arect)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(brect)

            painter.setRenderHint(painter.Antialiasing, False)
            painter.setBrush(self.palette().color(QPalette.Window).darker(120))
            painter.drawRect(x + 10, y + 1, w - 20, 16)
            painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())

        if self.dragDropMode():
            rect = self.dragDropRect()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
Example #15
0
    def paintEvent(self, event: QPaintEvent) -> None:
        p = QPainter(self)
        self.m_normalMap.render(p, event.rect())
        p.setPen(Qt.black)
        p.drawText(
            self.rect(),
            Qt.AlignBottom | Qt.TextWordWrap,
            "Map data CCBYSA 2009 OpenStreetMap.org contributors",
        )
        p.end()

        if self.zoomed:
            dim = min(self.width(), self.height())
            magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
            radius = magnifierSize / 2
            ring = radius - 15
            box = QSize(magnifierSize, magnifierSize)

            if self.maskPixmap.size() != box:
                self.maskPixmap = QPixmap(box)
                self.maskPixmap.fill(Qt.transparent)

                g = QRadialGradient()
                g.setCenter(radius, radius)
                g.setFocalPoint(radius, radius)
                g.setRadius(radius)
                g.setColorAt(1.0, QColor(255, 255, 255, 0))
                g.setColorAt(0.5, QColor(128, 128, 128, 255))

                mask = QPainter(self.maskPixmap)
                mask.setRenderHint(QPainter.Antialiasing)
                mask.setCompositionMode(QPainter.CompositionMode_Source)
                mask.setBrush(g)
                mask.setPen(Qt.NoPen)
                mask.drawRect(self.maskPixmap.rect())
                mask.setBrush(QColor(Qt.transparent))
                mask.drawEllipse(g.center(), ring, ring)
                mask.end()

            center = self.dragPos - QPoint(0, radius)
            center = center + QPoint(0, radius / 2)
            corner = center - QPoint(radius, radius)

            xy = center * 2 - QPoint(radius, radius)

            # only set the dimension to the magnified portion
            if self.zoomPixmap.size() != box:
                zoomPixmap = QPixmap(box)
                zoomPixmap.fill(Qt.lightGray)

            if True:
                p = QPainter(zoomPixmap)
                p.translate(-xy)
                self.m_largeMap.render(p, QRect(xy, box))
                p.end()

            clipPath = QPainterPath()
            clipPath.addEllipse(center, ring, ring)

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(Qt.gray)
            p.drawPath(clipPath)
        if self.invert:
            p = QPainter(self)
            p.setCompositionMode(QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), Qt.white)
            p.end()
Example #16
0
    def paint(self, p: QtGui.QPainter, option: QtWidgets.QGraphicsItem.ItemIsSelectable,
              widget: QtWidgets.QWidget): # pylint: disable=unused-argument

        # Set color when selected
        if option.state & QtWidgets.QStyle.State_Selected:
            fillColor = self.color.darker(150)
        else:
            fillColor = self.color

        # Lighten if mouse over
        if option.state & QtWidgets.QStyle.State_MouseOver:
            fillColor = fillColor.lighter(125)

        # Calculate level of detail
        lod = option.levelOfDetailFromTransform(p.worldTransform())
        if lod < 0.125:
            p.fillRect(QtCore.QRectF(0, 0, 110, 70), fillColor)
            return
        if lod < 0.2:
            oldBrush = p.brush()
            p.setBrush(fillColor)
            p.drawRect(13, 13, 97, 57)
            p.setBrush(oldBrush)
            return

        oldPen = p.pen()
        oldBrush = p.brush()

        # Use a copy of the old pen
        pen = QtGui.QPen(oldPen)
        if option.state & QtWidgets.QStyle.State_Selected:
            pen.setWidth(2)
        else:
            pen.setWidth(0)
        p.setPen(pen)

        # Draw the inside of the chip
        if option.state & QtWidgets.QStyle.State_Sunken:
            p.setBrush(QtGui.QBrush(fillColor.darker(120)))
        else:
            p.setBrush(QtGui.QBrush(fillColor.darker(100)))
        p.drawRect(QtCore.QRect(14, 14, 79, 39))
        p.setBrush(oldBrush)

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

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

        lines = []
        if lod >= 0.5:
            for i in range(0, 11, 1 if lod > 0.5 else 2):
                lines.append(QtCore.QLineF(18 + 7*i, 13, 18 + 7*i, 5))
                lines.append(QtCore.QLineF(18 + 7*i, 54, 18 + 7*i, 62))
            for i in range(0, 7, 1 if lod > 0.5 else 2):
                lines.append(QtCore.QLineF(5, 18 + i*5, 13, 18 + i*5))
                lines.append(QtCore.QLineF(94, 18 + i*5, 102, 18 + i*5))
        if lod >= 0.4:
            lines.append(QtCore.QLineF(25, 35, 35, 35))
            lines.append(QtCore.QLineF(35, 30, 35, 40))
            lines.append(QtCore.QLineF(35, 30, 45, 35))
            lines.append(QtCore.QLineF(35, 40, 45, 35))
            lines.append(QtCore.QLineF(45, 30, 45, 40))
            lines.append(QtCore.QLineF(45, 35, 55, 35))
        p.drawLines(lines)

        # Draw red ink
        if self.stuff:
            p.setPen(QtGui.QPen(QtCore.Qt.red, 1, QtCore.Qt.SolidLine,
                                QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
            p.setBrush(QtCore.Qt.NoBrush)
            path = QtGui.QPainterPath()
            path.moveTo(self.stuff[0])
            for point in self.stuff[1:]:
                path.lineTo(point)
            p.drawPath(path)

        p.setPen(oldPen)
        p.setBrush(oldBrush)