2026年5月23日暂存

This commit is contained in:
2026-05-23 14:16:57 +08:00
parent c8a5a121c9
commit 1cb9d5ac42
59 changed files with 15774 additions and 8662 deletions
+4 -44
View File
@@ -11,46 +11,6 @@ namespace Ui {
class ItemGeneralSettings;
}
/**
* @brief 图元通用属性的ViewModel
*
* 目的:解耦UI编辑器与PicTextItem,支持灵活的数据绑定和批量操作。
* UI修改属性时先更新VM,再决定何时应用到item(实时或延迟)。
*/
struct ItemGeneralSettingsVM {
// 图元类型,用于判断是否显示字间距
SourceType sourceType = SourceType::UNKNOWN;
ItemDirectionType direction = NORMAL;
int boldMultiple = 1;
int letterSpace = 0;
bool colorReversal = false;
std::function<QImage()> imageGenerator; // 图片生成函数
// 便利方法:从PicTextItem快照创建VM
static ItemGeneralSettingsVM fromItem(PicTextItem *item) {
ItemGeneralSettingsVM vm;
if (item) {
vm.sourceType = item->sourceType();
vm.direction = item->direction();
vm.boldMultiple = item->boldMultiple();
vm.letterSpace = item->letterSpace();
vm.colorReversal = item->colorReversal();
}
return vm;
}
// 检查是否有改动
bool hasDifference(const ItemGeneralSettingsVM &other) const {
return sourceType != other.sourceType ||
direction != other.direction ||
boldMultiple != other.boldMultiple ||
letterSpace != other.letterSpace ||
colorReversal != other.colorReversal;
}
};
class ItemGeneralSettings : public QWidget
{
Q_OBJECT
@@ -72,14 +32,14 @@ public:
*
* @param vm
*/
void setViewModel(const ItemGeneralSettingsVM& vm);
void setViewModel(const TextItemModel& vm);
/**
* @brief 获取当前ViewModel
*
* 调用者可以检查是否有改动,并决定是否应用
*/
ItemGeneralSettingsVM viewModel() const { return m_vm; }
TextItemModel viewModel() const { return m_vm; }
/**
* @brief 将ViewModel的属性应用到指定的PicTextItem
@@ -117,10 +77,10 @@ private:
PicTextItem* m_currItem = nullptr;
// UI编辑的状态,独立于m_currItem
ItemGeneralSettingsVM m_vm;
TextItemModel m_vm;
// 初始加载时的VM状态,用于检测改动
ItemGeneralSettingsVM m_vmSnapshot;
TextItemModel m_vmSnapshot;
QPainter m_painter;
};