增加摄像机
This commit is contained in:
111
client/gui/props/CameraPropertySection.cpp
Normal file
111
client/gui/props/CameraPropertySection.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#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
|
||||
47
client/gui/props/CameraPropertySection.h
Normal file
47
client/gui/props/CameraPropertySection.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "props/PropertySectionWidget.h"
|
||||
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
|
||||
class QCheckBox;
|
||||
class QDoubleSpinBox;
|
||||
class QLineEdit;
|
||||
|
||||
namespace gui {
|
||||
class Vec2ParamControl;
|
||||
}
|
||||
|
||||
namespace gui {
|
||||
|
||||
struct CameraPropertyUiState {
|
||||
QString displayName;
|
||||
QPointF centerWorld;
|
||||
double viewScale = 1.0;
|
||||
bool isActivePreviewCamera = false;
|
||||
};
|
||||
|
||||
class CameraPropertySection final : public PropertySectionWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CameraPropertySection(QWidget* parent = nullptr);
|
||||
|
||||
void clearDisconnected();
|
||||
void applyState(const CameraPropertyUiState& s);
|
||||
void setEditingEnabled(bool on);
|
||||
|
||||
signals:
|
||||
void displayNameCommitted(const QString& text);
|
||||
void centerEdited(double x, double y);
|
||||
void viewScaleEdited(double viewScale);
|
||||
void activePreviewToggled(bool on);
|
||||
|
||||
private:
|
||||
QLineEdit* m_name = nullptr;
|
||||
Vec2ParamControl* m_center = nullptr;
|
||||
QDoubleSpinBox* m_viewScale = nullptr;
|
||||
QCheckBox* m_activePreview = nullptr;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
Reference in New Issue
Block a user