新增根据帧数控制可见性

This commit is contained in:
2026-04-09 17:30:55 +08:00
parent e116a9ec79
commit d67d7dc0c5
29 changed files with 4387 additions and 408 deletions

View File

@@ -0,0 +1,130 @@
#include "props/ToolPropertySection.h"
#include <algorithm>
#include <QComboBox>
#include <QFormLayout>
#include <QCheckBox>
#include <QLineEdit>
#include <QSlider>
#include <QSpinBox>
#include <QVBoxLayout>
namespace gui {
ToolPropertySection::ToolPropertySection(QWidget* parent)
: PropertySectionWidget(parent) {
auto* lay = new QVBoxLayout(this);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(6);
auto* form = new QFormLayout();
form->setContentsMargins(0, 0, 0, 0);
form->setSpacing(6);
m_text = new QLineEdit(this);
m_text->setPlaceholderText(QStringLiteral("对话内容…"));
form->addRow(QStringLiteral("文字"), m_text);
m_pointerT = new QSlider(Qt::Horizontal, this);
m_pointerT->setRange(0, 1000);
m_pointerT->setSingleStep(10);
m_pointerT->setPageStep(50);
m_pointerT->setValue(500);
m_pointerT->setToolTip(QStringLiteral("发言实体位置"));
form->addRow(QStringLiteral("指向"), m_pointerT);
m_fontPx = new QSpinBox(this);
m_fontPx->setRange(8, 120);
m_fontPx->setSingleStep(1);
m_fontPx->setValue(18);
form->addRow(QStringLiteral("字号"), m_fontPx);
m_align = new QComboBox(this);
m_align->addItems({QStringLiteral("左对齐"), QStringLiteral("居中"), QStringLiteral("右对齐")});
form->addRow(QStringLiteral("对齐"), m_align);
m_visible = new QCheckBox(QString(), this);
m_visible->setChecked(true);
m_visible->setToolTip(QStringLiteral("随帧变化在当前帧切换会写入可见性关键帧10帧淡入淡出"));
form->addRow(QStringLiteral("可见性"), m_visible);
lay->addLayout(form);
lay->addStretch(1);
connect(m_text, &QLineEdit::editingFinished, this, [this]() {
if (m_text) emit textCommitted(m_text->text());
});
connect(m_pointerT, &QSlider::valueChanged, this, &ToolPropertySection::pointerTChanged);
connect(m_fontPx, qOverload<int>(&QSpinBox::valueChanged), this, &ToolPropertySection::fontPxChanged);
connect(m_align, qOverload<int>(&QComboBox::currentIndexChanged), this, &ToolPropertySection::alignChanged);
connect(m_visible, &QCheckBox::toggled, this, &ToolPropertySection::visibleToggled);
}
void ToolPropertySection::setEditingEnabled(bool on) {
for (auto* w : {static_cast<QWidget*>(m_text), static_cast<QWidget*>(m_pointerT),
static_cast<QWidget*>(m_fontPx), static_cast<QWidget*>(m_align),
static_cast<QWidget*>(m_visible)}) {
if (w) w->setEnabled(on);
}
}
void ToolPropertySection::clearDisconnected() {
setEditingEnabled(false);
if (m_text) {
m_text->blockSignals(true);
m_text->clear();
m_text->blockSignals(false);
}
if (m_pointerT) {
m_pointerT->blockSignals(true);
m_pointerT->setValue(500);
m_pointerT->blockSignals(false);
}
if (m_fontPx) {
m_fontPx->blockSignals(true);
m_fontPx->setValue(18);
m_fontPx->blockSignals(false);
}
if (m_align) {
m_align->blockSignals(true);
m_align->setCurrentIndex(1);
m_align->blockSignals(false);
}
if (m_visible) {
m_visible->blockSignals(true);
m_visible->setChecked(true);
m_visible->blockSignals(false);
}
}
void ToolPropertySection::applyState(const ToolPropertyUiState& s) {
setEditingEnabled(true);
if (m_text) {
m_text->blockSignals(true);
m_text->setText(s.text);
m_text->blockSignals(false);
}
if (m_pointerT) {
m_pointerT->blockSignals(true);
m_pointerT->setValue(std::clamp(s.pointerTThousandths, 0, 1000));
m_pointerT->blockSignals(false);
}
if (m_fontPx) {
m_fontPx->blockSignals(true);
m_fontPx->setValue(std::clamp(s.fontPx, 8, 120));
m_fontPx->blockSignals(false);
}
if (m_align) {
m_align->blockSignals(true);
m_align->setCurrentIndex(std::clamp(s.alignIndex, 0, 2));
m_align->blockSignals(false);
}
if (m_visible) {
m_visible->blockSignals(true);
m_visible->setChecked(s.visible);
m_visible->blockSignals(false);
}
}
} // namespace gui