PeriDyno 1.0.0
Loading...
Searching...
No Matches
QPiecewiseDoubleSpinBox.h
Go to the documentation of this file.
1
19#pragma once
20//Qt
21#include <QGroupBox>
22#include <QPushButton>
23#include <QSpinBox>
24#include <QDialog>
25#include <QLineEdit>
26#include <QMouseEvent>
27#include <QWheelEvent>
28#include <QLabel>
29#include <QVBoxLayout>
30
31//PeriDyno
32#include "Format.h"
33#include "FCallBackFunc.h"
34#include "QtGUI/Common.h"
35#include "Core/Vector.h"
36
37//C++
38#include <memory>
39#include <sstream>
40
41namespace dyno
42{
43 class Node;
44 class Module;
45 class FBase;
46
47 class QDoubleSpinner;
48 class QDoubleSlider;
50 class QValueDialog;
51
52 class QPiecewiseDoubleSpinBox : public QDoubleSpinBox
53 {
54 Q_OBJECT
55 public:
56 explicit QPiecewiseDoubleSpinBox(QWidget* parent = nullptr);
57
58 QPiecewiseDoubleSpinBox(Real v, QWidget* parent = nullptr);
59
60 double getRealValue()
61 {
62 return realValue;
63 }
64
65
66 QLineEdit* getLineEdit()
67 {
68 return this->lineEdit();
69 }
70
72
73
74 private:
75 //Prohibited to use
76 void wheelEvent(QWheelEvent* event);
77
78 void mousePressEvent(QMouseEvent* event) override;
79
80 void mouseReleaseEvent(QMouseEvent* event) override;
81
82 void mouseMoveEvent(QMouseEvent* event) override;
83
84 void contextMenuEvent(QContextMenuEvent* event) override;
85
86 double setRealValue(double val)
87 {
88 realValue = val;
89 return realValue;
90 }
91
92 protected:
93
94
95 virtual QString textFromValue(double val) const override
96 {
97 auto qstr = QString::number(realValue, 10, displayDecimals);
98
99 return qstr;
100 }
101
102 virtual double valueFromText(const QString& text) const override
103 {
104 if (istoggle)
105 {
106 return realValue;
107 }
108 else
109 {
110 return text.toDouble();
111 }
112 }
113
114 public:
115
116 signals:
117
118
119 public slots:
120 void ModifyValue(double);
121 void ModifyValueAndUpdate(double);
122 void LineEditFinished(double);
123 void LineEditStart(const QString& qStr);
124
125 void toggleDecimals(bool v)
126 {
127 if (v)
129 else
131
132 istoggle = true;
133
134 auto t = QString::number(realValue, 10, displayDecimals);
135 this->lineEdit()->setText(t);
136
137 istoggle = false;
138 }
139
140 private:
141 int decimalsMin = 3;
142 int decimalsMax = 8;
144 double realValue = 0;
145 bool istoggle = false;
146 };
147
148
149 class QToggleLabel : public QLabel
150 {
151 Q_OBJECT
152 public:
153
154 explicit QToggleLabel(QWidget* parent = nullptr)
155 : QLabel(parent)
156 {
157
158 }
159 explicit QToggleLabel(std::string text,QWidget* parent = nullptr)
160 : QLabel(parent)
161 {
162 this->setText(QString(text.c_str()));
163 }
164
165 Q_SIGNALS:
166 void toggle(bool high);
167
168 protected:
169 void mousePressEvent(QMouseEvent* event) override
170 {
171 current = !current;
172 emit toggle(current);
173 }
174
175
176 private:
177
178 bool current = false;
179 };
180
181
182 class mVec3fWidget : public QWidget
183 {
184 Q_OBJECT
185 public:
186
187 explicit mVec3fWidget(Vec3f v,std::string name,QWidget* parent = nullptr)
188 {
189 this->setContentsMargins(0, 0, 0, 0);
190 QHBoxLayout* layout = new QHBoxLayout;
191
192 nameLabel = new QToggleLabel(name.c_str());
193
194 nameLabel->setMinimumWidth(90);
195
196 this->setLayout(layout);
197
198 v0 = new QPiecewiseDoubleSpinBox(parent);
199 v1 = new QPiecewiseDoubleSpinBox(parent);
200 v2 = new QPiecewiseDoubleSpinBox(parent);
201
202 setRange(-999999,999999);
203
204 v0->setValue(v[0]);
205 v1->setValue(v[1]);
206 v2->setValue(v[2]);
207
208 v0->setMinimumWidth(90);
209 v1->setMinimumWidth(90);
210 v2->setMinimumWidth(90);
211
212 layout->addWidget(nameLabel);
213 layout->addWidget(v0);
214 layout->addWidget(v1);
215 layout->addWidget(v2);
216
217 QObject::connect(v0, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
218 QObject::connect(v1, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
219 QObject::connect(v2, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
220
221 QObject::connect(nameLabel, SIGNAL(toggle(bool)), v0, SLOT(toggleDecimals(bool)));
222 QObject::connect(nameLabel, SIGNAL(toggle(bool)), v1, SLOT(toggleDecimals(bool)));
223 QObject::connect(nameLabel, SIGNAL(toggle(bool)), v2, SLOT(toggleDecimals(bool)));
224 }
225
227 {
228 delete v0;
229 delete v1;
230 delete v2;
231 }
232
234 {
235 return Vec3f(v0->getRealValue(), v1->getRealValue(), v2->getRealValue());
236 };
237
239 {
240 nameLabel->setMinimumWidth(max);
241 }
242
243 void setRange(double min,double max)
244 {
245 v0->setRange(min, max);
246 v1->setRange(min, max);
247 v2->setRange(min, max);
248 }
249
250 void setRange(double min0, double max0, double min1, double max1, double min2, double max2)
251 {
252 v0->setRange(min0, max0);
253 v1->setRange(min1, max1);
254 v2->setRange(min2, max2);
255 }
256
257 Q_SIGNALS:
258
260
261 protected:
262
263 private:
264
268
270
271 };
272
273
274
275 class mPiecewiseDoubleSpinBox : public QWidget
276 {
277 Q_OBJECT
278 public:
279
280 explicit mPiecewiseDoubleSpinBox(double value, std::string name, QWidget* parent = nullptr)
281 {
282 this->setContentsMargins(0, 0, 0, 0);
283 QHBoxLayout* layout = new QHBoxLayout;
284
285 nameLabel = new QToggleLabel(name.c_str());
286 nameLabel->setMinimumWidth(90);
287
288 this->setLayout(layout);
289
290 spinBox = new QPiecewiseDoubleSpinBox(parent);
291 spinBox->setValue(value);
292
293 spinBox->setRange(-99999999, 99999999);
294
295 layout->addWidget(nameLabel);
296 layout->addWidget(spinBox);
297
298 QObject::connect(spinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit valueChange(); });
299
300 QObject::connect(nameLabel, SIGNAL(toggle(bool)), spinBox, SLOT(toggleDecimals(bool)));
301
302 }
303
305 {
306 delete spinBox;
307 delete nameLabel;
308 }
309
310 double getValue()
311 {
312 return spinBox->getRealValue();
313 };
314
316 {
317 nameLabel->setMinimumWidth(max);
318 }
319
320 void setRange(double min,double max)
321 {
322 spinBox->setRange(min,max);
323 }
324
325 Q_SIGNALS:
326
328
329 protected:
330
331 private:
332
334
336 };
337
338
339
340 class QVec3fWidget : public QWidget
341 {
342 Q_OBJECT
343 public:
344
345 explicit QVec3fWidget(Vec3f v, QWidget* parent = nullptr)
346 {
347 this->setContentsMargins(0, 0, 0, 0);
348 QHBoxLayout* layout = new QHBoxLayout;
349
350 this->setLayout(layout);
351
352 v0 = new QPiecewiseDoubleSpinBox(parent);
353 v1 = new QPiecewiseDoubleSpinBox(parent);
354 v2 = new QPiecewiseDoubleSpinBox(parent);
355
356 v0->setValue(v[0]);
357 v1->setValue(v[1]);
358 v2->setValue(v[2]);
359
360
361 layout->addWidget(v0);
362 layout->addWidget(v1);
363 layout->addWidget(v2);
364
365 QObject::connect(v0, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
366 QObject::connect(v1, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
367 QObject::connect(v2, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value) {emit vec3fChange(); });
368
369 }
370
372 {
373 delete v0;
374 delete v1;
375 delete v2;
376 }
377
379 {
380 return Vec3f(v0->getRealValue(), v1->getRealValue(), v2->getRealValue());
381 };
382
383
384
385 Q_SIGNALS:
386
388
389 protected:
390
391 private:
392
396
397
398 };
399
400
401}
double Real
Definition Typedef.inl:23
QPiecewiseDoubleSpinBox(QWidget *parent=nullptr)
void contextMenuEvent(QContextMenuEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void mousePressEvent(QMouseEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
virtual QString textFromValue(double val) const override
virtual double valueFromText(const QString &text) const override
void LineEditStart(const QString &qStr)
QToggleLabel(QWidget *parent=nullptr)
void mousePressEvent(QMouseEvent *event) override
QToggleLabel(std::string text, QWidget *parent=nullptr)
void toggle(bool high)
QPiecewiseDoubleSpinBox * v2
QVec3fWidget(Vec3f v, QWidget *parent=nullptr)
QPiecewiseDoubleSpinBox * v1
QPiecewiseDoubleSpinBox * v0
void setRange(double min, double max)
mPiecewiseDoubleSpinBox(double value, std::string name, QWidget *parent=nullptr)
void setRange(double min0, double max0, double min1, double max1, double min2, double max2)
void setRange(double min, double max)
QPiecewiseDoubleSpinBox * v0
mVec3fWidget(Vec3f v, std::string name, QWidget *parent=nullptr)
QPiecewiseDoubleSpinBox * v2
QPiecewiseDoubleSpinBox * v1
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
#define max(x, y)
Definition svd3_cuda.h:41