Esempio n. 1
0
 def drawControl(self, element, option, painter, widget):
     if element == QStyle.CE_TabBarTabShape:
         # https://code.woboq.org/qt5/qtbase/src/plugins/styles/mac/qmacstyle_mac.mm.html#613
         # On macOS, there will be seperate line between tabs, which looks bad.
         # So we paint the tab shape by ourselves.
         painter.save()
         rect = option.rect
         is_selected = option.state & QStyle.State_Selected
         color = widget.palette().color(QPalette.Base)
         if is_selected:
             color.setAlpha(160)
             painter.fillRect(rect, color)
         else:
             color.setAlpha(80)
             painter.fillRect(rect, color)
         painter.restore()
     elif element == QStyle.CE_TabBarTabLabel:
         # HELP: Changing font size in QTabBar does not work, so we
         # resize font size here.
         painter.save()
         font = painter.font()
         resize_font(font, 2)
         font.setBold(True)
         painter.setFont(font)
         super().drawControl(element, option, painter, widget)
         painter.restore()
     else:
         super().drawControl(element, option, painter, widget)
Esempio n. 2
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.setWordWrap(True)
     self.setTextInteractionFlags(Qt.TextSelectableByMouse)
     font = self.font()
     resize_font(font, -1)
     self.setFont(font)
     self.setTextFormat(Qt.RichText)
Esempio n. 3
0
    def paint(self, painter, option, index):
        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)
        rect = option.rect
        text_rect_height = 30
        img_text_height = self.view.img_text_height
        source_rect_height = img_text_height - text_rect_height
        text_y = rect.y() + rect.height() - img_text_height
        cover_height = rect.height() - img_text_height
        cover_width = rect.width()
        text_rect = QRectF(rect.x(), text_y, rect.width(), text_rect_height)
        source_rect = QRectF(rect.x(), text_y + text_rect_height - 5,
                             rect.width(), source_rect_height + 5)
        obj = index.data(Qt.DecorationRole)
        if obj is None:
            painter.restore()
            return

        text_color = option.palette.color(QPalette.Text)
        if text_color.lightness() > 150:
            non_text_color = text_color.darker(140)
        else:
            non_text_color = text_color.lighter(150)
        non_text_color.setAlpha(100)
        painter.save()
        pen = painter.pen()
        pen.setColor(non_text_color)
        painter.setPen(pen)
        painter.translate(rect.x(), rect.y())
        if isinstance(obj, QColor):
            color = obj
            brush = QBrush(color)
            painter.setBrush(brush)
        else:
            if obj.height() < obj.width():
                pixmap = obj.scaledToHeight(cover_height,
                                            Qt.SmoothTransformation)
            else:
                pixmap = obj.scaledToWidth(cover_width,
                                           Qt.SmoothTransformation)
            brush = QBrush(pixmap)
            painter.setBrush(brush)
        border_radius = 3
        if self.as_circle:
            border_radius = cover_width // 2
        cover_rect = QRect(0, 0, cover_width, cover_height)
        painter.drawRoundedRect(cover_rect, border_radius, border_radius)
        painter.restore()
        option = QTextOption()
        source_option = QTextOption()
        if self.as_circle:
            option.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
            source_option.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
        else:
            option.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
            source_option.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        name = index.data(Qt.DisplayRole)
        fm = QFontMetrics(painter.font())
        elided_name = fm.elidedText(name, Qt.ElideRight, text_rect.width())
        source = index.data(Qt.WhatsThisRole)
        painter.drawText(text_rect, elided_name, option)
        painter.restore()
        painter.save()
        pen = painter.pen()
        font = painter.font()
        resize_font(font, -2)
        painter.setFont(font)
        pen.setColor(non_text_color)
        painter.setPen(non_text_color)
        painter.drawText(source_rect, source, source_option)
        painter.restore()
Esempio n. 4
0
 def _setup_ui(self):
     font = self.font()
     resize_font(font, -2)
     self.setFont(font)
Esempio n. 5
0
    def paint(self, painter, option, index):
        painter.setRenderHint(QPainter.Antialiasing)
        provider_ui_item = index.data(Qt.UserRole)

        painter.save()
        painter.translate(self._padding + option.rect.x(),
                          self._padding + option.rect.y())

        w = h = (self._radius - self._padding) * 2
        body_rect = QRect(0, 0, w, h)

        if provider_ui_item.colorful_svg:
            svg_renderer = QSvgRenderer(QUrl(provider_ui_item.colorful_svg).toString())
            svg_renderer.render(painter, QRectF(body_rect))
        else:
            # draw rounded rect
            painter.save()
            text_color = option.palette.color(QPalette.Text)
            if text_color.lightness() > 150:
                non_text_color = text_color.darker(140)
            else:
                non_text_color = text_color.lighter(150)
            non_text_color.setAlpha(100)
            pen = painter.pen()
            pen.setColor(non_text_color)
            painter.setPen(pen)
            painter.drawRoundedRect(body_rect, w//2, h//2)
            painter.restore()

            painter.save()
            font = painter.font()
            resize_font(font, -3)
            painter.setFont(font)
            text_option = QTextOption()
            text_option.setWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere)
            text_option.setAlignment(Qt.AlignCenter)

            text_rect = QRectF(self.__text_rect_x, self.__text_rect_x,
                               self.__text_rect_width, self.__text_rect_width)
            painter.drawText(QRectF(text_rect), provider_ui_item.text, text_option)
            painter.restore()

        # TODO: use library.check_flags instead of provider.check_flags
        provider = provider_ui_item.provider
        if self._library.check_flags(
                provider.identifier, ModelType.none, PF.current_user):
            if provider.has_current_user():
                painter.save()
                bottom_right = body_rect.bottomRight()
                status_radius = self._radius // 5
                x = bottom_right.x() - status_radius * 2
                y = bottom_right.y() - status_radius * 2
                status_rect = QRect(QPoint(x, y), bottom_right)
                pen = painter.pen()
                pen.setWidth(2)
                pen.setColor(QGuiApplication.palette().color(QPalette.Window))
                painter.setPen(pen)
                painter.setBrush(QColor(SOLARIZED_COLORS['blue']))
                painter.drawRoundedRect(status_rect, status_radius, status_radius)
                painter.restore()

        painter.restore()
Esempio n. 6
0
    def paint(self, painter, option, index):
        # refer to pixelator.py
        if option.state & QStyle.State_Selected:
            painter.fillRect(option.rect, option.palette.highlight())

        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)

        text_pen = QPen(option.palette.color(QPalette.Text))
        hl_text_pen = QPen(option.palette.color(QPalette.HighlightedText))
        if option.state & QStyle.State_Selected:
            painter.setPen(hl_text_pen)
        else:
            painter.setPen(text_pen)

        model = index.data(Qt.UserRole)
        rect = option.rect

        # calculate geometry for model icon
        icon_margin_left = 3
        topleft = rect.topLeft()
        icon_x, icon_y = topleft.x() + icon_margin_left, topleft.y() + 1
        icon_w = icon_h = rect.height() - 2
        text_x = icon_x + icon_w + 5
        text_y = topleft.y()
        text_topleft = QPoint(text_x, text_y)

        text_color = option.palette.color(QPalette.Text)
        if text_color.lightness() > 150:
            bonus_text_color = text_color.darker(140)
        else:
            bonus_text_color = text_color.lighter(140)

        if model.meta.model_type == ModelType.album:
            draw_album_icon(painter, icon_x, icon_y, icon_h)
            text = model.name_display
            text_rect = QRect(text_topleft, rect.bottomRight())
            painter.drawText(text_rect, Qt.AlignVCenter, text)
        elif model.meta.model_type == ModelType.song:
            text = model.title_display
            mid_y = rect.y() + rect.height() // 2
            title_bottomright = QPoint(rect.right(), mid_y)
            title_rect = QRect(text_topleft, title_bottomright)
            painter.drawText(title_rect, Qt.AlignVCenter, text)

            # draw bonus text
            font = painter.font()
            resize_font(font, -2)
            painter.setFont(font)
            pen = painter.pen()
            pen.setColor(bonus_text_color)
            painter.setPen(pen)
            bonus_rect = QRect(QPoint(text_x, mid_y), rect.bottomRight())
            bonus_text = model.artists_name_display + ' - ' + model.album_name_display
            painter.drawText(bonus_rect, Qt.AlignVCenter, bonus_text)

            # draw model icon
            # TODO: draw icon by using shapes, instead of text
            pen.setColor(text_color)
            painter.setPen(pen)
            font = painter.font()
            font.setPointSize(30)
            painter.setFont(font)
            painter.drawText(
                QRect(QPoint(icon_x, icon_y),
                      QPoint(icon_x + icon_h, icon_y + icon_h)),
                Qt.AlignCenter, '♬')

        painter.restore()
Esempio n. 7
0
 def zoomout(self):
     label = self.c.label
     font = label.font()
     resize_font(font, - 1)
     label.setFont(font)
Esempio n. 8
0
 def zoomin(self):
     label = self.c.label
     font = label.font()
     resize_font(font, +1)
     label.setFont(font)