1/* 2 * Copyright (c) 2019-2021 Meltytech, LLC 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18import QtQuick 2.12 19import QtQuick.Controls 2.12 20import QtQuick.Layouts 1.12 21import Shotcut.Controls 1.0 as Shotcut 22 23Shotcut.KeyframableFilter { 24 property string phaseincrement: '0' 25 property string zoomrate: '1' 26 property double phaseincrementDefault: 0.02 27 property double zoomrateDefault: 0.20 28 29 keyframableParameters: [phaseincrement, zoomrate] 30 startValues: [0.5, 0.5] 31 middleValues: [phaseincrementDefault, zoomrateDefault] 32 endValues: [0.5, 0.5] 33 34 width: 350 35 height: 100 36 37 Component.onCompleted: { 38 if (filter.isNew) { 39 filter.set(phaseincrement, phaseincrementDefault) 40 filter.set(zoomrate, zoomrateDefault) 41 filter.savePreset(preset.parameters) 42 } 43 setControls() 44 } 45 46 function setControls() { 47 var position = getPosition() 48 blockUpdate = true 49 phaseincrementSlider.value = filter.getDouble(phaseincrement, position) * phaseincrementSlider.maximumValue 50 phaseKeyframesButton.checked = filter.animateIn <= 0 && filter.animateOut <= 0 && filter.keyframeCount(phaseincrement) > 0 51 zoomrateSlider.value = filter.getDouble(zoomrate, position) * zoomrateSlider.maximumValue 52 zoomKeyframesButton.checked = filter.animateIn <= 0 && filter.animateOut <= 0 && filter.keyframeCount(zoomrate) > 0 53 blockUpdate = false 54 enableControls(isSimpleKeyframesActive()) 55 } 56 57 function enableControls(enabled) { 58 phaseincrementSlider.enabled = zoomrateSlider.enabled = enabled 59 } 60 61 function updateSimpleKeyframes() { 62 updateFilter(phaseincrement, phaseincrementSlider.value / phaseincrementSlider.maximumValue, phaseKeyframesButton) 63 updateFilter(zoomrate, zoomrateSlider.value / zoomrateSlider.maximumValue, zoomKeyframesButton) 64 } 65 66 GridLayout { 67 anchors.fill: parent 68 anchors.margins: 8 69 columns: 4 70 71 Label { 72 text: qsTr('Preset') 73 Layout.alignment: Qt.AlignRight 74 } 75 Shotcut.Preset { 76 id: preset 77 parameters: [phaseincrement, zoomrate] 78 Layout.columnSpan: 3 79 onBeforePresetLoaded: { 80 filter.resetProperty(phaseincrement) 81 filter.resetProperty(zoomrate) 82 } 83 onPresetSelected: { 84 setControls() 85 initializeSimpleKeyframes() 86 } 87 } 88 89 Label { 90 text: qsTr('Speed') 91 Layout.alignment: Qt.AlignRight 92 } 93 Shotcut.SliderSpinner { 94 id: phaseincrementSlider 95 minimumValue: 0.0 96 maximumValue: 100 97 stepSize: 0.01 98 decimals: 2 99 suffix: ' %' 100 onValueChanged: updateFilter(phaseincrement, phaseincrementSlider.value / phaseincrementSlider.maximumValue, phaseKeyframesButton, getPosition()) 101 } 102 Shotcut.UndoButton { 103 onClicked: phaseincrementSlider.value = phaseincrementDefault * phaseincrementSlider.maximumValue 104 } 105 Shotcut.KeyframesButton { 106 id: phaseKeyframesButton 107 onToggled: { 108 enableControls(true) 109 toggleKeyframes(checked, phaseincrement, phaseincrementSlider.value / phaseincrementSlider.maximumValue) 110 } 111 } 112 113 Label { 114 text: qsTr('Zoom') 115 Layout.alignment: Qt.AlignRight 116 } 117 Shotcut.SliderSpinner { 118 id: zoomrateSlider 119 minimumValue: 0.0 120 maximumValue: 100 121 stepSize: 0.01 122 decimals: 2 123 suffix: ' %' 124 onValueChanged: updateFilter(zoomrate, zoomrateSlider.value / zoomrateSlider.maximumValue, zoomKeyframesButton, getPosition()) 125 } 126 Shotcut.UndoButton { 127 onClicked: zoomrateSlider.value = zoomrateDefault * zoomrateSlider.maximumValue 128 } 129 Shotcut.KeyframesButton { 130 id: zoomKeyframesButton 131 onToggled: { 132 enableControls(true) 133 toggleKeyframes(checked, zoomrate, zoomrateSlider.value / zoomrateSlider.maximumValue) 134 } 135 } 136 137 Item { 138 Layout.fillHeight: true 139 } 140 } 141 142 Connections { 143 target: filter 144 onInChanged: updateSimpleKeyframes() 145 onOutChanged: updateSimpleKeyframes() 146 onAnimateInChanged: updateSimpleKeyframes() 147 onAnimateOutChanged: updateSimpleKeyframes() 148 } 149 150 Connections { 151 target: producer 152 onPositionChanged: setControls() 153 } 154} 155