desktop_app/app/ui/widgets/message_bubble_widget.py
2025-09-29 02:43:25 +03:00

59 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel
from PySide6.QtCore import Qt
from app.core.theme import theme_manager
class MessageBubbleWidget(QWidget):
def __init__(self, text: str, timestamp: str, is_own: bool):
super().__init__()
self.init_ui(text, timestamp, is_own)
self.update_theme()
def init_ui(self, text: str, timestamp: str, is_own: bool):
"""Инициализирует пользовательский интерфейс."""
self.layout = QVBoxLayout(self)
self.layout.setSpacing(2)
self.text_label = QLabel(text)
self.text_label.setWordWrap(True)
self.timestamp_label = QLabel(timestamp)
self.timestamp_label.setAlignment(Qt.AlignRight)
self.layout.addWidget(self.text_label)
self.layout.addWidget(self.timestamp_label)
self.is_own = is_own
self.setObjectName("MessageBubble")
self.update_theme()
def update_theme(self):
"""Обновляет стили виджета в соответствии с текущей темой."""
palette = theme_manager.get_current_palette()
if self.is_own:
bg_color = palette['accent']
text_color = "#ffffff"
timestamp_color = "#dddddd"
alignment = Qt.AlignRight
else:
bg_color = palette['secondary']
text_color = palette['text']
timestamp_color = palette['text_secondary']
alignment = Qt.AlignLeft
self.setStyleSheet(f"""
#MessageBubble {{
background-color: {bg_color};
border-radius: 10px;
padding: 8px 12px;
}}
""")
self.text_label.setStyleSheet(f"color: {text_color}; font-size: 10pt;")
self.timestamp_label.setStyleSheet(f"color: {timestamp_color}; font-size: 8pt;")
# Устанавливаем выравнивание для всего layout
parent_layout = self.parentWidget().layout() if self.parentWidget() else None
if parent_layout:
# Этот способ не сработает напрямую, выравнивание нужно делать в QListWidgetItem
pass