Exemplo n.º 1
0
 def zoomout(self):
     label = self.c.label
     font = label.font()
     resize_font(font, -1)
     label.setFont(font)
Exemplo n.º 2
0
    def paint(self, painter, option, index):
        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)
        rect = option.rect
        text_rect_height = 30
        source_rect_height = TextHeight - text_rect_height
        cover_spacing = 0
        text_y = rect.y() + rect.height() - TextHeight
        cover_height = rect.height() - TextHeight
        cover_width = rect.width() - cover_spacing
        cover_x = rect.x() + cover_spacing // 2
        cover_y = rect.y()
        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(cover_x, cover_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()
Exemplo n.º 3
0
 def zoomin(self):
     label = self.c.label
     font = label.font()
     resize_font(font, +1)
     label.setFont(font)
Exemplo n.º 4
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()