design.md 1.92 KB

设计文档:款式设计锁定功能和表情符号按钮

数据结构设计

1. 锁定状态管理

# 在 StyleDesignerTab.__init__ 中添加
self.locked_fields = set()  # 存储锁定的类别名称

2. 按钮映射

使用字典存储每个类别的锁定按钮,便于更新状态:

self.lock_buttons = {}  # category -> QPushButton

功能实现

1. 锁定/解锁切换

def toggle_field_lock(self, category: str):
    """切换字段锁定状态"""
    if category in self.locked_fields:
        self.locked_fields.remove(category)
        button = self.lock_buttons[category]
        button.setText("🔓")
    else:
        self.locked_fields.add(category)
        button = self.lock_buttons[category]
        button.setText("🔒")

2. 修改随机生成逻辑

更新 randomize_parameters 方法,跳过锁定的字段:

def randomize_parameters(self):
    """随机生成一套参数(跳过锁定的字段)"""
    for category, combo in self.combo_boxes.items():
        if category not in self.locked_fields and combo.count() > 0:
            random_index = random.randint(0, combo.count() - 1)
            combo.setCurrentIndex(random_index)
    self.update_prompt_preview()

3. UI 布局优化

  • 按钮宽度:表情符号按钮可以设置为 40-50px
  • 按钮样式:统一使用简洁样式
  • 布局间距:调整按钮间距以适应更小的按钮

代码改动点

  1. StyleDesignerTab.init

    • 添加 locked_fields 和 lock_buttons 初始化
  2. create_field_widget

    • 将添加/删除按钮改为表情符号
    • 添加锁定按钮
    • 调整按钮宽度和样式
  3. 新增 toggle_field_lock 方法

    • 处理锁定状态切换
    • 更新按钮显示
  4. 修改 randomize_parameters 方法

    • 添加锁定字段判断逻辑
  5. 刷新相关方法

    • 确保在重置词库等操作时保持锁定状态一致性