107 lines
4.1 KiB
Python
107 lines
4.1 KiB
Python
from PySide6.QtCore import Qt, Signal
|
|
from PySide6.QtGui import QPixmap, QPainter, QColor, QBrush
|
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QHBoxLayout, QFrame
|
|
|
|
|
|
class ProfileView(QWidget):
|
|
start_chat_clicked = Signal(dict) # payload with user data
|
|
follow_clicked = Signal(dict)
|
|
|
|
def __init__(self, user: dict, parent=None):
|
|
super().__init__(parent)
|
|
self.user = user or {}
|
|
root = QVBoxLayout(self)
|
|
root.setContentsMargins(16, 16, 16, 16)
|
|
root.setSpacing(12)
|
|
|
|
# Card container
|
|
card = QFrame()
|
|
card.setObjectName("ProfileCard")
|
|
card_layout = QVBoxLayout(card)
|
|
card_layout.setContentsMargins(16, 16, 16, 16)
|
|
card_layout.setSpacing(10)
|
|
|
|
# Header: avatar + names
|
|
header = QHBoxLayout()
|
|
header.setSpacing(12)
|
|
|
|
self.avatar = QLabel()
|
|
self._set_avatar_placeholder()
|
|
header.addWidget(self.avatar)
|
|
|
|
names_box = QVBoxLayout()
|
|
names_box.setSpacing(4)
|
|
|
|
login = self.user.get("login") or "user"
|
|
full_name = self.user.get("full_name") or self.user.get("custom_name") or ""
|
|
bio = (self.user.get("profile") or {}).get("bio") if isinstance(self.user.get("profile"), dict) else None
|
|
|
|
self.name_label = QLabel(full_name or "Пользователь")
|
|
self.name_label.setObjectName("ProfileName")
|
|
self.login_label = QLabel(f"@{login}")
|
|
self.login_label.setObjectName("ProfileLogin")
|
|
names_box.addWidget(self.name_label)
|
|
names_box.addWidget(self.login_label)
|
|
|
|
header.addLayout(names_box)
|
|
header.addStretch(1)
|
|
card_layout.addLayout(header)
|
|
|
|
if bio:
|
|
bio_label = QLabel(str(bio))
|
|
bio_label.setObjectName("ProfileBio")
|
|
bio_label.setWordWrap(True)
|
|
card_layout.addWidget(bio_label)
|
|
|
|
# Actions
|
|
actions = QHBoxLayout()
|
|
actions.setSpacing(8)
|
|
self.message_btn = QPushButton("Написать сообщение")
|
|
self.message_btn.setObjectName("ProfileActionPrimary")
|
|
self.follow_btn = QPushButton("Подписаться")
|
|
self.follow_btn.setObjectName("ProfileActionSecondary")
|
|
actions.addWidget(self.message_btn)
|
|
actions.addWidget(self.follow_btn)
|
|
card_layout.addLayout(actions)
|
|
|
|
root.addWidget(card)
|
|
|
|
# Styles
|
|
self.setStyleSheet("""
|
|
#ProfileCard {
|
|
border: 1px solid #e5e5ea;
|
|
border-radius: 12px;
|
|
background-color: rgba(0,0,0,0.02);
|
|
}
|
|
#ProfileName { font-size: 16px; font-weight: 600; }
|
|
#ProfileLogin { font-size: 13px; color: #8e8e93; }
|
|
#ProfileBio { font-size: 13px; }
|
|
QPushButton#ProfileActionPrimary {
|
|
background-color: #0A84FF; color: white; border: none; border-radius: 10px; padding: 8px 12px;
|
|
}
|
|
QPushButton#ProfileActionPrimary:hover { background-color: #1B8CFF; }
|
|
QPushButton#ProfileActionPrimary:pressed { background-color: #0a6ed1; }
|
|
QPushButton#ProfileActionSecondary {
|
|
background-color: transparent; color: #0A84FF; border: 1px solid rgba(10,132,255,0.4); border-radius: 10px; padding: 8px 12px;
|
|
}
|
|
QPushButton#ProfileActionSecondary:hover { background-color: rgba(10,132,255,0.06); }
|
|
QPushButton#ProfileActionSecondary:pressed { background-color: rgba(10,132,255,0.14); }
|
|
""")
|
|
|
|
# Signals
|
|
self.message_btn.clicked.connect(lambda: self.start_chat_clicked.emit(self.user))
|
|
self.follow_btn.clicked.connect(lambda: self.follow_clicked.emit(self.user))
|
|
|
|
def _set_avatar_placeholder(self, size: int = 72):
|
|
pixmap = QPixmap(size, size)
|
|
pixmap.fill(Qt.transparent)
|
|
p = QPainter(pixmap)
|
|
p.setRenderHint(QPainter.Antialiasing)
|
|
p.setBrush(QBrush(QColor("#d1d1d6")))
|
|
p.setPen(Qt.NoPen)
|
|
p.drawEllipse(0, 0, size, size)
|
|
p.end()
|
|
self.avatar.setPixmap(pixmap)
|
|
self.avatar.setFixedSize(size, size)
|
|
self.avatar.setScaledContents(True)
|