#include "props/ToolPropertySection.h" #include "params/ParamControls.h" #include #include #include #include #include #include #include #include #include "widgets/CompactNumericSpinBox.h" #include "widgets/PropertyPanelControls.h" #include namespace gui { ToolPropertySection::ToolPropertySection(QWidget* parent) : PropertySectionWidget(parent) { auto* lay = new QVBoxLayout(this); polishPropertyVBoxLayout(lay); auto* form = new QFormLayout(); polishPropertyFormLayout(form); m_text = new PropertyPanelLineEdit(this); m_text->setPlaceholderText(QStringLiteral("对话内容…")); polishPropertyStretchyTextField(m_text); form->addRow(QStringLiteral("文字"), m_text); m_positionLabel = new QLabel(QStringLiteral("位置"), this); m_position = new Vec2ParamControl(this); m_position->setToolTip({}); form->addRow(m_positionLabel, m_position); m_priority = new CompactIntSpinBox(this, 72); m_priority->setRange(-1000000, 1000000); m_priority->setSingleStep(1); m_priority->setAccelerated(true); m_priority->setToolTip(QStringLiteral("优先级越高越靠上。背景为 0;工具默认 10。")); form->addRow(QStringLiteral("优先级"), m_priority); 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({}); form->addRow(QStringLiteral("指向"), m_pointerT); m_fontPx = new CompactIntSpinBox(this); m_fontPx->setRange(8, 120); m_fontPx->setSingleStep(1); m_fontPx->setValue(18); form->addRow(QStringLiteral("字号"), m_fontPx); m_align = new PropertyPanelComboBox(this); m_align->addItems({QStringLiteral("左对齐"), QStringLiteral("居中"), QStringLiteral("右对齐")}); polishPropertyStretchyTextField(m_align); form->addRow(QStringLiteral("对齐"), m_align); m_visible = new PropertyPanelCheckBox(QString(), this); m_visible->setChecked(true); m_visible->setToolTip({}); 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_priority, qOverload(&QSpinBox::valueChanged), this, &ToolPropertySection::priorityEdited); 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_priority), 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({}); m_position->setValue(0, 0); m_position->blockSignals(false); } if (m_priority) { m_priority->blockSignals(true); m_priority->setValue(10); m_priority->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->isActivelyEditing()) { m_position->blockSignals(true); m_position->setToolTip({}); m_position->setValue(qRound(s.position.x()), qRound(s.position.y())); m_position->blockSignals(false); } if (m_priority) { m_priority->blockSignals(true); m_priority->setValue(s.priority); m_priority->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