SIEdit/app/vector3edit.cpp

64 lines
1.8 KiB
C++
Raw Normal View History

#include "vector3edit.h"
#include <QHBoxLayout>
#include <QLabel>
Vector3Edit::Vector3Edit(QWidget *parent) :
QWidget{parent}
{
auto layout = new QHBoxLayout(this);
layout->addWidget(new QLabel(tr("X")));
x_edit_ = new QDoubleSpinBox();
x_edit_->setMinimum(std::numeric_limits<double>::lowest());
x_edit_->setMaximum(std::numeric_limits<double>::max());
layout->addWidget(x_edit_);
connect(x_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
layout->addStretch();
layout->addWidget(new QLabel(tr("Y")));
y_edit_ = new QDoubleSpinBox();
y_edit_->setMinimum(std::numeric_limits<double>::lowest());
y_edit_->setMaximum(std::numeric_limits<double>::max());
layout->addWidget(y_edit_);
connect(y_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
layout->addStretch();
layout->addWidget(new QLabel(tr("Z")));
z_edit_ = new QDoubleSpinBox();
z_edit_->setMinimum(std::numeric_limits<double>::lowest());
z_edit_->setMaximum(std::numeric_limits<double>::max());
layout->addWidget(z_edit_);
connect(z_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
}
si::Vector3 Vector3Edit::GetValue() const
{
return si::Vector3(x_edit_->value(), y_edit_->value(), z_edit_->value());
}
void Vector3Edit::SetValue(const si::Vector3 &xyz)
{
x_edit_->blockSignals(true);
y_edit_->blockSignals(true);
z_edit_->blockSignals(true);
x_edit_->setValue(xyz.x);
y_edit_->setValue(xyz.y);
z_edit_->setValue(xyz.z);
x_edit_->blockSignals(false);
y_edit_->blockSignals(false);
z_edit_->blockSignals(false);
}
void Vector3Edit::internalChanged()
{
emit changed(si::Vector3(x_edit_->value(), y_edit_->value(), z_edit_->value()));
}