chat patch
This commit is contained in:
parent
83cf48212b
commit
51dde0999d
@ -150,7 +150,7 @@ class ChatListView(QWidget):
|
|||||||
print("chat.chat_data", chat.chat_data)
|
print("chat.chat_data", chat.chat_data)
|
||||||
print("=============================")
|
print("=============================")
|
||||||
if chat.chat_data['custom_name']:
|
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:
|
else:
|
||||||
companion_name = "@"+chat.chat_data['login']
|
companion_name = "@"+chat.chat_data['login']
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -11,11 +11,14 @@ class ChatListItemWidget(QWidget):
|
|||||||
self.setStyleSheet("background-color: transparent;")
|
self.setStyleSheet("background-color: transparent;")
|
||||||
self.init_ui(companion_name, last_message, timestamp, avatar_path, unread_count)
|
self.init_ui(companion_name, last_message, timestamp, avatar_path, unread_count)
|
||||||
self.update_theme()
|
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):
|
def init_ui(self, companion_name, last_message, timestamp, avatar_path, unread_count):
|
||||||
"""Инициализирует пользовательский интерфейс виджета."""
|
"""Инициализирует пользовательский интерфейс виджета."""
|
||||||
main_layout = QHBoxLayout(self)
|
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)
|
main_layout.setSpacing(10)
|
||||||
|
|
||||||
# Аватар
|
# Аватар
|
||||||
@ -38,16 +41,21 @@ class ChatListItemWidget(QWidget):
|
|||||||
meta_layout = QVBoxLayout()
|
meta_layout = QVBoxLayout()
|
||||||
meta_layout.setSpacing(2)
|
meta_layout.setSpacing(2)
|
||||||
meta_layout.setAlignment(Qt.AlignRight)
|
meta_layout.setAlignment(Qt.AlignRight)
|
||||||
|
meta_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
self.timestamp_label = QLabel(timestamp)
|
self.timestamp_label = QLabel(timestamp)
|
||||||
self.unread_label = QLabel(str(unread_count) if unread_count > 0 else "")
|
self.unread_label = QLabel(str(unread_count) if unread_count > 0 else "")
|
||||||
self.unread_label.setAlignment(Qt.AlignCenter)
|
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.timestamp_label)
|
||||||
meta_layout.addWidget(self.unread_label)
|
meta_layout.addWidget(self.unread_label)
|
||||||
meta_layout.addStretch()
|
meta_layout.addStretch()
|
||||||
|
|
||||||
main_layout.addLayout(info_layout)
|
main_layout.addLayout(info_layout)
|
||||||
|
# Push metadata (time + unread) to the far right
|
||||||
|
main_layout.addStretch(1)
|
||||||
main_layout.addLayout(meta_layout)
|
main_layout.addLayout(meta_layout)
|
||||||
|
|
||||||
self.update_theme()
|
self.update_theme()
|
||||||
@ -62,13 +70,39 @@ class ChatListItemWidget(QWidget):
|
|||||||
|
|
||||||
unread_bg = palette['accent']
|
unread_bg = palette['accent']
|
||||||
unread_text = "#ffffff"
|
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"font-size: 8pt; font-weight: bold; color: {unread_text}; "
|
||||||
f"background-color: {unread_bg}; border-radius: 8px; "
|
f"background-color: {unread_bg};"
|
||||||
f"min-width: 16px; min-height: 16px; padding: 0 4px;"
|
|
||||||
)
|
)
|
||||||
|
self._update_unread_badge_shape()
|
||||||
self.unread_label.setVisible(self.unread_label.text() != "")
|
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):
|
def set_avatar(self, image_path):
|
||||||
"""Устанавливает аватар. Если путь не указан, создает заглушку."""
|
"""Устанавливает аватар. Если путь не указан, создает заглушку."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user