#include "props/ToolPropertySection.h" #include "params/ParamControls.h" #include #include #include #include #include #include #include #include #include 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_positionLabel = new QLabel(QStringLiteral("位置"), this); m_position = new Vec2ParamControl(this); m_position->setToolTip(QStringLiteral("工具在世界坐标中的位置")); form->addRow(m_positionLabel, m_position); 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("随帧变化:在当前帧切换会写入可见性关键帧")); 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(&QSpinBox::valueChanged), this, &ToolPropertySection::fontPxChanged); connect(m_align, qOverload(&QComboBox::currentIndexChanged), this, &ToolPropertySection::alignChanged); connect(m_position, &Vec2ParamControl::valueChanged, this, &ToolPropertySection::positionEdited); connect(m_visible, &QCheckBox::toggled, this, &ToolPropertySection::visibleToggled); } void ToolPropertySection::setEditingEnabled(bool on) { for (auto* w : {static_cast(m_text), static_cast(m_position), static_cast(m_pointerT), static_cast(m_fontPx), static_cast(m_align), static_cast(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_positionLabel) m_positionLabel->setText(QStringLiteral("位置")); if (m_position) { m_position->blockSignals(true); m_position->setToolTip(QStringLiteral("工具在世界坐标中的位置")); m_position->setValue(0.0, 0.0); m_position->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_positionLabel) { m_positionLabel->setText(QStringLiteral("位置")); } if (m_position) { m_position->blockSignals(true); m_position->setToolTip( s.parentRelativeMode ? QStringLiteral("工具相对父对象的位置;修改将写入相对父对象的位置关键帧") : QStringLiteral("工具在世界坐标中的位置")); m_position->setValue(s.position.x(), s.position.y()); m_position->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