Update
This commit is contained in:
@@ -56,6 +56,98 @@ TOOL_HEIGHT = config.TOOL_HEIGHT
|
||||
from scripts.ui import localization
|
||||
TEXT = localization.TEXT
|
||||
|
||||
class FlowLayout(QtWidgets.QLayout):
|
||||
"""
|
||||
流式布局 - 自动调整每行的项目数量,保持固定间距
|
||||
来源: Qt文档示例改进版
|
||||
"""
|
||||
def __init__(self, parent=None, margin=0, spacing=-1):
|
||||
super(FlowLayout, self).__init__(parent)
|
||||
|
||||
if parent is not None:
|
||||
self.setContentsMargins(margin, margin, margin, margin)
|
||||
|
||||
self.setSpacing(spacing)
|
||||
|
||||
self._item_list = []
|
||||
|
||||
def __del__(self):
|
||||
item = self.takeAt(0)
|
||||
while item:
|
||||
item = self.takeAt(0)
|
||||
|
||||
def addItem(self, item):
|
||||
self._item_list.append(item)
|
||||
|
||||
def count(self):
|
||||
return len(self._item_list)
|
||||
|
||||
def itemAt(self, index):
|
||||
if 0 <= index < len(self._item_list):
|
||||
return self._item_list[index]
|
||||
|
||||
return None
|
||||
|
||||
def takeAt(self, index):
|
||||
if 0 <= index < len(self._item_list):
|
||||
return self._item_list.pop(index)
|
||||
|
||||
return None
|
||||
|
||||
def expandingDirections(self):
|
||||
return QtCore.Qt.Orientations(QtCore.Qt.Orientation(0))
|
||||
|
||||
def hasHeightForWidth(self):
|
||||
return True
|
||||
|
||||
def heightForWidth(self, width):
|
||||
height = self._do_layout(QtCore.QRect(0, 0, width, 0), True)
|
||||
return height
|
||||
|
||||
def setGeometry(self, rect):
|
||||
super(FlowLayout, self).setGeometry(rect)
|
||||
self._do_layout(rect, False)
|
||||
|
||||
def sizeHint(self):
|
||||
return self.minimumSize()
|
||||
|
||||
def minimumSize(self):
|
||||
size = QtCore.QSize()
|
||||
|
||||
for item in self._item_list:
|
||||
size = size.expandedTo(item.minimumSize())
|
||||
|
||||
margin = self.contentsMargins()
|
||||
size += QtCore.QSize(margin.left() + margin.right(), margin.top() + margin.bottom())
|
||||
return size
|
||||
|
||||
def _do_layout(self, rect, test_only=False):
|
||||
x = rect.x()
|
||||
y = rect.y()
|
||||
line_height = 0
|
||||
spacing = self.spacing()
|
||||
|
||||
for item in self._item_list:
|
||||
widget = item.widget()
|
||||
item_width = item.sizeHint().width()
|
||||
item_height = item.sizeHint().height()
|
||||
|
||||
next_x = x + item_width + spacing
|
||||
|
||||
if next_x - spacing > rect.right() and line_height > 0:
|
||||
x = rect.x()
|
||||
y = y + line_height + spacing
|
||||
next_x = x + item_width + spacing
|
||||
line_height = 0
|
||||
|
||||
if not test_only:
|
||||
item.setGeometry(QtCore.QRect(QtCore.QPoint(x, y), item.sizeHint()))
|
||||
|
||||
x = next_x
|
||||
line_height = max(line_height, item_height)
|
||||
|
||||
return y + line_height - rect.y()
|
||||
|
||||
class RiggingUI(ui_utils.BaseUI):
|
||||
"""
|
||||
绑定系统UI类 - 负责显示骨骼绑定编辑界面和基础操作
|
||||
@@ -75,7 +167,7 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
|
||||
# 初始化DNA文件列表和按钮尺寸
|
||||
self.dna_files = []
|
||||
self.dna_button_size = (120, 150)
|
||||
self.dna_button_size = (140, 170) # 增加按钮尺寸,提供更好的视觉效果
|
||||
|
||||
# 初始化UI
|
||||
self.create_widgets()
|
||||
@@ -86,7 +178,7 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
self.update_language()
|
||||
|
||||
# 加载DNA文件和预览图 - 移到最后执行确保所有控件已创建
|
||||
self.load_dna_files()
|
||||
utils_rigging.load_dna_files(self)
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""
|
||||
@@ -142,11 +234,11 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
self.controls["presets_content"] = QtWidgets.QWidget()
|
||||
self.controls["presets_content"].setObjectName("presetsContent")
|
||||
|
||||
# 预设流布局
|
||||
self.controls["presets_flow_layout"] = QtWidgets.QGridLayout(self.controls["presets_content"])
|
||||
# 使用流式布局替代原来的网格布局
|
||||
self.controls["presets_flow_layout"] = FlowLayout(self.controls["presets_content"])
|
||||
self.controls["presets_flow_layout"].setObjectName("presetsFlowLayout")
|
||||
self.controls["presets_flow_layout"].setContentsMargins(5, 5, 5, 5)
|
||||
self.controls["presets_flow_layout"].setSpacing(10)
|
||||
self.controls["presets_flow_layout"].setContentsMargins(10, 10, 10, 10)
|
||||
self.controls["presets_flow_layout"].setSpacing(15) # 固定间距
|
||||
|
||||
# 设置滚动区域内容
|
||||
self.controls["presets_scroll_area"].setWidget(self.controls["presets_content"])
|
||||
@@ -162,12 +254,13 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
self.controls["presets_count_label"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.controls["presets_count_label"].setStyleSheet("font-weight: bold;")
|
||||
|
||||
# 滑块
|
||||
# 滑块 - 用于调整预览图大小
|
||||
self.controls["presets_slider"] = QtWidgets.QSlider(QtCore.Qt.Horizontal)
|
||||
self.controls["presets_slider"].setObjectName("presetsSlider")
|
||||
self.controls["presets_slider"].setMinimum(0)
|
||||
self.controls["presets_slider"].setMaximum(100)
|
||||
self.controls["presets_slider"].setValue(50)
|
||||
self.controls["presets_slider"].setMinimum(20) # 最小值
|
||||
self.controls["presets_slider"].setMaximum(100) # 最大值
|
||||
self.controls["presets_slider"].setValue(60) # 默认值
|
||||
self.controls["presets_slider"].setToolTip("调整预览图大小")
|
||||
|
||||
# 导出预设按钮
|
||||
self.buttons["export_presets"] = QtWidgets.QPushButton(TEXT("export_presets", "导出预设"))
|
||||
@@ -486,6 +579,9 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
self.buttons["export_presets"].clicked.connect(utils_rigging.export_dna)
|
||||
self.buttons["import_presets"].clicked.connect(utils_rigging.import_dna)
|
||||
|
||||
# 预设滑块连接 - 控制预览按钮大小
|
||||
self.controls["presets_slider"].valueChanged.connect(lambda value: utils_rigging.on_presets_slider_changed(self, value))
|
||||
|
||||
# 浏览文件按钮连接
|
||||
self.buttons["browse_path"].clicked.connect(lambda: utils_rigging.browse_file(self, "项目路径", self.controls["project_path_input"]))
|
||||
self.buttons["browse_dna"].clicked.connect(lambda: utils_rigging.browse_file(self, "DNA文件", self.controls["presets_dna_input"], "dna"))
|
||||
@@ -493,25 +589,4 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
# 底部按钮连接
|
||||
self.buttons["remove_all"].clicked.connect(utils_rigging.remove_all)
|
||||
self.buttons["import_skeleton"].clicked.connect(utils_rigging.import_skeleton)
|
||||
self.buttons["build_rigging"].clicked.connect(utils_rigging.build_rigging)
|
||||
|
||||
def load_dna_files(self):
|
||||
"""
|
||||
加载DNA文件和预览
|
||||
在所有UI控件创建完成后执行
|
||||
"""
|
||||
try:
|
||||
# 从utils_rigging加载DNA文件和预览图
|
||||
from scripts.utils import utils_rigging
|
||||
self.dna_files = utils_rigging.get_dna_files()
|
||||
|
||||
# 更新预设数量标签
|
||||
if 'presets_count_label' in self.controls:
|
||||
self.controls['presets_count_label'].setText(str(len(self.dna_files)))
|
||||
|
||||
# 调用utils_rigging中的加载预览按钮函数
|
||||
utils_rigging.load_dna_preview_buttons(self)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"加载DNA文件失败: {str(e)}")
|
||||
traceback.print_exc()
|
||||
self.buttons["build_rigging"].clicked.connect(utils_rigging.build_rigging)
|
Reference in New Issue
Block a user