fix: elide overflowed badge text in ClickableLabel
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@ -192,19 +192,26 @@ class ClickableLabel(QLabel):
|
|||||||
icon_size = self._icon_size
|
icon_size = self._icon_size
|
||||||
spacing = self._icon_space
|
spacing = self._icon_space
|
||||||
|
|
||||||
icon_rect = QRect()
|
|
||||||
text_rect = QRect()
|
|
||||||
text = self.text()
|
text = self.text()
|
||||||
|
|
||||||
if self._icon:
|
if self._icon:
|
||||||
pixmap = self._icon.pixmap(icon_size, icon_size)
|
pixmap = self._icon.pixmap(icon_size, icon_size)
|
||||||
icon_rect = QRect(0, 0, icon_size, icon_size)
|
|
||||||
icon_rect.moveTop(rect.top() + (rect.height() - icon_size) // 2)
|
|
||||||
else:
|
else:
|
||||||
pixmap = None
|
pixmap = None
|
||||||
|
|
||||||
fm = QFontMetrics(self.font())
|
fm = QFontMetrics(self.font())
|
||||||
text_width = fm.horizontalAdvance(text)
|
|
||||||
|
# Считаем, сколько места остаётся под текст
|
||||||
|
available_width = rect.width()
|
||||||
|
if pixmap:
|
||||||
|
available_width -= (icon_size + spacing)
|
||||||
|
# Отступы по 2px с каждой стороны
|
||||||
|
available_width = max(0, available_width - 4)
|
||||||
|
|
||||||
|
# Получаем «обрезанный» текст с многоточием
|
||||||
|
display_text = fm.elidedText(text, Qt.TextElideMode.ElideRight, available_width)
|
||||||
|
|
||||||
|
text_width = fm.horizontalAdvance(display_text)
|
||||||
text_height = fm.height()
|
text_height = fm.height()
|
||||||
total_width = text_width + (icon_size + spacing if pixmap else 0)
|
total_width = text_width + (icon_size + spacing if pixmap else 0)
|
||||||
|
|
||||||
@ -214,24 +221,23 @@ class ClickableLabel(QLabel):
|
|||||||
x = rect.right() - total_width
|
x = rect.right() - total_width
|
||||||
else:
|
else:
|
||||||
x = rect.left()
|
x = rect.left()
|
||||||
|
|
||||||
y = rect.top() + (rect.height() - text_height) // 2
|
y = rect.top() + (rect.height() - text_height) // 2
|
||||||
|
|
||||||
if pixmap:
|
if pixmap:
|
||||||
icon_rect.moveLeft(x)
|
icon_rect = QRect(x, y + (text_height - icon_size) // 2, icon_size, icon_size)
|
||||||
text_rect = QRect(x + icon_size + spacing, y, text_width, text_height)
|
|
||||||
painter.drawPixmap(icon_rect, pixmap)
|
painter.drawPixmap(icon_rect, pixmap)
|
||||||
|
text_x = x + icon_size + spacing
|
||||||
else:
|
else:
|
||||||
# Устанавливаем text_rect для меток без иконки (например, favoriteLabel)
|
text_x = x
|
||||||
text_rect = QRect(x, y, text_width, text_height)
|
|
||||||
|
|
||||||
|
text_rect = QRect(text_x, y, text_width, text_height)
|
||||||
self.style().drawItemText(
|
self.style().drawItemText(
|
||||||
painter,
|
painter,
|
||||||
text_rect,
|
text_rect,
|
||||||
alignment,
|
alignment,
|
||||||
self.palette(),
|
self.palette(),
|
||||||
self.isEnabled(),
|
self.isEnabled(),
|
||||||
text,
|
display_text,
|
||||||
self.foregroundRole(),
|
self.foregroundRole(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -480,7 +480,6 @@ def get_protondb_badge_style(tier):
|
|||||||
qproperty-alignment: AlignCenter;
|
qproperty-alignment: AlignCenter;
|
||||||
background-color: {colors["background"]};
|
background-color: {colors["background"]};
|
||||||
color: {colors["color"]};
|
color: {colors["color"]};
|
||||||
font-size: 14px;
|
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: 'Poppins';
|
font-family: 'Poppins';
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -500,7 +499,6 @@ def get_anticheat_badge_style(status):
|
|||||||
qproperty-alignment: AlignCenter;
|
qproperty-alignment: AlignCenter;
|
||||||
background-color: {colors["background"]};
|
background-color: {colors["background"]};
|
||||||
color: {colors["color"]};
|
color: {colors["color"]};
|
||||||
font-size: 14px;
|
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: 'Poppins';
|
font-family: 'Poppins';
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -511,7 +509,6 @@ STEAM_BADGE_STYLE= """
|
|||||||
qproperty-alignment: AlignCenter;
|
qproperty-alignment: AlignCenter;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
color: white;
|
color: white;
|
||||||
font-size: 14px;
|
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: 'Poppins';
|
font-family: 'Poppins';
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
@ -641,7 +641,6 @@ def get_protondb_badge_style(tier):
|
|||||||
qproperty-alignment: AlignCenter;
|
qproperty-alignment: AlignCenter;
|
||||||
background-color: {colors["background"]};
|
background-color: {colors["background"]};
|
||||||
color: {colors["color"]};
|
color: {colors["color"]};
|
||||||
font-size: {font_size_a};
|
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: '{font_family}';
|
font-family: '{font_family}';
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -664,7 +663,6 @@ def get_anticheat_badge_style(status):
|
|||||||
color: {colors["color"]};
|
color: {colors["color"]};
|
||||||
font-size: {font_size_a};
|
font-size: {font_size_a};
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: '{font_family}';
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -673,7 +671,6 @@ STEAM_BADGE_STYLE= f"""
|
|||||||
qproperty-alignment: AlignCenter;
|
qproperty-alignment: AlignCenter;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
color: white;
|
color: white;
|
||||||
font-size: {font_size_a};
|
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-family: '{font_family}';
|
font-family: '{font_family}';
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
Reference in New Issue
Block a user