-
Notifications
You must be signed in to change notification settings - Fork 2
/
widgets.h
388 lines (336 loc) · 11.4 KB
/
widgets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#ifndef WIDGETS_H
#define WIDGETS_H
#include <QObject>
#include <QWidget>
#include <QHBoxLayout>
#include <QUrl>
#include <QLineEdit>
#include <QToolButton>
#include <QFileDialog>
#include <QMatrix4x4>
#include <QGridLayout>
#include <QDoubleSpinBox>
#include <QVector2D>
#include <QVector3D>
#include <QVector4D>
#include <QQuaternion>
#include <QItemEditorCreatorBase>
class UrlWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QUrl value READ value WRITE setValue NOTIFY valueChanged)
public:
inline UrlWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_lineEdit = new QLineEdit(this));
{
auto toolButton = new QToolButton(this);
connect(toolButton, &QAbstractButton::pressed, this, &UrlWidget::pressed);
layout->addWidget(toolButton);
}
setLayout(layout);
}
inline QUrl value() const
{
return QUrl(m_lineEdit->text());
}
inline void setValue(const QUrl &value)
{
m_lineEdit->setText(value.toString());
}
Q_SIGNALS:
void valueChanged(const QUrl &value);
private Q_SLOTS:
inline void pressed()
{
auto path = QFileDialog::getOpenFileName(this);
if(!path.isEmpty())
m_lineEdit->setText(path);
}
private:
QLineEdit *m_lineEdit;
};
class UrlCreator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new UrlWidget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
class Matrix4x4Widget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QMatrix4x4 value READ value WRITE setValue NOTIFY valueChanged)
public:
inline Matrix4x4Widget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QGridLayout(this);
layout->setMargin(0);
layout->addWidget(m_doubleSpinBox11 = new QDoubleSpinBox(this), 0, 0);
layout->addWidget(m_doubleSpinBox12 = new QDoubleSpinBox(this), 0, 1);
layout->addWidget(m_doubleSpinBox13 = new QDoubleSpinBox(this), 0, 2);
layout->addWidget(m_doubleSpinBox14 = new QDoubleSpinBox(this), 0, 3);
layout->addWidget(m_doubleSpinBox21 = new QDoubleSpinBox(this), 1, 0);
layout->addWidget(m_doubleSpinBox22 = new QDoubleSpinBox(this), 1, 1);
layout->addWidget(m_doubleSpinBox23 = new QDoubleSpinBox(this), 1, 2);
layout->addWidget(m_doubleSpinBox24 = new QDoubleSpinBox(this), 1, 3);
layout->addWidget(m_doubleSpinBox31 = new QDoubleSpinBox(this), 2, 0);
layout->addWidget(m_doubleSpinBox32 = new QDoubleSpinBox(this), 2, 1);
layout->addWidget(m_doubleSpinBox33 = new QDoubleSpinBox(this), 2, 2);
layout->addWidget(m_doubleSpinBox34 = new QDoubleSpinBox(this), 2, 3);
layout->addWidget(m_doubleSpinBox41 = new QDoubleSpinBox(this), 3, 0);
layout->addWidget(m_doubleSpinBox42 = new QDoubleSpinBox(this), 3, 1);
layout->addWidget(m_doubleSpinBox43 = new QDoubleSpinBox(this), 3, 2);
layout->addWidget(m_doubleSpinBox44 = new QDoubleSpinBox(this), 3, 3);
setLayout(layout);
}
inline QMatrix4x4 value() const
{
return QMatrix4x4(m_doubleSpinBox11->value(), m_doubleSpinBox12->value(), m_doubleSpinBox13->value(), m_doubleSpinBox14->value(),
m_doubleSpinBox21->value(), m_doubleSpinBox22->value(), m_doubleSpinBox23->value(), m_doubleSpinBox24->value(),
m_doubleSpinBox31->value(), m_doubleSpinBox32->value(), m_doubleSpinBox33->value(), m_doubleSpinBox34->value(),
m_doubleSpinBox41->value(), m_doubleSpinBox42->value(), m_doubleSpinBox43->value(), m_doubleSpinBox44->value());
}
inline void setValue(const QMatrix4x4 &value)
{
{
auto row = value.row(0);
m_doubleSpinBox11->setValue(row.x());
m_doubleSpinBox12->setValue(row.y());
m_doubleSpinBox13->setValue(row.z());
m_doubleSpinBox14->setValue(row.w());
}
{
auto row = value.row(1);
m_doubleSpinBox21->setValue(row.x());
m_doubleSpinBox22->setValue(row.y());
m_doubleSpinBox23->setValue(row.z());
m_doubleSpinBox24->setValue(row.w());
}
{
auto row = value.row(2);
m_doubleSpinBox31->setValue(row.x());
m_doubleSpinBox32->setValue(row.y());
m_doubleSpinBox33->setValue(row.z());
m_doubleSpinBox34->setValue(row.w());
}
{
auto row = value.row(3);
m_doubleSpinBox41->setValue(row.x());
m_doubleSpinBox42->setValue(row.y());
m_doubleSpinBox43->setValue(row.z());
m_doubleSpinBox44->setValue(row.w());
}
}
Q_SIGNALS:
void valueChanged(const QMatrix4x4 &value);
private:
QDoubleSpinBox *m_doubleSpinBox11, *m_doubleSpinBox12, *m_doubleSpinBox13, *m_doubleSpinBox14;
QDoubleSpinBox *m_doubleSpinBox21, *m_doubleSpinBox22, *m_doubleSpinBox23, *m_doubleSpinBox24;
QDoubleSpinBox *m_doubleSpinBox31, *m_doubleSpinBox32, *m_doubleSpinBox33, *m_doubleSpinBox34;
QDoubleSpinBox *m_doubleSpinBox41, *m_doubleSpinBox42, *m_doubleSpinBox43, *m_doubleSpinBox44;
};
class Matrix4x4Creator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new Matrix4x4Widget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
class Vector2DWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVector2D value READ value WRITE setValue NOTIFY valueChanged)
public:
inline Vector2DWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_doubleSpinBoxX = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxY = new QDoubleSpinBox(this));
setLayout(layout);
}
inline QVector2D value() const
{
return QVector2D(m_doubleSpinBoxX->value(), m_doubleSpinBoxY->value());
}
inline void setValue(const QVector2D &value)
{
m_doubleSpinBoxX->setValue(value.x());
m_doubleSpinBoxY->setValue(value.y());
}
Q_SIGNALS:
void valueChanged(const QVector2D &value);
private:
QDoubleSpinBox *m_doubleSpinBoxX;
QDoubleSpinBox *m_doubleSpinBoxY;
};
class Vector2DCreator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new Vector2DWidget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
class Vector3DWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVector3D value READ value WRITE setValue NOTIFY valueChanged)
public:
inline Vector3DWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_doubleSpinBoxX = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxY = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxZ = new QDoubleSpinBox(this));
setLayout(layout);
}
inline QVector3D value() const
{
return QVector3D(m_doubleSpinBoxX->value(), m_doubleSpinBoxY->value(), m_doubleSpinBoxZ->value());
}
inline void setValue(const QVector3D &value)
{
m_doubleSpinBoxX->setValue(value.x());
m_doubleSpinBoxY->setValue(value.y());
m_doubleSpinBoxZ->setValue(value.z());
}
Q_SIGNALS:
void valueChanged(const QVector3D &value);
private:
QDoubleSpinBox *m_doubleSpinBoxX;
QDoubleSpinBox *m_doubleSpinBoxY;
QDoubleSpinBox *m_doubleSpinBoxZ;
};
class Vector3DCreator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new Vector3DWidget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
class Vector4DWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVector4D value READ value WRITE setValue NOTIFY valueChanged)
public:
inline Vector4DWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_doubleSpinBoxX = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxY = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxZ = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxW = new QDoubleSpinBox(this));
setLayout(layout);
}
inline QVector4D value() const
{
return QVector4D(m_doubleSpinBoxX->value(), m_doubleSpinBoxY->value(), m_doubleSpinBoxZ->value(), m_doubleSpinBoxW->value());
}
inline void setValue(const QVector4D &value)
{
m_doubleSpinBoxX->setValue(value.x());
m_doubleSpinBoxY->setValue(value.y());
m_doubleSpinBoxZ->setValue(value.z());
m_doubleSpinBoxW->setValue(value.w());
}
Q_SIGNALS:
void valueChanged(const QVector4D &value);
private:
QDoubleSpinBox *m_doubleSpinBoxX;
QDoubleSpinBox *m_doubleSpinBoxY;
QDoubleSpinBox *m_doubleSpinBoxZ;
QDoubleSpinBox *m_doubleSpinBoxW;
};
class Vector4DCreator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new Vector4DWidget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
class QuaternionWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QQuaternion value READ value WRITE setValue NOTIFY valueChanged)
public:
inline QuaternionWidget(QWidget *parent = Q_NULLPTR) : QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_doubleSpinBoxX = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxY = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxZ = new QDoubleSpinBox(this));
layout->addWidget(m_doubleSpinBoxScalar = new QDoubleSpinBox(this));
setLayout(layout);
}
inline QQuaternion value() const
{
return QQuaternion(m_doubleSpinBoxX->value(), m_doubleSpinBoxY->value(), m_doubleSpinBoxZ->value(), m_doubleSpinBoxScalar->value());
}
inline void setValue(const QQuaternion &value)
{
m_doubleSpinBoxX->setValue(value.x());
m_doubleSpinBoxY->setValue(value.y());
m_doubleSpinBoxZ->setValue(value.z());
m_doubleSpinBoxScalar->setValue(value.scalar());
}
Q_SIGNALS:
void valueChanged(const QQuaternion &value);
private:
QDoubleSpinBox *m_doubleSpinBoxX;
QDoubleSpinBox *m_doubleSpinBoxY;
QDoubleSpinBox *m_doubleSpinBoxZ;
QDoubleSpinBox *m_doubleSpinBoxScalar;
};
class QuaternionCreator : public QItemEditorCreatorBase
{
public:
QWidget *createWidget(QWidget *parent) const Q_DECL_OVERRIDE
{
return new QuaternionWidget(parent);
}
QByteArray valuePropertyName() const Q_DECL_OVERRIDE
{
return "value";
}
};
template<int Tmin, int Tmax>
class LimitedQSpinBox : public QSpinBox
{
public:
inline LimitedQSpinBox(QWidget *parent = Q_NULLPTR) : QSpinBox(parent)
{
setRange(Tmin, Tmax);
}
};
#endif // WIDGETS_H