57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#include "dialogs/EntityFinalizeDialog.h"
|
||
|
||
#include <QDialogButtonBox>
|
||
#include <QFormLayout>
|
||
#include <QLineEdit>
|
||
#include <QDoubleSpinBox>
|
||
#include <QVBoxLayout>
|
||
|
||
EntityFinalizeDialog::EntityFinalizeDialog(QWidget* parent)
|
||
: QDialog(parent) {
|
||
setWindowTitle(QStringLiteral("确认实体"));
|
||
setModal(true);
|
||
|
||
auto* root = new QVBoxLayout(this);
|
||
auto* form = new QFormLayout();
|
||
|
||
m_name = new QLineEdit(this);
|
||
m_name->setPlaceholderText(QStringLiteral("例如:entity-1、人物、树、建筑…"));
|
||
form->addRow(QStringLiteral("名称"), m_name);
|
||
|
||
m_userScale = new QDoubleSpinBox(this);
|
||
m_userScale->setDecimals(3);
|
||
m_userScale->setRange(0.01, 50.0);
|
||
m_userScale->setSingleStep(0.05);
|
||
form->addRow(QStringLiteral("整体缩放"), m_userScale);
|
||
|
||
root->addLayout(form);
|
||
|
||
auto* btns = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||
connect(btns, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||
connect(btns, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||
root->addWidget(btns);
|
||
}
|
||
|
||
void EntityFinalizeDialog::setDefaultName(const QString& name) {
|
||
if (m_name) {
|
||
m_name->setText(name);
|
||
m_name->selectAll();
|
||
m_name->setFocus();
|
||
}
|
||
}
|
||
|
||
QString EntityFinalizeDialog::name() const {
|
||
return m_name ? m_name->text().trimmed() : QString();
|
||
}
|
||
|
||
void EntityFinalizeDialog::setUserScale(double s) {
|
||
if (m_userScale) {
|
||
m_userScale->setValue(s);
|
||
}
|
||
}
|
||
|
||
double EntityFinalizeDialog::userScale() const {
|
||
return m_userScale ? m_userScale->value() : 1.0;
|
||
}
|
||
|