def drawTitle(self, painter: QPainter) -> None:
        painter.save()

        painter.setPen(Qt.NoPen)
        painter.setBrush(self.__tempColor)

        offset: int = self.__borderWidth - self.__borderWidth // 3
        rect: QRect = QRect(offset, offset, self.width() - offset * 2, self.__titleHeight)
        painter.drawRect(rect)

        # 绘制标题文字
        if self.__isEnable:
            painter.setPen(self.__alarmTextColor if self.__isAlarm else self.__titleColor)
        else:
            painter.setPen(self.__titleDisableColor)

        painter.setFont(self.__titleFont)

        # 文字区域要重新计算
        offset = self.__borderWidth * 3
        textRect: QRect = QRect(offset, 0, self.width() - offset * 2, self.__titleHeight)

        align: Qt.Alignment = Qt.Alignment
        if self.__titleAlignment == PanelItem.Alignment.Alignment_Left:
            align = Qt.AlignLeft | Qt.AlignVCenter
        elif self.__titleAlignment == PanelItem.Alignment.Alignment_Center:
            align = Qt.AlignHCenter | Qt.AlignVCenter
        elif self.__titleAlignment == PanelItem.Alignment.Alignment_Right:
            align = Qt.AlignRight | Qt.AlignVCenter

        painter.drawText(textRect, align, self.__titleText)

        painter.restore()
예제 #2
0
    def paint(
        self, painter: QPainter, rect: QRect, mode: QIcon.Mode, state: QIcon.State
    ):
        """override"""
        font = FIconEngine.font if hasattr(FIconEngine, "font") else painter.font()

        # The following test is to avoid crash when running python widget outside the __main__.my
        if not font:
            font = painter.font()
            return

        painter.save()

        if self.color:
            painter.setPen(QPen(self.color))

        else:
            if mode == QIcon.Disabled:
                painter.setPen(
                    QPen(self.palette.color(QPalette.Disabled, QPalette.ButtonText))
                )
            else:
                painter.setPen(QPen(self.palette.color(QPalette.Active, QPalette.Text)))

        font.setPixelSize(rect.size().width())

        painter.setFont(font)
        # painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
        painter.drawText(
            rect, Qt.AlignCenter | Qt.AlignVCenter, str(chr(self.hex_character))
        )
        painter.restore()
예제 #3
0
    def paint(self, painter: QPainter, option, widget=...) -> None:
        painter.setBrush(self.brush())
        painter.setPen(self.pen())
        painter.setFont(self.font())

        painter.drawText(self.boundingRect(), self.alignMode(),
                         self.elidedText())
예제 #4
0
    def paintEvent(self, event):
        contents_y = self.edit.verticalScrollBar().value()
        page_bottom = contents_y + self.edit.viewport().height()
        font_metrics = self.fontMetrics()
        current_block = self.edit.document().findBlock(self.edit.textCursor().position())
        painter = QPainter(self)
        line_count = 0
        block = self.edit.document().begin()
        while block.isValid():
            line_count += 1
            position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
            if position.y() > page_bottom:
                break
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)
                self.current = line_count
            painter.drawText(self.width() - font_metrics.width(str(line_count)) - 10,
                             round(position.y()) - contents_y + font_metrics.ascent(),
                             str(line_count))
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            block = block.next()
        self.highest_line = line_count
        painter.end()

        QWidget.paintEvent(self, event)
예제 #5
0
    def setup_category_view(self):
        self.current_view = StepViews.CATEGORY_VIEW
        i, j = 0, 0

        for category in self.categories:
            data = urllib.request.urlopen(category["icons"][0]["url"]).read()

            label = ClickableLabel(self)
            label.setScaledContents(True)
            label.setFixedSize(190, 190)
            label.dataId = category["id"]
            label.clicked.connect(self.category_click)

            image = QImage(32, 32, QImage.Format_RGB32)
            image.loadFromData(data)

            painter = QPainter(image)
            painter.setPen(QPen(QColor("white")))
            painter.setFont(QFont("Roboto", 22, QFont.Bold))
            painter.drawText(QRect(0, 0, image.width(),
                                   image.height() - 25),
                             Qt.AlignCenter | Qt.AlignBottom, category["name"])
            painter.end()

            pixmap = QPixmap(image)
            label.setPixmap(pixmap)
            self.layout.addWidget(label, i, j)

            j += 1

            if j % 4 == 0:
                i += 1
                j = 0
예제 #6
0
    def paintEvent(self, e):

        r = min(self.width(), self.height()) / 2
        self.__text_r = r - (r / 10)  # radius of the text
        self.__tick_r = r - (r / 8)  # outer radius of the tick marks
        self.__tick_l = (r / 6)  # length of each tick, extending inwards
        self.__needle_l = (r / 5) * 3  # length of the needle

        self.font.setPixelSize(int(max(self.width(), self.height()) / 3))
        self.note_font.setPixelSize(int(max(self.width(), self.height()) / 30))
        self.title_font.setPixelSize(int(
            max(self.width(), self.height()) / 12))

        painter = QPainter()
        painter.begin(self)

        painter.setFont(self.font)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        painter.setRenderHint(QPainter.Antialiasing)

        self.draw_title(painter)
        self.draw_value(painter)
        if self.config["numerals"]:
            self.draw_multiplier(painter)
        self.draw_marks(painter)

        painter.end()
예제 #7
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex) -> None:
        # Draw the list item with all the default selection styling, but with an
        # invalid index so text formatting is left to us.
        super().paint(painter, option, QModelIndex())

        rect = option.rect.adjusted(self.HMARGIN, self.VMARGIN, -self.HMARGIN,
                                    -self.VMARGIN)

        with painter_context(painter):
            painter.setFont(self.get_font(option))

            icon: Optional[QIcon] = index.data(Qt.DecorationRole)
            if icon is not None:
                icon.paint(painter, rect, Qt.AlignLeft | Qt.AlignVCenter,
                           self.icon_mode(option),
                           self.icon_state(option))

            rect = rect.adjusted(self.icon_size(option).width() + self.HMARGIN,
                                 0, 0, 0)
            painter.drawText(rect, Qt.AlignLeft, self.first_row_text(index))
            line2 = rect.adjusted(0, rect.height() / 2, 0, rect.height() / 2)
            painter.drawText(line2, Qt.AlignLeft, self.second_row_text(index))

            clients = self.num_clients(index)
            if clients:
                painter.drawText(rect, Qt.AlignRight,
                                 f"Player Slots: {clients}")
예제 #8
0
    def drawText(self, painter: QPainter) -> None:
        painter.save()
        painter.setPen(Qt.NoPen)

        font: QFont = QFont()
        font.setBold(True)
        font.setPointSize(10)
        painter.setFont(font)

        now: QDateTime = QDateTime.currentDateTime()
        fm: QFontMetricsF = QFontMetricsF(font)
        textList: List[AnyStr] = [
            now.toString("MM月dd日yyyy"),
            now.toString("hh:mm:ss.zzz")
        ]

        # 绘制文本路径
        textPath: QPainterPath = QPainterPath()
        textPath.addText(-fm.width(textList[0]) / 2.0, -fm.lineSpacing() / 2.0,
                         font, textList[0])
        textPath.addText(-fm.width(textList[1]) / 2.0,
                         fm.lineSpacing() / 2.0, font, textList[1])

        strokeColor: QColor = self.__textColor.light(80)
        strokeColor.setAlphaF(0.2)
        painter.strokePath(
            textPath,
            QPen(strokeColor, self.__shadowWidth, Qt.SolidLine, Qt.RoundCap,
                 Qt.RoundJoin))
        painter.setBrush(self.__textColor)
        painter.drawPath(textPath)

        painter.restore()
예제 #9
0
    def paintEvent(self, paintEvent):
        painter = QPainter(self)

        font = painter.font()
        font.setPixelSize(14)
        font.setBold(True)
        painter.setFont(font)

        # clear background
        painter.setBackground(QColor("#1D212D"))
        painter.eraseRect(self.rect())

        self.apply_camera(painter)

        self.draw_links(painter)

        self.draw_rooms(painter)

        self.draw_solution_paths(painter)

        self.draw_ants(painter)

        # reset transform
        painter.resetMatrix()

        self.draw_room_names(painter)
예제 #10
0
파일: view.py 프로젝트: arptra/Corewar
    def write_bytes(self, addr, bytes_str, pen):
        pixmap_painter = QPainter(self.bytes_pixmap)
        pixmap_painter.setFont(self.font)

        self.print_to_pixmap(pixmap_painter, addr, bytes_str, pen)
        pixmap_painter.end()

        self.print_to_bytes_field(addr, bytes_str, pen)
예제 #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

        # 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)

        painter.end()
예제 #12
0
파일: page.py 프로젝트: yimuchens/doc
 def paintEvent(self, event):
     super().paintEvent(event)
     p = QPainter(self)
     p.fillRect(QRect(0, 0, self.PageWidth, self.PageHeight), Qt.white)
     p.setFont(QFont("微软雅黑", pointSize=10))
     p.setPen(Qt.black)
     p.drawRect(self.PageHorizontalMargin, self.PageVerticalMargin,
                self.PageContentWidth, self.PageContentHeight)
     p.drawText(QPoint(0, self.PageVerticalMargin), str(self.PageNumber))
예제 #13
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setFont(QFont("Arial", 18))
     painter.drawText(0, 30, self.__text)
     # draw preedit text with diffrent color
     if self.driver.preeditVisible():
         rect = painter.boundingRect(self.rect(), self.__text)
         painter.setPen(Qt.red)
         painter.drawText(rect.width(), 30, self.driver.preedit())
예제 #14
0
    def paintEvent(self, event: PySide2.QtGui.QPaintEvent):
        painter = QPainter(self)

        if self.orientation is None:
            return
        if self.image is not None:
            painter.save()
            image_width = self.image.width()
            image_height = self.image.height()
            if self.orientation % 2 == 0:
                scale = min(self.width() / image_width,
                            self.height() / image_height)
            else:
                scale = min(self.width() / image_height,
                            self.height() / image_width)

            target_width = image_width * scale
            target_height = image_height * scale
            padding_left = (self.width() - target_width) // 2
            padding_top = (self.height() - target_height) // 2
            painter.translate(self.width() / 2, self.height() / 2)
            painter.rotate(90 * self.orientation)
            painter.translate(-self.width() / 2, -self.height() / 2)
            painter.drawImage(
                QRect(padding_left, padding_top, target_width, target_height),
                self.image)
            painter.restore()

            if self.original_orientation is not None:
                painter.save()
                self.render_orientation_indicator(painter,
                                                  self.original_orientation,
                                                  target_height,
                                                  target_width,
                                                  pen_color=Qt.yellow,
                                                  brush_color=Qt.darkYellow)
                painter.restore()
            if self.suggested_orientation is not None:
                painter.save()
                self.render_orientation_indicator(painter,
                                                  self.suggested_orientation,
                                                  target_height,
                                                  target_width,
                                                  pen_color=Qt.green,
                                                  brush_color=Qt.darkGreen)
                painter.restore()
        if self.loading:
            painter.save()
            painter.setPen(self.palette().brush(QPalette.Foreground).color())
            font = painter.font()
            font.setPointSize(font.pointSize() * 2)
            painter.setFont(font)
            draw_text(painter,
                      self.width() / 2,
                      self.height() / 2, Qt.AlignVCenter | Qt.AlignHCenter,
                      "Loading...")
            painter.restore()
예제 #15
0
    def paintPageNumbers(self):
        # Page numbers are drawn only when the editor is in page mode,
        # if fields are set and the option to display numbers is enabled
        if (self.m_usePageMode
                and not self.m_pageMetrics.pxPageMargins().isNull()
                and self.m_showPageNumbers):

            pageWidth = self.m_pageMetrics.pxPageSize().width()
            pageHeight = self.m_pageMetrics.pxPageSize().height()
            pageMargins = QMarginsF(self.m_pageMetrics.pxPageMargins())

            p = QPainter(self.viewport())
            font = QFont()
            font.setPointSize(10)
            font.setFamily('Calibri')
            p.setFont(font)
            p.setPen(QPen(self.palette().text(), 1))

            # The current height and width are displayed on the screen.
            curHeight = pageHeight - (self.verticalScrollBar().value() %
                                      pageHeight)

            # The start of the field must take into account the scrollbar offset.
            leftMarginPosition = pageMargins.left() - self.horizontalScrollBar(
            ).value()

            # Total field width
            marginWidth = pageWidth - pageMargins.left() - pageMargins.right()

            # The number of the first page to see.
            pageNumber = self.verticalScrollBar().value() / pageHeight + 1

            # Add 0.3 to pageNumber before emitting
            # to announce page when it is about halfway up the screen
            self.pageInfo.emit(
                (int(pageNumber + 0.3),
                 int(self.verticalScrollBar().maximum() / pageHeight + 1)))

            # Paint page numbers while there are remotely more visible pages
            while (curHeight < pageHeight + self.height()):

                # Define the space for top page number; paint number
                topMarginRect = QRectF(leftMarginPosition,
                                       curHeight - pageHeight, marginWidth,
                                       pageMargins.top())
                self.paintPageNumber(p, topMarginRect, True, pageNumber)

                # Define the space for bottom page number; paint number
                bottomMarginRect = QRectF(leftMarginPosition,
                                          curHeight - pageMargins.bottom(),
                                          marginWidth, pageMargins.bottom())
                self.paintPageNumber(p, bottomMarginRect, False, pageNumber)

                # Go to next page
                pageNumber += 1
                curHeight += pageHeight
예제 #16
0
    def drawHeader(self):
        """Draw logo/copyright in the header"""
        pHeight = 90
        pMargin = 15
        icon_path = cm.DIR_ICONS + "app.png"

        self.header_lbl.setMinimumHeight(pHeight)
        self.header_lbl.setFrameShape(QFrame.StyledPanel)
        self.header_lbl.setContentsMargins(0, 0, 0, 0)

        pixmap = QPixmap(450, pHeight)
        pixmap.fill(Qt.transparent)

        iconY = (pHeight - 64) / 2
        logoRect = QRect(pMargin, iconY, 64, 64)

        painter = QPainter(pixmap)
        painter.setBrush(QBrush(Qt.red))
        painter.drawPixmap(
            logoRect,
            QPixmap(icon_path).scaled(
                logoRect.width(),
                logoRect.height(),
                Qt.KeepAspectRatio,
                Qt.SmoothTransformation,
            ),
        )

        titleRect = QRect(logoRect.right() + 10, iconY, 200, pHeight)

        font = QFont()
        font.setBold(True)
        font.setPixelSize(16)
        painter.setFont(font)
        painter.setPen(QPen(QApplication.instance().palette().text().color()))
        painter.drawText(titleRect, Qt.AlignTop, "Cutevariant")

        font_metrics = QFontMetrics(font)
        font.setBold(False)
        font.setPixelSize(12)
        painter.setFont(font)
        painter.setPen(QPen(Qt.darkGray))
        titleRect.setY(titleRect.y() + font_metrics.height())

        painter.drawText(
            titleRect,
            Qt.AlignTop,
            f"Version %s\nGPL3 Copyright (C) 2018-2020\nLabsquare.org" % __version__,
        )

        self.header_lbl.setPixmap(pixmap)

        # Painting is finished !
        # Avoid Segfault:
        # QPaintDevice: Cannot destroy paint device that is being painted
        painter.end()
    def drawCurrentBg_TB(self, painter: QPainter) -> None:
        painter.save()

        # 圆半径为高度一定比例,计算宽度,将宽度等分
        width: int = self.width() // self.__maxStep
        height: int = self.height() // 3
        radius: int = height // 2
        initX: int = width // 2
        initY: int = self.height() // 2
        radius -= radius // 5

        # 逐个绘制连接线条
        pen: QPen = QPen()
        pen.setWidthF(radius / 7)
        pen.setCapStyle(Qt.RoundCap)
        pen.setColor(self.__currentBackground)
        painter.setPen(pen)
        painter.setBrush(Qt.NoBrush)

        for i in range(self.__currentStep - 1):
            painter.drawLine(QPoint(initX, initY),
                             QPoint(initX + width, initY))
            initX += width

        # 如果当前进度超过一个步数且小于最大步数则增加半个线条
        if 0 < self.__currentStep < self.__maxStep:
            painter.drawLine(QPoint(initX, initY),
                             QPoint(initX + width // 2, initY))

        # 逐个绘制圆
        initX: int = width // 2
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.__currentBackground)

        for i in range(self.__currentStep):
            painter.drawEllipse(QPoint(initX, initY), radius, radius)
            initX += width

        # 逐个绘制圆中的字符串
        initX: int = width // 2
        self.__iconFont.setPixelSize(radius)
        painter.setFont(self.__iconFont)
        painter.setPen(self.__currentForeground)
        painter.setBrush(Qt.NoBrush)

        # 完成字符,可以查看表格更换图形字符
        finshStr: str = chr(0xf00c)

        for i in range(self.__currentStep):
            textRect: QRect = QRect(initX - radius, initY - radius, radius * 2,
                                    radius * 2)
            painter.drawText(textRect, Qt.AlignCenter, finshStr)
            initX += width

        painter.restore()
예제 #18
0
    def paintEvent(self, e):
        qp = QPainter(self)
        # Draw circle
        qp.setPen(QColor("#999999"))
        qp.setBrush(QColor("#3e2723"))
        qp.drawEllipse(0, 0, self.w - 2, self.h - 2)

        # Draw text
        qp.setFont(self.font)
        qp.setBrush(QColor("#999999"))
        qp.drawText(8, 37, "-")
예제 #19
0
class GroupMemberWidget(QWidget):
    def __init__(self, parent=None):
        super(GroupMemberWidget, self).__init__(parent)
        self.parent = parent
        self.setFixedSize(200, 50)
        self.setAcceptDrops(True)
        self._player_name = ""
        self._player_id = 0
        self._csoport_number = 0
        self._csoport_sor = 0
        self.painter = QPainter()

    def _set_player_id(self, number):
        self._player_id = number

    # todo a beállításnál ez legyen használva
    def _set_csoport_number(self, number):
        self._csoport_number = number

    def _set_csoport_sor(self, number):
        self._csoport_sor = number

    def _set_player_name(self, name):
        self._player_name = name
        self.update()

    def _get_player_id(self):
        return int(self._player_id)

    def _get_csoport_number(self):
        return int(self._csoport_number)

    def _get_csoport_sor(self):
        return int(self._csoport_sor)

    def paintEvent(self, event):
        self.painter.begin(self)
        self.painter.setPen(QPen(QColor("blue")))
        self.painter.setBrush(QBrush(QColor("lightgray")))
        pen0 = QPen()
        pen0.setWidth(0)
        pen = self.painter.pen()
        self.painter.setPen(pen0)
        self.painter.drawRect(0, 0, 199, 49)
        font = QFont("Verdana, 20")
        font.setBold(True)
        self.painter.setFont(font)
        self.painter.setPen(pen)
        self.painter.drawText(5, 30, str(self._csoport_sor + 1))
        self.painter.drawText(20, 30, self._player_name)
        # self.painter.drawText(20, 35, str(self._player_id) + "   " + str(self._csoport_sor + 1) + "    " + self._player_name)
        self.painter.end()
 def _draw_text(self, p: QPainter) -> None:
     """
     绘制项目的名称
     :param p: 画刷
     :return: None
     """
     p.save()
     p.setPen(self._m_item_text_color)
     for key, value in self._m_item_maps.items():
         self._m_item_font.setPointSize(self._m_item_font_size)
         p.setFont(self._m_item_font)
         p.drawText(value[1], Qt.AlignCenter, value[0])
     p.restore()
    def drawText(self, painter: QPainter) -> None:
        if self.__text == '': return

        radius: int = 100
        painter.save()

        font: QFont = QFont()
        font.setPixelSize(85)
        painter.setFont(font)
        painter.setPen(self.__textColor)
        rect: QRect = QRect(-radius, -radius, radius * 2, radius * 2)
        painter.drawText(rect, Qt.AlignCenter, self.__text)
        painter.restore()
예제 #22
0
    def draw(cls, x, y, self: PreparedText, painter: QPainter):
        font = QFont(self.fontName)
        if self.fontSize:
            font.setPointSizeF(self.fontSize)
        if self.fontBold:
            font.setBold(True)
        if self.fontItalic:
            font.setItalic(True)
        brushStyle = self.brushStyle or Qt.BrushStyle.SolidPattern
        w = self.width
        h = self.height
        tx = self.left + x
        ty = self.top + y
        if self.border:
            w -= self.border.width
            h -= self.border.width * 2
            tx += self.border.width
            ty += self.border.width
        rect = QRectF(tx, ty, w, h)

        if self.backColor:
            painter.setBrush(brush_style_map[brushStyle])
            painter.fillRect(rect, QColor('#' + hex(self.backColor)[2:]))
        if self.allowTags:
            doc = QTextDocument()
            doc.setDefaultFont(font)
            doc.setHtml(self.text)
            doc.setDocumentMargin(0)
            painter.save()
            painter.translate(tx + 2, ty + 1)
            doc.drawContents(painter, QRectF(0, 0, self.width, self.height))
            painter.restore()
        else:
            painter.save()
            painter.setFont(font)
            flags = cls.textFlags(self)
            rect.setX(rect.x() + 2)
            rect.setY(rect.y() + 1)
            painter.drawText(rect, flags, self.text)
            painter.restore()
        if self.border and self.border.color is not None:
            old_pen = painter.pen()
            pen = QPen(
                QColor(self.border.color), self.border.width,
                pen_style_map.get(self.border.style, Qt.PenStyle.SolidLine))
            painter.setPen(pen)
            painter.drawLines(
                cls.getLines(self, self.left + x, self.top + y,
                             self.left + self.width + x,
                             self.top + y + self.height))
            painter.setPen(old_pen)
예제 #23
0
    def drawText(self, painter: QPainter) -> None:
        """  """
        painter.save()
        textFont: QFont = QFont()
        textFont.setBold(True)
        painter.setFont(textFont)

        count: int = len(self.__listItem)
        self.__initLen = 0

        # 横向导航时,字符区域取条目元素中最长的字符宽度
        longText: str = ""
        for item in self.__items.split("|"):
            if len(item) > len(longText):
                longText = item

        if self.horizontal:
            textLen: Decimal = Decimal(painter.fontMetrics().width(longText))
        else:
            textLen: Decimal = Decimal(painter.fontMetrics().height())

        # 逐个绘制元素列表中的文字及文字背景
        for i in range(count):
            strText: str = self.__listItem[i][0]
            left: QPointF = QPointF(self.__initLen, 0)
            right: QPointF = QPointF(self.__initLen + textLen + self.__space,
                                     self.height())

            if not self.horizontal:
                left = QPointF(0, self.__initLen)
                right = QPointF(self.width(),
                                self.__initLen + textLen + self.__space)

            textRect: QRectF = QRectF(left, right)
            self.__listItem[i][1] = textRect

            if self.__isVirgin:
                self.__barRect = textRect
                self.__isVirgin = False

            # 当前选中区域的文字显示选中文字颜色
            if textRect == self.__listItem[self.__currentIndex][1]:
                painter.setPen(self.__textSelectColor)
            else:
                painter.setPen(self.__textNormalColor)

            painter.drawText(textRect, Qt.AlignCenter, strText)
            self.__initLen += textLen + self.__space

        painter.restore()
예제 #24
0
    def paintEvent(self, event):
        """
        Paint the linear view.

        :param event:
        :return:
        """

        painter = QPainter(self.viewport())

        # Set the disassembly font
        painter.setFont(Conf.disasm_font)

        self._paint_objects(painter)
예제 #25
0
    def paintEvent(self, event):  # pylint: disable=invalid-name, unused-argument
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setPen(Qt.NoPen)
        track_opacity = self._track_opacity
        thumb_opacity = 1.0
        text_opacity = 1.0
        if self.isEnabled():
            track_brush = self._track_color[self.isChecked()]
            thumb_brush = self._thumb_color[self.isChecked()]
            text_color = self._text_color[self.isChecked()]
        else:
            track_opacity *= 0.8
            track_brush = self.palette().shadow()
            thumb_brush = self.palette().mid()
            text_color = self.palette().shadow().color()

        p.setBrush(track_brush)
        p.setOpacity(track_opacity)
        p.drawRoundedRect(
            self._margin,
            self._margin,
            self.width() - 2 * self._margin,
            self.height() - 2 * self._margin,
            self._track_radius,
            self._track_radius,
        )
        p.setBrush(thumb_brush)
        p.setOpacity(thumb_opacity)
        p.drawEllipse(
            self.offset - self._thumb_radius,
            self._base_offset - self._thumb_radius,
            2 * self._thumb_radius,
            2 * self._thumb_radius,
        )
        p.setPen(text_color)
        p.setOpacity(text_opacity)
        font = p.font()
        font.setPixelSize(1.5 * self._thumb_radius)
        p.setFont(font)
        p.drawText(
            QRectF(
                self.offset - self._thumb_radius,
                self._base_offset - self._thumb_radius,
                2 * self._thumb_radius,
                2 * self._thumb_radius,
            ),
            Qt.AlignCenter,
            self._thumb_text[self.isChecked()],
        )
예제 #26
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex):
        """Paint a cell according index and option
        
        Args:
            painter (QPainter)
            option (QStyleOptionViewItem)
            index (QModelIndex)
        """

        # Draw background selections
        if option.state & QStyle.State_Selected:
            select_color = option.palette.color(QPalette.Normal,
                                                QPalette.Highlight)
            text_color = option.palette.color(QPalette.Normal,
                                              QPalette.BrightText)
            painter.fillRect(option.rect, select_color)

        else:
            text_color = option.palette.color(QPalette.Normal, QPalette.Text)

        # get icon and color background
        icon = index.data(Qt.DecorationRole)
        icon_color = index.data(Qt.BackgroundColorRole)

        # draw icon background
        area = QRect(option.rect.x(), option.rect.y(), option.rect.height(),
                     option.rect.height())
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(icon_color))
        painter.drawRect(area)

        # Draw icon
        if icon:
            icon_area = area.adjusted(3, 3, -3, -3)
            painter.drawPixmap(icon_area, icon.pixmap(icon_area.size()))

        # Draw text
        text_rect = option.rect
        text_rect.setLeft(option.rect.height() + 3)

        light_font = QFont()
        dark_font = QFont()

        word = index.data(Qt.DisplayRole)
        font = QFont("monospace")
        painter.setFont(font)
        painter.setPen(QPen(text_color))
        painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, word)
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              index: QWidget) -> None:
        """
		Paint the graphics of the action wrapper including action name, number, and ports.

		:param painter: This draws the widget.
		:type painter: QPainter
		:param option: Option for the style of graphic.
		:type option: QStyleOptionGraphicsItem
		:param index: Index for the painted graphic.
		:type index: QWidget
		:return: None
		:rtype: NoneType
		"""
        ActionGraphics.paint(self, painter, option, index)

        # Get dimensions of the action
        x, y, width, height = self.getActionRect(self._action.getInputPorts(),
                                                 self._action.getOutputPorts())

        # Draw the number tag.
        number = str(
            self._action.getParent().getActions().index(self._action) + 1)
        offset = 5
        radius = 15
        size = ActionGraphics.H_SPACE / 2 - offset * 2
        painter.setBrush(QColor(29, 110, 37))
        painter.drawRoundedRect(QRectF(x + offset, y + offset, size, size),
                                radius, radius)
        painter.setPen(ActionWrapperGraphics.TAG_TEXT_COLOR)
        painter.setBrush(ActionWrapperGraphics.TAG_TEXT_COLOR)
        painter.setFont(ActionWrapperGraphics.TAG_FONT)
        fm = QFontMetricsF(ActionWrapperGraphics.TAG_FONT)
        pixelsWide = fm.width(number)
        pixelsHigh = fm.height()
        # TODO: fix text positioning - font metrics aren't working well
        painter.drawText(x + offset + size / 2 - pixelsWide,
                         y + offset + size / 2 + pixelsHigh / 2, number)

        # Draw the name of the action
        painter.setPen(ActionWrapperGraphics.NAME_TEXT_COLOR)
        painter.setBrush(ActionWrapperGraphics.NAME_TEXT_COLOR)
        painter.setFont(ActionWrapperGraphics.NAME_FONT)
        fm = QFontMetricsF(ActionWrapperGraphics.NAME_FONT)
        br = fm.boundingRect(self._action.getName())
        # TODO: fix text positioning - font metrics aren't working well
        t = fm.elidedText(self._action.getName(), Qt.ElideRight,
                          self._width - offset * 2)
        painter.drawText(x + offset, br.height(), t)
    def drawCurrentBg_ZFB(self, painter: QPainter) -> None:
        painter.save()

        # 圆半径为高度一定比例,计算宽度,将宽度等分
        width: int = self.width() // self.__maxStep
        height: int = self.height() // 3
        radius: int = height // 3
        initX: int = width // 2
        initY: int = self.height() // 2

        # 绘制当前圆
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.__currentBackground)

        for i in range(self.__currentStep - 1):
            initX += width

        painter.drawEllipse(QPoint(initX, initY), radius, radius)

        initX = initX - width // 4
        initY = 0
        height = self.height() // 4

        # 绘制当前上部提示信息背景
        bgRect: QRect = QRect(initX, initY, width // 2, height)
        painter.setBrush(self.__currentBackground)
        painter.drawRoundedRect(bgRect, height / 2, height / 2)

        # 绘制当前上部提示信息
        font: QFont = QFont()
        font.setPixelSize(height / 1.9)
        font.setBold(True)
        painter.setFont(font)
        painter.setPen(self.__currentForeground)
        painter.drawText(bgRect, Qt.AlignCenter,
                         self.__topInfo[self.__currentStep - 1])

        # 绘制倒三角
        centerX: int = initX + width // 4
        offset: int = 10
        pts: QPolygon = QPolygon()
        pts.append(QPoint(centerX - offset, height))
        pts.append(QPoint(centerX + offset, height))
        pts.append(QPoint(centerX, height + offset))

        painter.setPen(Qt.NoPen)
        painter.drawPolygon(pts)

        painter.restore()
예제 #29
0
    def paintEvent(self, e):
        painter = QPainter()
        painter.begin(self)

        self.pre_compute(painter)

        painter.setFont(self.font)
        painter.setPen(self.text_pen)
        painter.setRenderHint(QPainter.Antialiasing)

        self.draw_title(painter)
        #self.draw_border(painter)
        self.draw_bars(painter)

        painter.end()
예제 #30
0
    def paintEvent(self, e):
        """ Draws the color bar and arrow """
        if self.item():
            painter = QPainter(self)

            # Draws the color bar
            painter.setPen(Qt.NoPen)
            rect = QRect(0, 0, self.COLOR_BAR_WIDTH, self.COLOR_BAR_HEIGHT)
            painter.fillRect(rect,
                             self.item().data(renderSetupRoles.NODE_COLOR_BAR))
            oldBrush = painter.brush()

            if self.item().type(
            ) == renderSetup.RENDER_OVERRIDE_TYPE and self.item(
            ).isLocalRender():
                diameter = rect.width() - 2
                rect2 = QRect(rect.x() + 1,
                              rect.y() + (rect.height() - diameter) / 2,
                              diameter, diameter)
                brush = painter.brush()
                pen = painter.pen()
                hints = painter.renderHints()

                painter.setRenderHint(QPainter.Antialiasing, on=True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(
                    QBrush(QColor(67, 79, 70), style=Qt.SolidPattern))
                painter.drawEllipse(rect2)

                painter.setRenderHints(hints)
                painter.setPen(pen)
                painter.setBrush(brush)

            # Draws the arrow
            painter.setBrush(self.ARROW_COLOR)
            if self.arrowPoints == BaseDelegate.EXPANDED_ARROW:
                painter.translate(self.EXPANDED_ARROW_OFFSET, 0.0)
            else:
                painter.translate(self.COLLAPSED_ARROW_OFFSET, 0.0)
            painter.drawPolygon(self.arrowPoints)
            painter.setBrush(oldBrush)

            # Draws the node type text
            painter.setPen(QPen(self.item().data(Qt.TextColorRole)))
            text = self.item().data(renderSetupRoles.NODE_TYPE_STR)
            painter.setFont(self.item().data(Qt.FontRole))
            painter.drawText(self.NODE_TYPE_TEXT_RECT, text,
                             QTextOption(Qt.AlignLeft | Qt.AlignVCenter))
예제 #31
0
 def createDropTextPixmap(self):
     pixmap = QPixmap(481, 300)
     pixmap.fill(QColor("#333333"))
     painter = QPainter(pixmap)
     font = QFont("Arial")
     font.setPixelSize(28)
     font.setBold(True)
     fm = QFontMetrics(font)
     painter.setFont(font)
     painter.setPen(QPen(QColor("#888888"), 1))
     text = "Drop the tileset image here"
     x = (pixmap.width()-fm.width(text))/2
     y = (pixmap.height()+fm.height())/2
     painter.drawText(x, y, text)
     del painter
     return pixmap
예제 #32
0
    def paintEvent(self, event: QPaintEvent):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        # Draw background
        painter.setBrush(QBrush(self._bg_colors[self._state.mode]))
        painter.drawRect(event.rect())

        # Draw digit
        font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
        font.setPixelSize(int(self.width() * 6 / 7))
        digit = str(self._state.digit) if self._state.digit != 0 else ' '
        painter.setPen(self._fg_color)
        painter.setFont(font)
        flags = Qt.AlignCenter | Qt.TextJustificationForced
        painter.drawText(event.rect(), flags, digit)