chat patch

This commit is contained in:
unknown 2025-10-04 01:06:54 +03:00
parent 83cf48212b
commit 51dde0999d
2 changed files with 40 additions and 6 deletions

View File

@ -150,7 +150,7 @@ class ChatListView(QWidget):
print("chat.chat_data", chat.chat_data)
print("=============================")
if chat.chat_data['custom_name']:
companion_name = chat.chat_data['custom_name']
companion_name = "@"+chat.chat_data['login'] + " (" + chat.chat_data['custom_name'] + ")"
else:
companion_name = "@"+chat.chat_data['login']
else:
@ -165,7 +165,7 @@ class ChatListView(QWidget):
timestamp = ""
# TODO: Заменить на реальное количество непрочитанных сообщений
unread_count = 2
unread_count = 2
# Создаем кастомный виджет
item_widget = ChatListItemWidget(companion_name, last_msg, timestamp, unread_count=unread_count)

View File

@ -11,11 +11,14 @@ class ChatListItemWidget(QWidget):
self.setStyleSheet("background-color: transparent;")
self.init_ui(companion_name, last_message, timestamp, avatar_path, unread_count)
self.update_theme()
# Ensure badge shape reflects current count
self._update_unread_badge_shape()
def init_ui(self, companion_name, last_message, timestamp, avatar_path, unread_count):
"""Инициализирует пользовательский интерфейс виджета."""
main_layout = QHBoxLayout(self)
main_layout.setContentsMargins(10, 5, 10, 5)
# Reduce right margin to bring unread badge closer to edge
main_layout.setContentsMargins(10, 5, 6, 5)
main_layout.setSpacing(10)
# Аватар
@ -38,16 +41,21 @@ class ChatListItemWidget(QWidget):
meta_layout = QVBoxLayout()
meta_layout.setSpacing(2)
meta_layout.setAlignment(Qt.AlignRight)
meta_layout.setContentsMargins(0, 0, 0, 0)
self.timestamp_label = QLabel(timestamp)
self.unread_label = QLabel(str(unread_count) if unread_count > 0 else "")
self.unread_label.setAlignment(Qt.AlignCenter)
self.unread_label.setMargin(0)
self.unread_label.setContentsMargins(0, 0, 0, 0)
meta_layout.addWidget(self.timestamp_label)
meta_layout.addWidget(self.unread_label)
meta_layout.addStretch()
main_layout.addLayout(info_layout)
# Push metadata (time + unread) to the far right
main_layout.addStretch(1)
main_layout.addLayout(meta_layout)
self.update_theme()
@ -62,13 +70,39 @@ class ChatListItemWidget(QWidget):
unread_bg = palette['accent']
unread_text = "#ffffff"
self.unread_label.setStyleSheet(
# Base style; specific shape applied in _update_unread_badge_shape
self._unread_base_style = (
f"font-size: 8pt; font-weight: bold; color: {unread_text}; "
f"background-color: {unread_bg}; border-radius: 8px; "
f"min-width: 16px; min-height: 16px; padding: 0 4px;"
f"background-color: {unread_bg};"
)
self._update_unread_badge_shape()
self.unread_label.setVisible(self.unread_label.text() != "")
def _update_unread_badge_shape(self):
text = self.unread_label.text()
if not hasattr(self, "_unread_base_style"):
self._unread_base_style = ""
# Default hidden when empty is handled by caller
if not text:
self.unread_label.setVisible(False)
return
# Single digit -> perfect circle
if len(text) == 1:
size = 18
self.unread_label.setFixedSize(size, size)
self.unread_label.setStyleSheet(
self._unread_base_style + f" border-radius: {size//2}px; padding: 0;"
)
else:
# Multiple digits -> pill
height = 18
self.unread_label.setFixedHeight(height)
self.unread_label.setMinimumWidth(height)
self.unread_label.setMaximumWidth(200)
self.unread_label.setStyleSheet(
self._unread_base_style + f" border-radius: {height//2}px; padding: 0 6px;"
)
def set_avatar(self, image_path):
"""Устанавливает аватар. Если путь не указан, создает заглушку."""