Files
hfut-bishe/client/gui/props/CameraPropertySection.cpp
2026-05-14 13:30:06 +08:00

112 lines
3.6 KiB
C++

#include "props/CameraPropertySection.h"
#include "params/ParamControls.h"
#include <QCheckBox>
#include <QDoubleSpinBox>
#include "widgets/CompactNumericSpinBox.h"
#include "widgets/PropertyPanelControls.h"
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
namespace gui {
CameraPropertySection::CameraPropertySection(QWidget* parent) : PropertySectionWidget(parent) {
auto* lay = new QVBoxLayout(this);
polishPropertyVBoxLayout(lay);
auto* form = new QFormLayout();
polishPropertyFormLayout(form);
m_name = new PropertyPanelLineEdit(this);
m_name->setPlaceholderText(QStringLiteral("显示名称…"));
polishPropertyStretchyTextField(m_name);
form->addRow(QStringLiteral("名称"), m_name);
m_center = new Vec2ParamControl(this);
m_center->setToolTip({});
form->addRow(QStringLiteral("中心"), m_center);
m_viewScale = new CompactDoubleSpinBox(this, 56);
m_viewScale->setRange(1e-4, 1000.0);
m_viewScale->setDecimals(5);
m_viewScale->setSingleStep(0.01);
m_viewScale->setToolTip({});
form->addRow(QStringLiteral("缩放"), m_viewScale);
m_activePreview = new PropertyPanelCheckBox(QStringLiteral("用作预览展示镜头"), this);
m_activePreview->setToolTip({});
form->addRow(QStringLiteral("预览"), m_activePreview);
lay->addLayout(form);
lay->addStretch(1);
connect(m_name, &QLineEdit::editingFinished, this, [this]() {
if (m_name) emit displayNameCommitted(m_name->text());
});
connect(m_center, &Vec2ParamControl::valueChanged, this, [this](int x, int y) { emit centerEdited(x, y); });
connect(m_viewScale, qOverload<double>(&QDoubleSpinBox::valueChanged), this,
&CameraPropertySection::viewScaleEdited);
connect(m_activePreview, &QCheckBox::toggled, this, &CameraPropertySection::activePreviewToggled);
}
void CameraPropertySection::setEditingEnabled(bool on) {
for (auto* w : {static_cast<QWidget*>(m_name), static_cast<QWidget*>(m_center), static_cast<QWidget*>(m_viewScale),
static_cast<QWidget*>(m_activePreview)}) {
if (w) w->setEnabled(on);
}
}
void CameraPropertySection::clearDisconnected() {
setEditingEnabled(false);
if (m_name) {
m_name->blockSignals(true);
m_name->clear();
m_name->blockSignals(false);
}
if (m_center) {
m_center->blockSignals(true);
m_center->setValue(0, 0);
m_center->blockSignals(false);
}
if (m_viewScale) {
m_viewScale->blockSignals(true);
m_viewScale->setValue(1.0);
m_viewScale->blockSignals(false);
}
if (m_activePreview) {
m_activePreview->blockSignals(true);
m_activePreview->setChecked(false);
m_activePreview->blockSignals(false);
}
}
void CameraPropertySection::applyState(const CameraPropertyUiState& s) {
setEditingEnabled(true);
if (m_name) {
m_name->blockSignals(true);
m_name->setText(s.displayName);
m_name->blockSignals(false);
}
if (m_center && !m_center->isActivelyEditing()) {
m_center->blockSignals(true);
m_center->setValue(qRound(s.centerWorld.x()), qRound(s.centerWorld.y()));
m_center->blockSignals(false);
}
if (m_viewScale) {
m_viewScale->blockSignals(true);
m_viewScale->setValue(s.viewScale);
m_viewScale->blockSignals(false);
}
if (m_activePreview) {
m_activePreview->blockSignals(true);
m_activePreview->setChecked(s.isActivePreviewCamera);
m_activePreview->blockSignals(false);
}
}
} // namespace gui