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
389
390
391
392
393
394
395
396
397
398
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D Editor of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.5
import QtQuick.Layouts 1.2
Item {
id: matrix4x4Input
width: parent.width
height: mainLayout.height
property real cellwidth: matrix4x4Input.width / 4 - 4 // 4 = column spacing
property alias label: matrixLabel.text
property int roundDigits: 2 // TODO: Determine nice default rounding
property int roundMultiplier: Math.pow(10, roundDigits) // Calculated from roundDigits, do not set directly
property matrix4x4 value: Qt.matrix4x4(0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0)
property bool affine: true
property alias tooltip: matrixLabel.tooltip
signal valueEdited
function roundNumber(number) {
if (roundDigits >= 0)
return Math.round(number * roundMultiplier) / roundMultiplier
else
return number
}
onValueChanged: {
m11Field.text = roundNumber(value.m11)
m12Field.text = roundNumber(value.m12)
m13Field.text = roundNumber(value.m13)
m14Field.text = roundNumber(value.m14)
m21Field.text = roundNumber(value.m21)
m22Field.text = roundNumber(value.m22)
m23Field.text = roundNumber(value.m23)
m24Field.text = roundNumber(value.m24)
m31Field.text = roundNumber(value.m31)
m32Field.text = roundNumber(value.m32)
m33Field.text = roundNumber(value.m33)
m34Field.text = roundNumber(value.m34)
m41Field.text = roundNumber(value.m41)
m42Field.text = roundNumber(value.m42)
m43Field.text = roundNumber(value.m43)
m44Field.text = roundNumber(value.m44)
}
DoubleValidator {
id: doubleValidator
locale: "C"
}
ColumnLayout {
id: mainLayout
anchors.right: parent.right
anchors.left: parent.left
StyledLabel {
id: matrixLabel
text: qsTr("Matrix4x4") + editorScene.emptyString
Layout.alignment: Qt.AlignLeft
}
ColumnLayout {
Layout.alignment: Qt.AlignLeft
RowLayout {
StyledTextField {
id: m11Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m11
matrix4x4Input.value.m11 = text
if (oldValue !== matrix4x4Input.value.m11)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m11)
}
StyledTextField {
id: m12Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m12
matrix4x4Input.value.m12 = text
if (oldValue !== matrix4x4Input.value.m12)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m12)
}
StyledTextField {
id: m13Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m13
matrix4x4Input.value.m13 = text
if (oldValue !== matrix4x4Input.value.m13)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m13)
}
StyledTextField {
id: m14Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m14
matrix4x4Input.value.m14 = text
if (oldValue !== matrix4x4Input.value.m14)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m14)
}
}
RowLayout {
StyledTextField {
id: m21Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m21
matrix4x4Input.value.m21 = text
if (oldValue !== matrix4x4Input.value.m21)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m21)
}
StyledTextField {
id: m22Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m22
matrix4x4Input.value.m22 = text
if (oldValue !== matrix4x4Input.value.m22)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m22)
}
StyledTextField {
id: m23Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m23
matrix4x4Input.value.m23 = text
if (oldValue !== matrix4x4Input.value.m23)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m23)
}
StyledTextField {
id: m24Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m24
matrix4x4Input.value.m24 = text
if (oldValue !== matrix4x4Input.value.m24)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m24)
}
}
RowLayout {
StyledTextField {
id: m31Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m31
matrix4x4Input.value.m31 = text
if (oldValue !== matrix4x4Input.value.m31)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m31)
}
StyledTextField {
id: m32Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m32
matrix4x4Input.value.m32 = text
if (oldValue !== matrix4x4Input.value.m32)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m32)
}
StyledTextField {
id: m33Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m33
matrix4x4Input.value.m33 = text
if (oldValue !== matrix4x4Input.value.m33)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m33)
}
StyledTextField {
id: m34Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m34
matrix4x4Input.value.m34 = text
if (oldValue !== matrix4x4Input.value.m34)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m34)
}
}
RowLayout {
StyledTextField {
id: m41Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
enabled: !affine
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m41
matrix4x4Input.value.m41 = text
if (oldValue !== matrix4x4Input.value.m41)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m41)
}
StyledTextField {
id: m42Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
enabled: !affine
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m42
matrix4x4Input.value.m42 = text
if (oldValue !== matrix4x4Input.value.m42)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m42)
}
StyledTextField {
id: m43Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
enabled: !affine
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m43
matrix4x4Input.value.m43 = text
if (oldValue !== matrix4x4Input.value.m43)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m43)
}
StyledTextField {
id: m44Field
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: doubleValidator
implicitWidth: cellwidth
enabled: !affine
selectByMouse: true
onEditingFinished: {
if (text !== "") {
var oldValue = matrix4x4Input.value.m44
matrix4x4Input.value.m44 = text
if (oldValue !== matrix4x4Input.value.m44)
valueEdited()
}
}
Component.onCompleted: text = roundNumber(matrix4x4Input.value.m44)
}
}
}
}
}
|