From 51dde0999d9e31c3aa23eaf87cc2b73fbf5cd0bd Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 4 Oct 2025 01:06:54 +0300 Subject: [PATCH] chat patch --- app/ui/views/chat_list_view.py | 4 +-- app/ui/widgets/chat_list_item_widget.py | 42 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/ui/views/chat_list_view.py b/app/ui/views/chat_list_view.py index cfad284..3787897 100644 --- a/app/ui/views/chat_list_view.py +++ b/app/ui/views/chat_list_view.py @@ -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) diff --git a/app/ui/widgets/chat_list_item_widget.py b/app/ui/widgets/chat_list_item_widget.py index 0200f78..0f3c408 100644 --- a/app/ui/widgets/chat_list_item_widget.py +++ b/app/ui/widgets/chat_list_item_widget.py @@ -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): """Устанавливает аватар. Если путь не указан, создает заглушку."""