107 lines
2.9 KiB
Python
107 lines
2.9 KiB
Python
|
|
"""
|
||
|
|
项目列表项组件
|
||
|
|
"""
|
||
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel
|
||
|
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||
|
|
|
||
|
|
|
||
|
|
class ProjectItemWidget(QWidget):
|
||
|
|
"""项目列表项组件"""
|
||
|
|
|
||
|
|
clicked = pyqtSignal(object) # 点击信号
|
||
|
|
|
||
|
|
def __init__(self, project, parent=None):
|
||
|
|
"""
|
||
|
|
初始化项目列表项
|
||
|
|
|
||
|
|
Args:
|
||
|
|
project: 项目对象
|
||
|
|
parent: 父组件
|
||
|
|
"""
|
||
|
|
super().__init__(parent)
|
||
|
|
self.project = project
|
||
|
|
self._setup_ui()
|
||
|
|
|
||
|
|
def _setup_ui(self):
|
||
|
|
"""设置UI"""
|
||
|
|
layout = QVBoxLayout(self)
|
||
|
|
layout.setContentsMargins(12, 12, 12, 12)
|
||
|
|
layout.setSpacing(8)
|
||
|
|
|
||
|
|
# 项目名称
|
||
|
|
name_label = QLabel(self.project.name)
|
||
|
|
name_label.setStyleSheet("""
|
||
|
|
font-weight: bold;
|
||
|
|
color: #60a5fa;
|
||
|
|
font-size: 14px;
|
||
|
|
""")
|
||
|
|
layout.addWidget(name_label)
|
||
|
|
|
||
|
|
# 项目描述
|
||
|
|
desc_label = QLabel(self.project.description or "暂无描述")
|
||
|
|
desc_label.setStyleSheet("""
|
||
|
|
color: #94a3b8;
|
||
|
|
font-size: 12px;
|
||
|
|
""")
|
||
|
|
desc_label.setWordWrap(True)
|
||
|
|
layout.addWidget(desc_label)
|
||
|
|
|
||
|
|
# 底部信息
|
||
|
|
bottom_layout = QHBoxLayout()
|
||
|
|
bottom_layout.setSpacing(10)
|
||
|
|
|
||
|
|
# 创建时间
|
||
|
|
time_label = QLabel(self.project.created_at.strftime('%Y-%m-%d'))
|
||
|
|
time_label.setStyleSheet("""
|
||
|
|
color: #64748b;
|
||
|
|
font-size: 11px;
|
||
|
|
""")
|
||
|
|
bottom_layout.addWidget(time_label)
|
||
|
|
|
||
|
|
bottom_layout.addStretch()
|
||
|
|
|
||
|
|
# 状态标签
|
||
|
|
status_label = self._create_status_label()
|
||
|
|
bottom_layout.addWidget(status_label)
|
||
|
|
|
||
|
|
layout.addLayout(bottom_layout)
|
||
|
|
|
||
|
|
# 设置整体样式
|
||
|
|
self.setStyleSheet("""
|
||
|
|
QWidget {
|
||
|
|
background: rgba(51, 65, 85, 0.4);
|
||
|
|
border: 1px solid rgba(59, 130, 246, 0.2);
|
||
|
|
border-radius: 8px;
|
||
|
|
}
|
||
|
|
QWidget:hover {
|
||
|
|
background: rgba(59, 130, 246, 0.15);
|
||
|
|
border-color: rgba(59, 130, 246, 0.4);
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
def _create_status_label(self) -> QLabel:
|
||
|
|
"""创建状态标签"""
|
||
|
|
status_colors = {
|
||
|
|
"进行中": "#10b981",
|
||
|
|
"已完成": "#3b82f6",
|
||
|
|
"已暂停": "#f59e0b"
|
||
|
|
}
|
||
|
|
color = status_colors.get(self.project.status, "#94a3b8")
|
||
|
|
|
||
|
|
status_label = QLabel(self.project.status)
|
||
|
|
status_label.setStyleSheet(f"""
|
||
|
|
background: {color}33;
|
||
|
|
color: {color};
|
||
|
|
border: 1px solid {color};
|
||
|
|
border-radius: 4px;
|
||
|
|
padding: 2px 8px;
|
||
|
|
font-size: 10px;
|
||
|
|
""")
|
||
|
|
|
||
|
|
return status_label
|
||
|
|
|
||
|
|
def mousePressEvent(self, event):
|
||
|
|
"""鼠标点击事件"""
|
||
|
|
self.clicked.emit(self.project)
|
||
|
|
super().mousePressEvent(event)
|