PeriDyno 1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
QVector3FieldWidget.cpp
Go to the documentation of this file.
2
3#include <QVBoxLayout>
4
5#include "Field.h"
7
8
9namespace dyno
10{
12
15 {
16 QGridLayout* layout = new QGridLayout;
17 layout->setContentsMargins(0, 0, 0, 0);
18 layout->setSpacing(0);
19
20 this->setLayout(layout);
21
22 QToggleLabel* name = new QToggleLabel();
23 QString str = FormatFieldWidgetName(field->getObjectName());
24 name->setFixedSize(100, 18);
25 QFontMetrics fontMetrics(name->font());
26 QString elide = fontMetrics.elidedText(str, Qt::ElideRight, 100);
27 name->setText(elide);
28 //Set label tips
29 name->setToolTip(str);
30
32 spinner1->setMinimumWidth(30);
33 spinner1->setRange(field->getMin(), field->getMax());
34
36 spinner2->setMinimumWidth(30);
37 spinner2->setRange(field->getMin(), field->getMax());
38
40 spinner3->setMinimumWidth(30);
41 spinner3->setRange(field->getMin(), field->getMax());
42
43 layout->addWidget(name, 0, 0);
44 layout->addWidget(spinner1, 0, 1);
45 layout->addWidget(spinner2, 0, 2);
46 layout->addWidget(spinner3, 0, 3);
47 layout->setSpacing(3);
48
49 std::string template_name = field->getTemplateName();
50
51 double v1 = 0;
52 double v2 = 0;
53 double v3 = 0;
54
55 if (template_name == std::string(typeid(Vec3f).name()))
56 {
58 auto v = f->getValue();
59 v1 = v[0];
60 v2 = v[1];
61 v3 = v[2];
62 }
63 else if (template_name == std::string(typeid(Vec3d).name()))
64 {
66 auto v = f->getValue();
67
68 v1 = v[0];
69 v2 = v[1];
70 v3 = v[2];
71 }
72 spinner1->ModifyValueAndUpdate(v1);
73 spinner2->ModifyValueAndUpdate(v2);
74 spinner3->ModifyValueAndUpdate(v3);
75
76 QObject::connect(spinner1, SIGNAL(valueChanged(double)), this, SLOT(updateField(double)));
77 QObject::connect(spinner2, SIGNAL(valueChanged(double)), this, SLOT(updateField(double)));
78 QObject::connect(spinner3, SIGNAL(valueChanged(double)), this, SLOT(updateField(double)));
79
80 QObject::connect(name, SIGNAL(toggle(bool)), spinner1, SLOT(toggleDecimals(bool)));
81 QObject::connect(name, SIGNAL(toggle(bool)), spinner2, SLOT(toggleDecimals(bool)));
82 QObject::connect(name, SIGNAL(toggle(bool)), spinner3, SLOT(toggleDecimals(bool)));
83
84
85
86 QObject::connect(this, SIGNAL(fieldChanged()), this, SLOT(updateWidget()));
87 }
88
89
91 {
92 value = v;
93
94 QGridLayout* layout = new QGridLayout;
95 layout->setContentsMargins(0, 0, 0, 0);
96 layout->setSpacing(0);
97
98 this->setLayout(layout);
99
100 QToggleLabel* nameLabel = new QToggleLabel();
101
102 nameLabel->setFixedSize(100, 18);
103 QFontMetrics fontMetrics(nameLabel->font());
104 QString elide = fontMetrics.elidedText(name, Qt::ElideRight, 100);
105 nameLabel->setText(elide);
106 //Set label tips
107 nameLabel->setToolTip(name);
108
110 spinner1->setMinimumWidth(30);
111 spinner1->setRange(-100000, 100000);
112
114 spinner2->setMinimumWidth(30);
115 spinner2->setRange(-100000, 100000);
116
118 spinner3->setMinimumWidth(30);
119 spinner3->setRange(-100000, 100000);
120
121
122 layout->addWidget(nameLabel, 0, 0);
123 layout->addWidget(spinner1, 0, 1);
124 layout->addWidget(spinner2, 0, 2);
125 layout->addWidget(spinner3, 0, 3);
126 layout->setSpacing(3);
127
128
129 QObject::connect(nameLabel, SIGNAL(toggle(bool)), spinner1, SLOT(toggleDecimals(bool)));
130 QObject::connect(nameLabel, SIGNAL(toggle(bool)), spinner2, SLOT(toggleDecimals(bool)));
131 QObject::connect(nameLabel, SIGNAL(toggle(bool)), spinner3, SLOT(toggleDecimals(bool)));
132
133 QObject::connect(spinner1, SIGNAL(valueChanged(double)), this, SLOT(vec3fValueChange(double)));
134 QObject::connect(spinner2, SIGNAL(valueChanged(double)), this, SLOT(vec3fValueChange(double)));
135 QObject::connect(spinner3, SIGNAL(valueChanged(double)), this, SLOT(vec3fValueChange(double)));
136
137 //QObject::connect(this, SIGNAL(fieldChanged()), this, SLOT(updateWidget()));
138 }
139
140
144
146 {
147 double v1 = spinner1->getRealValue();
148 double v2 = spinner2->getRealValue();
149 double v3 = spinner3->getRealValue();
150
151 std::string template_name = field()->getTemplateName();
152
153 if (template_name == std::string(typeid(Vec3f).name()))
154 {
156 f->setValue(Vec3f((float)v1, (float)v2, (float)v3));
157 }
158 else if (template_name == std::string(typeid(Vec3d).name()))
159 {
161 f->setValue(Vec3d(v1, v2, v3));
162 }
163 }
164
165
167 {
168 std::string template_name = field()->getTemplateName();
169
170 double v1 = 0;
171 double v2 = 0;
172 double v3 = 0;
173
174 if (template_name == std::string(typeid(Vec3f).name()))
175 {
177 auto v = f->getValue();
178 v1 = v[0];
179 v2 = v[1];
180 v3 = v[2];
181 }
182 else if (template_name == std::string(typeid(Vec3d).name()))
183 {
185 auto v = f->getValue();
186
187 v1 = v[0];
188 v2 = v[1];
189 v3 = v[2];
190 }
191
192 spinner1->blockSignals(true);
193 spinner2->blockSignals(true);
194 spinner3->blockSignals(true);
195
196 spinner1->ModifyValueAndUpdate(v1);
197 spinner2->ModifyValueAndUpdate(v2);
198 spinner3->ModifyValueAndUpdate(v3);
199
200 spinner1->blockSignals(false);
201 spinner2->blockSignals(false);
202 spinner3->blockSignals(false);
203 }
204
206 {
207 value = Vec3f(spinner1->getRealValue(), spinner2->getRealValue(), spinner3->getRealValue());
208 emit vec3fChange(double(value[0]), double(value[1]), double(value[2]));
209 }
210
211}
212
#define IMPL_FIELD_WIDGET(_data_type_, _type_)
virtual const std::string getTemplateName()
Definition FBase.h:51
T getValue()
Definition Field.h:130
void setValue(T val)
Definition Field.h:111
QFieldWidget(FBase *field)
QPiecewiseDoubleSpinBox * spinner1
QPiecewiseDoubleSpinBox * spinner3
void vec3fChange(double, double, double)
QPiecewiseDoubleSpinBox * spinner2
DECLARE_FIELD_WIDGET QVector3FieldWidget(FBase *field)
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9
Vector< double, 3 > Vec3d
Definition Vector3D.h:94
Vector< float, 3 > Vec3f
Definition Vector3D.h:93