Split out components into new files
This commit is contained in:
82
desktop-client/chat_widgets.py
Normal file
82
desktop-client/chat_widgets.py
Normal file
@@ -0,0 +1,82 @@
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget, QVBoxLayout, QHBoxLayout, QLabel, QFrame,
|
||||
QMainWindow
|
||||
)
|
||||
from PyQt6.QtCore import Qt, pyqtSignal
|
||||
|
||||
|
||||
class ChatBubble(QWidget):
|
||||
def __init__(self, author, text, time_str, is_self, on_link_clicked):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(5, 2, 5, 2)
|
||||
|
||||
# Container for the actual bubble
|
||||
self.bubble = QFrame()
|
||||
self.bubble.setObjectName("bubble")
|
||||
|
||||
bg_color = "#0084FF" if is_self else "#2a2a2e"
|
||||
text_color = "#FFFFFF"
|
||||
author_color = "#E1E1E1" if is_self else "#3ea6ff"
|
||||
|
||||
self.bubble.setStyleSheet(f"""
|
||||
#bubble {{
|
||||
background-color: {bg_color};
|
||||
border-radius: 12px;
|
||||
}}
|
||||
""")
|
||||
|
||||
bubble_layout = QVBoxLayout(self.bubble)
|
||||
bubble_layout.setContentsMargins(10, 8, 10, 6)
|
||||
bubble_layout.setSpacing(2)
|
||||
|
||||
# Author
|
||||
author_lbl = QLabel("You" if is_self else author)
|
||||
author_lbl.setStyleSheet(f"color: {author_color}; font-weight: bold; font-size: 11px; background: transparent;")
|
||||
bubble_layout.addWidget(author_lbl)
|
||||
|
||||
# Text
|
||||
self.text_lbl = QLabel(text)
|
||||
self.text_lbl.setWordWrap(True)
|
||||
self.text_lbl.setStyleSheet(f"color: {text_color}; font-size: 13px; border: none; background: transparent;")
|
||||
self.text_lbl.setOpenExternalLinks(False)
|
||||
self.text_lbl.linkActivated.connect(on_link_clicked)
|
||||
bubble_layout.addWidget(self.text_lbl)
|
||||
|
||||
# Time
|
||||
time_lbl = QLabel(time_str)
|
||||
time_lbl.setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||
time_lbl.setStyleSheet(f"color: {text_color}; font-size: 9px; opacity: 0.6; border: none; background: transparent;")
|
||||
bubble_layout.addWidget(time_lbl)
|
||||
|
||||
if is_self:
|
||||
layout.addStretch()
|
||||
layout.addWidget(self.bubble)
|
||||
else:
|
||||
layout.addWidget(self.bubble)
|
||||
layout.addStretch()
|
||||
|
||||
|
||||
class SystemMessageWidget(QWidget):
|
||||
def __init__(self, text):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 5, 0, 5)
|
||||
lbl = QLabel(text)
|
||||
lbl.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
lbl.setWordWrap(True)
|
||||
lbl.setStyleSheet("color: #888; font-style: italic; font-size: 11px; background: transparent;")
|
||||
layout.addWidget(lbl)
|
||||
|
||||
|
||||
class ChatPopoutWindow(QMainWindow):
|
||||
closed = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Live Chat")
|
||||
self.resize(350, 600)
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.closed.emit()
|
||||
super().closeEvent(event)
|
||||
Reference in New Issue
Block a user