Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
Vector3Widget.cpp
Go to the documentation of this file.
1#include "Vector3Widget.h"
2
3Vector3Widget::Vector3Widget(const QString& suffix, QWidget* parent) : QWidget(parent) {
4 QHBoxLayout* layout = new QHBoxLayout(this);
5 layout->setContentsMargins(0,0,0,0);
6
7 auto setupSpin = [&](QDoubleSpinBox*& spin) {
8 spin = new QDoubleSpinBox();
9 spin->setRange(-10000000.0, 10000000.0);
10 spin->setDecimals(2);
11 spin->setButtonSymbols(QAbstractSpinBox::NoButtons); // Clean look
12 spin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
13 spin->setSuffix(suffix);
14 layout->addWidget(spin);
15
16 connect(spin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, [this](double) {
17 emit valueChanged(getValue());
18 });
19 };
20
21 setupSpin(xSpin);
22 setupSpin(ySpin);
23 setupSpin(zSpin);
24}
25
26glm::vec3 Vector3Widget::getValue() const {
27 return glm::vec3(xSpin->value(), ySpin->value(), zSpin->value());
28}
29
30void Vector3Widget::setValue(const glm::vec3& v) {
31 QSignalBlocker b1(xSpin); QSignalBlocker b2(ySpin); QSignalBlocker b3(zSpin);
32 xSpin->setValue(v.x);
33 ySpin->setValue(v.y);
34 zSpin->setValue(v.z);
35}
void valueChanged(const glm::vec3 &newValue)
void setValue(const glm::vec3 &v)
glm::vec3 getValue() const
Vector3Widget(const QString &suffix="", QWidget *parent=nullptr)