This commit is contained in:
2026-05-14 13:30:06 +08:00
parent 974946cee4
commit e43171521d
91 changed files with 10485 additions and 3254 deletions
@@ -0,0 +1,90 @@
#include "dialogs/AnimationSchemeSettingsDialog.h"
#include "core/domain/Project.h"
#include "core/workspace/ProjectWorkspace.h"
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QCheckBox>
AnimationSchemeSettingsDialog::AnimationSchemeSettingsDialog(Mode mode, core::ProjectWorkspace& workspace,
QWidget* parent)
: QDialog(parent)
, m_mode(mode)
, m_workspace(workspace) {
setModal(true);
setMinimumWidth(360);
if (mode == Mode::Create) {
setWindowTitle(QStringLiteral("新建动画方案"));
} else {
setWindowTitle(QStringLiteral("动画方案设置"));
}
auto* root = new QVBoxLayout(this);
root->setContentsMargins(12, 12, 12, 12);
auto* form = new QFormLayout();
form->setSpacing(8);
root->addLayout(form);
m_name = new QLineEdit(this);
m_name->setPlaceholderText(QStringLiteral("显示名称"));
form->addRow(QStringLiteral("名称"), m_name);
m_frames = new QSpinBox(this);
m_frames->setRange(1, 1000000);
m_frames->setValue(600);
form->addRow(QStringLiteral("总帧数"), m_frames);
m_fps = new QSpinBox(this);
m_fps->setRange(1, 240);
m_fps->setValue(std::max(1, m_workspace.project().fps()));
form->addRow(QStringLiteral("帧率"), m_fps);
m_loop = new QCheckBox(QStringLiteral("循环播放"), this);
m_loop->setChecked(true);
form->addRow(QString(), m_loop);
auto* box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
root->addWidget(box);
connect(box, &QDialogButtonBox::accepted, this, &AnimationSchemeSettingsDialog::accept);
connect(box, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
void AnimationSchemeSettingsDialog::setEditTarget(const QString& animationId) {
m_editId = animationId;
if (const core::Project::Animation* a = m_workspace.project().findAnimationById(animationId)) {
m_name->setText(a->name);
m_frames->setValue(std::max(1, a->lengthFrames));
m_fps->setValue(std::max(1, a->fps));
m_loop->setChecked(a->loop);
}
}
void AnimationSchemeSettingsDialog::accept() {
const QString nm = m_name->text().trimmed();
const int frames = m_frames->value();
const int fps = m_fps->value();
const bool loop = m_loop->isChecked();
if (m_mode == Mode::Create) {
if (!m_workspace.createAnimationScheme(nm, frames, loop, fps, &m_createdNewId)) {
QMessageBox::warning(this, windowTitle(), QStringLiteral("新建失败"));
return;
}
} else {
if (m_editId.isEmpty() || !m_workspace.project().findAnimationById(m_editId)) {
QMessageBox::warning(this, windowTitle(), QStringLiteral("无效的动画方案"));
return;
}
if (!m_workspace.updateAnimationSchemeSettings(m_editId, nm, frames, loop, fps)) {
QMessageBox::warning(this, windowTitle(), QStringLiteral("保存失败"));
return;
}
}
QDialog::accept();
}