-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ui.qml
529 lines (511 loc) · 20.9 KB
/
ui.qml
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
/*
* Copyright (c) 2014-2019 Meltytech, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.0
import Shotcut.Controls 1.0
Item {
property var defaultParameters: ['lift_r', 'lift_g', 'lift_b', 'gamma_r', 'gamma_g', 'gamma_b', 'gain_r', 'gain_g', 'gain_b']
property double gammaFactor: 2.0
property double gainFactor: 4.0
property bool blockUpdate: true
width: 620
height: 350
Component.onCompleted: {
if (filter.isNew) {
// Set default parameter values
filter.set("lift_r", 0.0);
filter.set("lift_g", 0.0);
filter.set("lift_b", 0.0);
filter.set("gamma_r", 1.0);
filter.set("gamma_g", 1.0);
filter.set("gamma_b", 1.0);
filter.set("gain_r", 1.0);
filter.set("gain_g", 1.0);
filter.set("gain_b", 1.0);
filter.savePreset(defaultParameters)
}
loadValues()
}
function loadValues() {
var position = getPosition()
blockUpdate = true
// Force a color change to make sure the color wheel is updated.
liftRedSpinner.value = 1.0
gammaRedSpinner.value = 1.0
gainRedSpinner.value = 1.0
liftRedSpinner.value = filter.getDouble("lift_r", position) * 100.0
liftGreenSpinner.value = filter.getDouble("lift_g", position) * 100.0
liftBlueSpinner.value = filter.getDouble("lift_b", position) * 100.0
gammaRedSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gamma_r", position), gammaFactor))
gammaGreenSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gamma_g", position), gammaFactor))
gammaBlueSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gamma_b", position), gammaFactor))
gainRedSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gain_r", position), gainFactor))
gainGreenSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gain_g", position), gainFactor))
gainBlueSpinner.value = wheelToSpinner(scaleValueToWheel(filter.getDouble("gain_b", position), gainFactor))
blockUpdate = false
}
function getPosition() {
return Math.max(producer.position - (filter.in - producer.in), 0)
}
function scaleWheelToValue(w, f) {
// The color wheel value (w) range is [0.0 - 1.0]. For the gamma and gain
// gain parameters, we want to scale that to [0.0 - f] where (f) is the
// maximum scaling factor. The middle of the wheel (0.5) needs to map to
// a filter value of 1.0 (no change). Since this could be a non-linear
// scaling, we use the quadratic equation:
// f(x) = ax**2 + bx + c
// With the following point mappings:
// f(0) = 0
// f(0.5) = 1
// f(1) = f (scaling factor)
// This reduces to:
// a = 2f - 4
// b = f - a
// c = 0
var a = (2*f) - 4
var b = f - a
return a * (w*w) + b*w
}
function scaleValueToWheel(v, f) {
// Do the opposite of scaleWheelToValue
var a = (2*f) - 4
var b = f - a
if (a == 0) {
// For a = 0, the function is linear
return v / f
} else {
// The solution to the quadratic formula reduces to:
return ((b*-1.0) + Math.sqrt((b*b) + (4*a*v))) / (2*a)
}
}
function wheelToSpinner(w) {
// Convert a wheel value [0.0 - 1.0] to a spinner value [-100.0 - 100.0]
return (w * 2.0 - 1.0) * 100.0
}
function spinnerToWheel(s) {
// Convert a spinner value [-100.0 - 100.0] to wheel value [0.0 - 1.0]
return (s / 100.0 + 1.0) / 2.0
}
GridLayout {
columns: 9
anchors.fill: parent
anchors.margins: 8
// Row 1
Label {
text: qsTr('Preset')
Layout.alignment: Qt.AlignRight
}
Preset {
Layout.columnSpan: 8
parameters: defaultParameters
onBeforePresetLoaded: {
filter.resetProperty('lift_r')
filter.resetProperty('lift_g')
filter.resetProperty('lift_b')
filter.resetProperty('gamma_r')
filter.resetProperty('gamma_g')
filter.resetProperty('gamma_b')
filter.resetProperty('gain_r')
filter.resetProperty('gain_g')
filter.resetProperty('gain_b')
}
onPresetSelected: {
loadValues()
}
}
// Row 2
Label { text: qsTr('Shadows (Lift)') }
UndoButton {
Layout.alignment: Qt.AlignRight
onClicked: {
// Force a color change to make sure the color wheel is updated.
liftRedSpinner.value = 1.0
liftRedSpinner.value = 0.0
liftGreenSpinner.value = 0.0
liftBlueSpinner.value = 0.0
}
}
KeyframesButton {
id: liftKeyframesButton
checked: filter.keyframeCount('lift_r') > 0
Layout.alignment: Qt.AlignLeft
onToggled: {
if (checked) {
filter.set('lift_r', liftwheel.redF * 2.0 - 1.0, getPosition())
filter.set('lift_g', liftwheel.greenF * 2.0 - 1.0, getPosition())
filter.set('lift_b', liftwheel.blueF * 2.0 - 1.0, getPosition())
} else {
filter.resetProperty('lift_r')
filter.resetProperty('lift_g')
filter.resetProperty('lift_b')
filter.set('lift_r', liftwheel.redF * 2.0 - 1.0)
filter.set('lift_g', liftwheel.greenF * 2.0 - 1.0)
filter.set('lift_b', liftwheel.blueF * 2.0 - 1.0)
}
}
}
Label { text: qsTr('Midtones (Gamma)') }
UndoButton {
Layout.alignment: Qt.AlignRight
onClicked: {
// Force a color change to make sure the color wheel is updated.
gammaRedSpinner.value = 100.0
gammaRedSpinner.value = 0.0
gammaGreenSpinner.value = 0.0
gammaBlueSpinner.value = 0.0
}
}
KeyframesButton {
id: gammaKeyframesButton
checked: filter.keyframeCount('gamma_r') > 0
Layout.alignment: Qt.AlignLeft
onToggled: {
if (checked) {
filter.set('gamma_r', scaleWheelToValue(gammawheel.redF, gammaFactor), getPosition())
filter.set('gamma_g', scaleWheelToValue(gammawheel.greenF, gammaFactor), getPosition())
filter.set('gamma_b', scaleWheelToValue(gammawheel.blueF, gammaFactor), getPosition())
} else {
filter.resetProperty('gamma_r')
filter.resetProperty('gamma_g')
filter.resetProperty('gamma_b')
filter.set('gamma_r', scaleWheelToValue(gammawheel.redF, gammaFactor))
filter.set('gamma_g', scaleWheelToValue(gammawheel.greenF, gammaFactor))
filter.set('gamma_b', scaleWheelToValue(gammawheel.blueF, gammaFactor))
}
}
}
Label { text: qsTr('Highlights (Gain)') }
UndoButton {
Layout.alignment: Qt.AlignRight
onClicked: {
// Force a color change to make sure the color wheel is updated.
gainRedSpinner.value = 100.0
gainRedSpinner.value = 0.0
gainGreenSpinner.value = 0.0
gainBlueSpinner.value = 0.0
}
}
KeyframesButton {
id: gainKeyframesButton
checked: filter.keyframeCount('gain_r') > 0
Layout.alignment: Qt.AlignLeft
onToggled: {
if (checked) {
filter.set('gain_r', scaleWheelToValue(gainwheel.redF, gainFactor), getPosition())
filter.set('gain_g', scaleWheelToValue(gainwheel.greenF, gainFactor), getPosition())
filter.set('gain_b', scaleWheelToValue(gainwheel.blueF, gainFactor), getPosition())
} else {
filter.resetProperty('gain_r')
filter.resetProperty('gain_g')
filter.resetProperty('gain_b')
filter.set('gain_r', scaleWheelToValue(gainwheel.redF, gainFactor))
filter.set('gain_g', scaleWheelToValue(gainwheel.greenF, gainFactor))
filter.set('gain_b', scaleWheelToValue(gainwheel.blueF, gainFactor))
}
}
}
// Row 3
ColorWheelItem {
id: liftwheel
Layout.columnSpan: 3
implicitWidth: parent.width / 3 - parent.columnSpacing
implicitHeight: implicitWidth / 1.1
Layout.alignment : Qt.AlignCenter | Qt.AlignTop
Layout.minimumHeight: 75
Layout.maximumHeight: 300
step: 0.0005
onColorChanged: {
if( liftRedSpinner.value != wheelToSpinner(liftwheel.redF) ) {
liftRedSpinner.value = wheelToSpinner(liftwheel.redF)
}
if( liftGreenSpinner.value != wheelToSpinner(liftwheel.greenF) ) {
liftGreenSpinner.value = wheelToSpinner(liftwheel.greenF)
}
if( liftBlueSpinner.value != wheelToSpinner(liftwheel.blueF) ) {
liftBlueSpinner.value = wheelToSpinner(liftwheel.blueF)
}
if (!blockUpdate) {
if (!liftKeyframesButton.checked) {
filter.resetProperty('lift_r')
filter.resetProperty('lift_g')
filter.resetProperty('lift_b')
filter.set('lift_r', liftwheel.redF * 2.0 - 1.0)
filter.set('lift_g', liftwheel.greenF * 2.0 - 1.0)
filter.set('lift_b', liftwheel.blueF * 2.0 - 1.0)
} else {
var position = getPosition()
filter.set('lift_r', liftwheel.redF * 2.0 - 1.0, position)
filter.set('lift_g', liftwheel.greenF * 2.0 - 1.0, position)
filter.set('lift_b', liftwheel.blueF * 2.0 - 1.0, position)
}
}
}
}
ColorWheelItem {
id: gammawheel
Layout.columnSpan: 3
implicitWidth: parent.width / 3 - parent.columnSpacing
implicitHeight: implicitWidth / 1.1
Layout.alignment : Qt.AlignCenter | Qt.AlignTop
Layout.minimumHeight: 75
Layout.maximumHeight: 300
step: 0.0005
onColorChanged: {
if( gammaRedSpinner.value != wheelToSpinner(gammawheel.redF) ) {
gammaRedSpinner.value = wheelToSpinner(gammawheel.redF)
}
if( gammaGreenSpinner.value != wheelToSpinner(gammawheel.greenF) ) {
gammaGreenSpinner.value = wheelToSpinner(gammawheel.greenF)
}
if( gammaBlueSpinner.value != wheelToSpinner(gammawheel.blueF) ) {
gammaBlueSpinner.value = wheelToSpinner(gammawheel.blueF)
}
if (!blockUpdate) {
if (!gammaKeyframesButton.checked) {
filter.resetProperty('gamma_r')
filter.resetProperty('gamma_g')
filter.resetProperty('gamma_b')
filter.set('gamma_r', scaleWheelToValue(gammawheel.redF, gammaFactor))
filter.set('gamma_g', scaleWheelToValue(gammawheel.greenF, gammaFactor))
filter.set('gamma_b', scaleWheelToValue(gammawheel.blueF, gammaFactor))
} else {
var position = getPosition()
filter.set('gamma_r', scaleWheelToValue(gammawheel.redF, gammaFactor), position)
filter.set('gamma_g', scaleWheelToValue(gammawheel.greenF, gammaFactor), position)
filter.set('gamma_b', scaleWheelToValue(gammawheel.blueF, gammaFactor), position)
}
}
}
}
ColorWheelItem {
id: gainwheel
Layout.columnSpan: 3
implicitWidth: parent.width / 3 - parent.columnSpacing
implicitHeight: implicitWidth / 1.1
Layout.alignment : Qt.AlignCenter | Qt.AlignTop
Layout.minimumHeight: 75
Layout.maximumHeight: 300
step: 0.0005
onColorChanged: {
if( gainRedSpinner.value != wheelToSpinner(gainwheel.redF) ) {
gainRedSpinner.value = wheelToSpinner(gainwheel.redF)
}
if( gainGreenSpinner.value != wheelToSpinner(gainwheel.greenF) ) {
gainGreenSpinner.value = wheelToSpinner(gainwheel.greenF)
}
if( gainBlueSpinner.value != wheelToSpinner(gainwheel.blueF) ) {
gainBlueSpinner.value = wheelToSpinner(gainwheel.blueF)
}
if (!blockUpdate) {
if (!gainKeyframesButton.checked) {
filter.resetProperty('gain_r')
filter.resetProperty('gain_g')
filter.resetProperty('gain_b')
filter.set('gain_r', scaleWheelToValue(gainwheel.redF, gainFactor))
filter.set('gain_g', scaleWheelToValue(gainwheel.greenF, gainFactor))
filter.set('gain_b', scaleWheelToValue(gainwheel.blueF, gainFactor))
} else {
var position = getPosition()
filter.set('gain_r', scaleWheelToValue(gainwheel.redF, gainFactor), position)
filter.set('gain_g', scaleWheelToValue(gainwheel.greenF, gainFactor), position)
filter.set('gain_b', scaleWheelToValue(gainwheel.blueF, gainFactor), position)
}
}
}
}
// Row 4
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'R' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: liftRedSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( liftwheel.redF != spinnerToWheel(value) ) {
liftwheel.redF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'R' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gammaRedSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gammawheel.redF != spinnerToWheel(value) ) {
gammawheel.redF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'R' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gainRedSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gainwheel.redF != spinnerToWheel(value) ) {
gainwheel.redF = spinnerToWheel(value)
}
}
}
}
// Row 5
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'G' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: liftGreenSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( liftwheel.greenF != spinnerToWheel(value) ) {
liftwheel.greenF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'G' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gammaGreenSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gammawheel.greenF != spinnerToWheel(value) ) {
gammawheel.greenF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'G' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gainGreenSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gainwheel.greenF != spinnerToWheel(value) ) {
gainwheel.greenF = spinnerToWheel(value)
}
}
}
}
// Row 6
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'B' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: liftBlueSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( liftwheel.blueF != spinnerToWheel(value) ) {
liftwheel.blueF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'B' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gammaBlueSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gammawheel.blueF != spinnerToWheel(value) ) {
gammawheel.blueF = spinnerToWheel(value)
}
}
}
}
RowLayout {
Layout.columnSpan: 3
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Label { text: 'B' }
SpinBox {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
id: gainBlueSpinner
minimumValue: -100
maximumValue: 100
decimals: 1
stepSize: 0.1
suffix: ' %'
onValueChanged: {
if( gainwheel.blueF != spinnerToWheel(value) ) {
gainwheel.blueF = spinnerToWheel(value)
}
}
}
}
Item { Layout.fillHeight: true }
}
Connections {
target: producer
onPositionChanged: loadValues()
}
}