219 lines
6.8 KiB
Python
219 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试项目卡片5px圆角效果
|
||
"""
|
||
|
||
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 CornerRadiusTestWindow(QWidget):
|
||
"""测试5px圆角效果的窗口"""
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.setWindowTitle("项目卡片5px圆角测试")
|
||
self.setGeometry(100, 100, 1000, 700)
|
||
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("项目卡片5px圆角效果测试")
|
||
title.setStyleSheet("""
|
||
QLabel {
|
||
font-size: 24px;
|
||
font-weight: bold;
|
||
color: #ffffff;
|
||
margin-bottom: 20px;
|
||
}
|
||
""")
|
||
title.setAlignment(Qt.AlignCenter)
|
||
layout.addWidget(title)
|
||
|
||
# 说明文字
|
||
description = QLabel("""
|
||
测试说明:
|
||
• 所有项目卡片现在都使用5px的圆角
|
||
• 包括卡片外框、背景图片和列表视图图标
|
||
• 圆角效果应该统一且美观
|
||
""")
|
||
description.setStyleSheet("""
|
||
QLabel {
|
||
font-size: 14px;
|
||
color: #cccccc;
|
||
line-height: 1.5;
|
||
margin-bottom: 20px;
|
||
}
|
||
""")
|
||
layout.addWidget(description)
|
||
|
||
# 创建测试卡片网格
|
||
self.create_test_grid(layout)
|
||
|
||
def create_test_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') if (project_root / 'MetaCore' / 'Resources' / 'ProjectPreviews' / 'preview_6_1760434704537.png').exists() else None
|
||
},
|
||
{
|
||
'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': '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 >= 3: # 每行3个卡片
|
||
col = 0
|
||
row += 1
|
||
|
||
# 添加列表视图示例
|
||
list_title = QLabel("列表视图示例(也使用5px圆角):")
|
||
list_title.setStyleSheet("""
|
||
QLabel {
|
||
font-size: 18px;
|
||
font-weight: bold;
|
||
color: #ffffff;
|
||
margin: 20px 0 10px 0;
|
||
}
|
||
""")
|
||
|
||
# 创建列表视图卡片
|
||
list_widget = QWidget()
|
||
list_layout = QVBoxLayout(list_widget)
|
||
list_layout.setSpacing(8)
|
||
list_layout.setContentsMargins(0, 0, 0, 0)
|
||
|
||
for project_data in test_projects[:2]: # 只显示前两个
|
||
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']
|
||
)
|
||
|
||
list_card = ProjectCard(project, project_manager, view_mode="list")
|
||
list_layout.addWidget(list_card)
|
||
|
||
# 添加到主网格
|
||
grid_layout.addWidget(list_title, row + 1, 0, 1, 3)
|
||
grid_layout.addWidget(list_widget, row + 2, 0, 1, 3)
|
||
|
||
scroll_area.setWidget(grid_widget)
|
||
layout.addWidget(scroll_area)
|
||
|
||
def main():
|
||
"""主函数"""
|
||
app = QApplication(sys.argv)
|
||
|
||
# 设置应用程序属性
|
||
app.setApplicationName("圆角测试")
|
||
app.setOrganizationName("MetaCore")
|
||
|
||
# 创建并显示测试窗口
|
||
window = CornerRadiusTestWindow()
|
||
window.show()
|
||
|
||
sys.exit(app.exec_())
|
||
|
||
if __name__ == '__main__':
|
||
main()
|