Skip to content

Commit

Permalink
add keyframes for Text: Rich > Background color
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Aug 30, 2023
1 parent 47bba2c commit 1f4fef4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/qml/filters/richtext/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Metadata {
name: qsTr('Position / Size')
property: 'geometry'
isRectangle: true
},
Parameter {
name: qsTr('Background color')
property: 'bgcolour'
isCurve: false
}
]
}
Expand Down
64 changes: 47 additions & 17 deletions src/qml/filters/richtext/ui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ Item {
property string sizeProperty: '_shotcut:size'
property string specialPresetProperty: 'shotcut:preset'
property rect defaultRect: Qt.rect(Math.round(profile.width * 0.1), Math.round(profile.height * 0.1), Math.round(profile.width * 0.8), Math.round(profile.height * 0.8))
property bool blockUpdate: true

function getPosition() {
return Math.max(producer.position - (filter.in - producer.in), 0);
}

function updateFilter(position) {
function updateFilterRect(position) {
if (position !== null) {
filter.blockSignals = true;
if (position <= 0 && filter.animateIn > 0)
Expand Down Expand Up @@ -65,7 +66,6 @@ Item {
}

function setControls() {
bgColor.value = filter.get('bgcolour');
switch (filter.get('overflow-y')) {
case '':
automaticOverflowRadioButton.checked = true;
Expand Down Expand Up @@ -95,12 +95,16 @@ Item {
rectW.value = filterRect.width;
rectH.value = filterRect.height;
}
blockUpdate = true;
bgColor.value = filter.getColor('bgcolour', position);
blockUpdate = false;
var enabled = position <= 0 || (position >= (filter.animateIn - 1) && position <= (filter.duration - filter.animateOut)) || position >= (filter.duration - 1);
rectX.enabled = enabled;
rectY.enabled = enabled;
rectW.enabled = enabled;
rectH.enabled = enabled;
positionKeyframesButton.checked = filter.keyframeCount(rectProperty) > 0 && filter.animateIn <= 0 && filter.animateOut <= 0;
bgcolorKeyframesButton.checked = filter.keyframeCount('bgcolour') > 0;
var document = getTextDimensions();
if (parseInt(sizeW.text) !== Math.round(document.width) || parseInt(sizeH.text) !== Math.round(document.height)) {
sizeW.text = Math.round(document.width);
Expand Down Expand Up @@ -132,6 +136,30 @@ Item {
}
}

function updateFilter(parameter, value, button, position) {
if (blockUpdate)
return;
if (button.checked && position !== null) {
filter.set(parameter, value, position);
} else if (position !== null) {
filter.set(parameter, value);
}
}

function toggleKeyframes(isEnabled, parameter, value) {
if (isEnabled) {
blockUpdate = true;
filter.clearSimpleAnimation(parameter);
blockUpdate = false;
// Set this keyframe value.
filter.set(parameter, value, getPosition());
} else {
// Remove keyframes and set the parameter.
filter.resetProperty(parameter);
filter.set(parameter, value);
}
}

function applyTracking(motionTrackerRow, operation, frame) {
motionTrackerModel.reset(filter, rectProperty, motionTrackerRow);
const data = motionTrackerModel.trackingData(motionTrackerRow);
Expand Down Expand Up @@ -271,6 +299,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onBeforePresetLoaded: {
filter.resetProperty(rectProperty);
filter.resetProperty(specialPresetProperty);
filter.resetProperty('bgcolour');
}
onPresetSelected: {
handleSpecialPreset();
Expand Down Expand Up @@ -314,7 +343,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onValueModified: {
if (Math.abs(filterRect.x - value) > 1) {
filterRect.x = value;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}
}
Expand All @@ -337,7 +366,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onValueModified: {
if (Math.abs(filterRect.y - value) > 1) {
filterRect.y = value;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}
}
Expand All @@ -347,7 +376,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onClicked: {
filterRect.x = rectX.value = defaultRect.x;
filterRect.y = rectY.value = defaultRect.y;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}

Expand Down Expand Up @@ -391,7 +420,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onValueModified: {
if (Math.abs(filterRect.width - value) > 1) {
filterRect.width = value;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}
}
Expand All @@ -414,7 +443,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onValueModified: {
if (Math.abs(filterRect.height - value) > 1) {
filterRect.height = value;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}
}
Expand All @@ -424,7 +453,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
onClicked: {
filterRect.width = rectW.value = defaultRect.width;
filterRect.height = rectH.value = defaultRect.height;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}

Expand Down Expand Up @@ -503,15 +532,16 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
Layout.columnSpan: 3
eyedropper: false
alpha: true
onValueChanged: filter.set('bgcolour', value)
onValueChanged: updateFilter('bgcolour', value, bgcolorKeyframesButton, getPosition())
}

Shotcut.UndoButton {
onClicked: bgColor.value = '#00000000'
onClicked: bgColor.value = Qt.rgba(0, 0, 0, 0)
}

Item {
Layout.fillWidth: true
Shotcut.KeyframesButton {
id: bgcolorKeyframesButton
onToggled: toggleKeyframes(checked, 'bgcolour', bgColor.value)
}

Label {
Expand Down Expand Up @@ -590,7 +620,7 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
rectY.value = filterRect.y;
rectW.value = filterRect.width;
rectH.value = filterRect.height;
updateFilter(getPosition());
updateFilterRect(getPosition());
}
}

Expand All @@ -600,19 +630,19 @@ body { font-family:%1; font-size:72pt; font-weight:600; font-style:normal; color
}

function onInChanged() {
updateFilter(null);
updateFilterRect(null);
}

function onOutChanged() {
updateFilter(null);
updateFilterRect(null);
}

function onAnimateInChanged() {
updateFilter(null);
updateFilterRect(null);
}

function onAnimateOutChanged() {
updateFilter(null);
updateFilterRect(null);
}

target: filter
Expand Down
5 changes: 3 additions & 2 deletions src/qml/filters/richtext/vui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Shotcut.VuiBase {
Component.onCompleted: {
setRectangleControl();
filter.set('_hide', 1);
background.color = filter.get('bgcolour');
background.color = filter.getColor('bgcolour', getPosition());
setTextAreaHeight();
textArea.text = filter.get('html');
fontSizeSpinBox.value = document.fontSize;
Expand Down Expand Up @@ -854,7 +854,7 @@ Shotcut.VuiBase {
function onChanged() {
setRectangleControl();
videoItem.enabled = filter.get('disable') !== '1';
background.color = filter.get('bgcolour');
background.color = filter.getColor('bgcolour', getPosition());
setTextAreaHeight();
}

Expand All @@ -864,6 +864,7 @@ Shotcut.VuiBase {
Connections {
function onPositionChanged() {
setRectangleControl();
background.color = filter.getColor('bgcolour', getPosition());
}

target: producer
Expand Down
6 changes: 3 additions & 3 deletions src/qml/modules/Shotcut/Controls/TextFilterUi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ GridLayout {
rectH.enabled = enabled;
fgColor.enabled = enabled;
positionKeyframesButton.checked = filter.keyframeCount(rectProperty) > 0 && filter.animateIn <= 0 && filter.animateOut <= 0;
fgcolorKeyframesButton.checked = filter.keyframeCount('fgcolour') > 0 && filter.animateIn <= 0 && filter.animateOut <= 0;
olcolorKeyframesButton.checked = filter.keyframeCount('olcolour') > 0 && filter.animateIn <= 0 && filter.animateOut <= 0;
bgcolorKeyframesButton.checked = filter.keyframeCount('bgcolour') > 0 && filter.animateIn <= 0 && filter.animateOut <= 0;
fgcolorKeyframesButton.checked = filter.keyframeCount('fgcolour') > 0;
olcolorKeyframesButton.checked = filter.keyframeCount('olcolour') > 0;
bgcolorKeyframesButton.checked = filter.keyframeCount('bgcolour') > 0;
}

function resetColorKeyframes() {
Expand Down

0 comments on commit 1f4fef4

Please sign in to comment.