Files
hfut-bishe/client/gui/props/CameraPropertySection.cpp
2026-04-23 13:11:36 +08:00

112 lines
3.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "props/CameraPropertySection.h"
#include "params/ParamControls.h"
#include <QCheckBox>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
namespace gui {
CameraPropertySection::CameraPropertySection(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("显示名称…"));
form->addRow(QStringLiteral("名称"), m_name);
m_center = new Vec2ParamControl(this);
m_center->setToolTip(QStringLiteral("摄像机中心(世界坐标),与画布上黄色圆点一致"));
form->addRow(QStringLiteral("中心"), m_center);
m_viewScale = new QDoubleSpinBox(this);
m_viewScale->setRange(1e-4, 1000.0);
m_viewScale->setDecimals(5);
m_viewScale->setSingleStep(0.01);
m_viewScale->setToolTip(QStringLiteral(
"视口缩放:在参考分辨率 1600×900 下的像素/世界单位比(与预览、画布上镜头框一致);"
"不随当前窗口大小改变镜头覆盖的世界范围。数值越小,可见的世界范围越大。"));
form->addRow(QStringLiteral("缩放"), m_viewScale);
m_activePreview = new QCheckBox(QStringLiteral("用作预览展示镜头"), this);
m_activePreview->setToolTip(QStringLiteral("进入预览展示时,按该摄像机在当前帧的位置与缩放呈现画面"));
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](double x, double 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, 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->blockSignals(true);
m_center->setValue(s.centerWorld.x(), 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