109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
#include "props/EntityPropertySection.h"
|
|
|
|
#include "params/ParamControls.h"
|
|
|
|
#include <QDoubleSpinBox>
|
|
#include <QFormLayout>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QVBoxLayout>
|
|
|
|
namespace gui {
|
|
|
|
EntityPropertySection::EntityPropertySection(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_name = new QLineEdit(this);
|
|
m_name->setPlaceholderText(QStringLiteral("显示名称"));
|
|
m_name->setToolTip(QStringLiteral("仅显示用;内部 id 不变"));
|
|
form->addRow(QStringLiteral("名称"), m_name);
|
|
|
|
m_depth = new QLabel(QStringLiteral("-"), this);
|
|
m_distScale = new QLabel(QStringLiteral("-"), this);
|
|
for (QLabel* lab : {m_depth, m_distScale}) {
|
|
lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
}
|
|
form->addRow(QStringLiteral("深度"), m_depth);
|
|
form->addRow(QStringLiteral("距离缩放"), m_distScale);
|
|
|
|
m_pivot = new Vec2ParamControl(this);
|
|
m_pivot->setToolTip(QStringLiteral("枢轴在世界坐标中的位置(限制在轮廓包络内),用于重定位局部原点"));
|
|
form->addRow(QStringLiteral("中心坐标"), m_pivot);
|
|
|
|
m_centroid = new Vec2ParamControl(this);
|
|
m_centroid->setToolTip(QStringLiteral("实体几何质心的世界坐标;修改将整体平移实体"));
|
|
form->addRow(QStringLiteral("位置"), m_centroid);
|
|
|
|
m_userScale = new QDoubleSpinBox(this);
|
|
m_userScale->setRange(0.05, 20.0);
|
|
m_userScale->setDecimals(3);
|
|
m_userScale->setSingleStep(0.05);
|
|
m_userScale->setValue(1.0);
|
|
m_userScale->setToolTip(QStringLiteral("人为整体缩放,与深度距离缩放相乘"));
|
|
form->addRow(QStringLiteral("整体缩放"), m_userScale);
|
|
|
|
lay->addLayout(form);
|
|
lay->addStretch(1);
|
|
|
|
connect(m_name, &QLineEdit::editingFinished, this, [this]() {
|
|
if (m_name) {
|
|
emit displayNameCommitted(m_name->text());
|
|
}
|
|
});
|
|
connect(m_pivot, &Vec2ParamControl::valueChanged, this, &EntityPropertySection::pivotEdited);
|
|
connect(m_centroid, &Vec2ParamControl::valueChanged, this, &EntityPropertySection::centroidEdited);
|
|
connect(m_userScale, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &EntityPropertySection::userScaleEdited);
|
|
}
|
|
|
|
void EntityPropertySection::clearDisconnected() {
|
|
setEditingEnabled(false);
|
|
if (m_name) {
|
|
m_name->blockSignals(true);
|
|
m_name->clear();
|
|
m_name->blockSignals(false);
|
|
}
|
|
if (m_depth) m_depth->setText(QStringLiteral("-"));
|
|
if (m_distScale) m_distScale->setText(QStringLiteral("-"));
|
|
if (m_pivot) m_pivot->setValue(0.0, 0.0);
|
|
if (m_centroid) m_centroid->setValue(0.0, 0.0);
|
|
if (m_userScale) {
|
|
m_userScale->blockSignals(true);
|
|
m_userScale->setValue(1.0);
|
|
m_userScale->blockSignals(false);
|
|
}
|
|
}
|
|
|
|
void EntityPropertySection::applyState(const EntityPropertyUiState& s) {
|
|
setEditingEnabled(true);
|
|
if (m_name) {
|
|
m_name->blockSignals(true);
|
|
m_name->setText(s.displayName);
|
|
m_name->blockSignals(false);
|
|
}
|
|
if (m_depth) m_depth->setText(QString::number(s.depthZ));
|
|
if (m_distScale) m_distScale->setText(s.distanceScaleText);
|
|
if (m_pivot) m_pivot->setValue(s.pivot.x(), s.pivot.y());
|
|
if (m_centroid) m_centroid->setValue(s.centroid.x(), s.centroid.y());
|
|
if (m_userScale) {
|
|
m_userScale->blockSignals(true);
|
|
m_userScale->setValue(s.userScale);
|
|
m_userScale->blockSignals(false);
|
|
}
|
|
}
|
|
|
|
void EntityPropertySection::setEditingEnabled(bool on) {
|
|
if (m_name) m_name->setEnabled(on);
|
|
if (m_pivot) m_pivot->setEnabled(on);
|
|
if (m_centroid) m_centroid->setEnabled(on);
|
|
if (m_userScale) m_userScale->setEnabled(on);
|
|
}
|
|
|
|
} // namespace gui
|