201 lines
6.0 KiB
Python
201 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试优化后的项目卡片组件
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
from pathlib import Path
|
||
|
||
# 添加项目根目录到Python路径
|
||
project_root = Path(__file__).parent.parent
|
||
sys.path.insert(0, str(project_root))
|
||
sys.path.insert(0, str(project_root / 'MetaCore'))
|
||
|
||
from PyQt5.QtWidgets import *
|
||
from PyQt5.QtCore import *
|
||
from PyQt5.QtGui import *
|
||
|
||
from data.project_manager import ProjectManager, Project
|
||
from ui.project_card import ProjectCard
|
||
from ui.styles import StyleSheet
|
||
|
||
class TestWindow(QWidget):
|
||
"""测试窗口"""
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.setWindowTitle("优化后的项目卡片测试")
|
||
self.setGeometry(100, 100, 1200, 800)
|
||
self.setStyleSheet(StyleSheet.get_main_stylesheet())
|
||
|
||
# 设置深色背景
|
||
self.setStyleSheet("""
|
||
QWidget {
|
||
background-color: #1a1a1a;
|
||
color: #ffffff;
|
||
}
|
||
""" + StyleSheet.get_main_stylesheet())
|
||
|
||
self.init_ui()
|
||
|
||
def init_ui(self):
|
||
"""初始化UI"""
|
||
layout = QVBoxLayout(self)
|
||
layout.setContentsMargins(40, 40, 40, 40)
|
||
layout.setSpacing(20)
|
||
|
||
# 标题
|
||
title = QLabel("项目卡片优化效果展示")
|
||
title.setStyleSheet("""
|
||
QLabel {
|
||
font-size: 24px;
|
||
font-weight: bold;
|
||
color: #ffffff;
|
||
margin-bottom: 20px;
|
||
}
|
||
""")
|
||
title.setAlignment(Qt.AlignCenter)
|
||
layout.addWidget(title)
|
||
|
||
# 说明文字
|
||
description = QLabel("""
|
||
根据Figma设计优化的项目卡片特性:
|
||
• 图片作为背景填充整个卡片 (276x191px)
|
||
• 底部半透明信息覆盖层显示项目详情
|
||
• 右上角操作按钮悬浮显示
|
||
• 无图片时使用project_empty_icon作为默认背景
|
||
• 完全匹配Figma设计规范的颜色和字体
|
||
""")
|
||
description.setStyleSheet("""
|
||
QLabel {
|
||
font-size: 14px;
|
||
color: #cccccc;
|
||
line-height: 1.5;
|
||
margin-bottom: 20px;
|
||
}
|
||
""")
|
||
layout.addWidget(description)
|
||
|
||
# 创建项目卡片网格
|
||
self.create_project_grid(layout)
|
||
|
||
def create_project_grid(self, layout):
|
||
"""创建项目卡片网格"""
|
||
# 滚动区域
|
||
scroll_area = QScrollArea()
|
||
scroll_area.setWidgetResizable(True)
|
||
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||
scroll_area.setStyleSheet("""
|
||
QScrollArea {
|
||
border: none;
|
||
background: transparent;
|
||
}
|
||
""")
|
||
|
||
# 网格容器
|
||
grid_widget = QWidget()
|
||
grid_layout = QGridLayout(grid_widget)
|
||
grid_layout.setSpacing(24)
|
||
grid_layout.setContentsMargins(20, 20, 20, 20)
|
||
|
||
# 创建项目管理器
|
||
project_manager = ProjectManager()
|
||
|
||
# 创建测试项目数据
|
||
test_projects = [
|
||
{
|
||
'id': '1',
|
||
'title': '智能家居控制系统',
|
||
'date': '2024-10-14 15:30',
|
||
'type': 'smart',
|
||
'status': 'active',
|
||
'image': None # 测试默认图标
|
||
},
|
||
{
|
||
'id': '2',
|
||
'title': 'VR虚拟现实项目',
|
||
'date': '2024-10-13 09:15',
|
||
'type': 'vr',
|
||
'status': 'active',
|
||
'image': str(project_root / 'MetaCore' / 'Resources' / 'ProjectPreviews' / 'preview_6_1760434704537.png')
|
||
},
|
||
{
|
||
'id': '3',
|
||
'title': '工业自动化系统',
|
||
'date': '2024-10-12 14:20',
|
||
'type': 'industrial',
|
||
'status': 'active',
|
||
'image': None
|
||
},
|
||
{
|
||
'id': '4',
|
||
'title': '游戏开发项目',
|
||
'date': '2024-10-11 11:45',
|
||
'type': 'game',
|
||
'status': 'pending_delete', # 测试待删除状态
|
||
'image': None
|
||
},
|
||
{
|
||
'id': '5',
|
||
'title': 'UI设计项目',
|
||
'date': '2024-10-10 16:30',
|
||
'type': 'design',
|
||
'status': 'active',
|
||
'image': None
|
||
},
|
||
{
|
||
'id': '6',
|
||
'title': '数据分析平台',
|
||
'date': '2024-10-09 13:15',
|
||
'type': 'smart',
|
||
'status': 'active',
|
||
'image': None
|
||
}
|
||
]
|
||
|
||
# 创建项目卡片
|
||
row, col = 0, 0
|
||
for project_data in test_projects:
|
||
project = Project(
|
||
id=project_data['id'],
|
||
title=project_data['title'],
|
||
date=project_data['date'],
|
||
project_type=project_data['type'],
|
||
status=project_data['status'],
|
||
path=f"/test/path/{project_data['id']}",
|
||
project_dir=f"/test/path/{project_data['id']}",
|
||
image=project_data['image']
|
||
)
|
||
|
||
# 创建项目卡片
|
||
card = ProjectCard(project, project_manager, view_mode="grid")
|
||
grid_layout.addWidget(card, row, col)
|
||
|
||
col += 1
|
||
if col >= 4: # 每行4个卡片
|
||
col = 0
|
||
row += 1
|
||
|
||
scroll_area.setWidget(grid_widget)
|
||
layout.addWidget(scroll_area)
|
||
|
||
def main():
|
||
"""主函数"""
|
||
app = QApplication(sys.argv)
|
||
|
||
# 设置应用程序属性
|
||
app.setApplicationName("项目卡片测试")
|
||
app.setOrganizationName("MetaCore")
|
||
|
||
# 创建并显示测试窗口
|
||
window = TestWindow()
|
||
window.show()
|
||
|
||
sys.exit(app.exec_())
|
||
|
||
if __name__ == '__main__':
|
||
main()
|