diff --git a/src/models/keyframesmodel.cpp b/src/models/keyframesmodel.cpp index 07aa7c16cd..12b4db973b 100644 --- a/src/models/keyframesmodel.cpp +++ b/src/models/keyframesmodel.cpp @@ -484,6 +484,19 @@ void KeyframesModel::addKeyframe(int parameterIndex, int position) emit keyframeAdded(name, position); } } else { + // Strings and color values + auto value = m_filter->get(name, position); + Mlt::Animation anim = m_filter->getAnimation(name); + if (anim.is_valid() && !anim.is_key(position)) { + mlt_keyframe_type keyframeType = m_filter->getKeyframeType(anim, position, mlt_keyframe_type(-1)); + m_filter->blockSignals(true); + m_filter->set(name, value, position, keyframeType); + for (auto &key : parameter->gangedProperties()) { + value = m_filter->get(key, position); + m_filter->set(key, value, position, keyframeType); + } + m_filter->blockSignals(false); + } emit keyframeAdded(name, position); } onFilterChanged(name); diff --git a/src/qml/modules/Shotcut/Controls/ColorPicker.qml b/src/qml/modules/Shotcut/Controls/ColorPicker.qml index 859e70dedc..17071d4ce5 100644 --- a/src/qml/modules/Shotcut/Controls/ColorPicker.qml +++ b/src/qml/modules/Shotcut/Controls/ColorPicker.qml @@ -20,7 +20,7 @@ import QtQuick.Layouts import Shotcut.Controls as Shotcut RowLayout { - property string value: "white" + property color value: "white" property bool alpha: false property alias eyedropper: pickerButton.visible diff --git a/src/qmltypes/qmlfilter.cpp b/src/qmltypes/qmlfilter.cpp index d745c94e1e..500fbf88f4 100644 --- a/src/qmltypes/qmlfilter.cpp +++ b/src/qmltypes/qmlfilter.cpp @@ -78,6 +78,18 @@ QString QmlFilter::get(QString name, int position) } } +QColor QmlFilter::getColor(QString name, int position) +{ + mlt_color color = {0, 0, 0, 0}; + if (m_service.is_valid()) { + if (position < 0) + color = m_service.get_color(qUtf8Printable(name)); + else + color = m_service.anim_get_color(qUtf8Printable(name), position, duration()); + } + return QColor(color.r, color.g, color.b, color.a); +} + double QmlFilter::getDouble(QString name, int position) { if (m_service.is_valid()) { @@ -175,6 +187,28 @@ void QmlFilter::set(QString name, QString value, int position) } } +void QmlFilter::set(QString name, QColor value, int position, mlt_keyframe_type keyframeType) +{ + if (!m_service.is_valid()) return; + if (position < 0) { + auto mltColor = m_service.get_color(qUtf8Printable(name)); + if (!m_service.get(qUtf8Printable(name)) + || value != QColor(mltColor.r, mltColor.g, mltColor.b, mltColor.a)) { + m_service.set(qUtf8Printable(name), Util::mltColorFromQColor(value)); + emit changed(name); + } + } else { + // Only set an animation keyframe if it does not already exist with the same value. + Mlt::Animation animation(m_service.get_animation(qUtf8Printable(name))); + auto mltColor = m_service.anim_get_color(qUtf8Printable(name), position, duration()); + if (!animation.is_valid() || !animation.is_key(position) + || value != QColor(mltColor.r, mltColor.g, mltColor.b, mltColor.a)) { + m_service.anim_set(qUtf8Printable(name), Util::mltColorFromQColor(value), position, duration()); + emit changed(name); + } + } +} + void QmlFilter::set(QString name, double value, int position, mlt_keyframe_type keyframeType) { if (!m_service.is_valid()) return; diff --git a/src/qmltypes/qmlfilter.h b/src/qmltypes/qmlfilter.h index 0097576a93..66a6123fd5 100644 --- a/src/qmltypes/qmlfilter.h +++ b/src/qmltypes/qmlfilter.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -76,11 +77,14 @@ class QmlFilter : public QObject } Q_INVOKABLE QString get(QString name, int position = -1); + Q_INVOKABLE QColor getColor(QString name, int position = -1); Q_INVOKABLE double getDouble(QString name, int position = -1); Q_INVOKABLE QRectF getRect(QString name, int position = -1); Q_INVOKABLE void removeRectPercents(QString name); Q_INVOKABLE QStringList getGradient(QString name); Q_INVOKABLE void set(QString name, QString value, int position = -1); + Q_INVOKABLE void set(QString name, QColor value, + int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1)); Q_INVOKABLE void set(QString name, double value, int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1)); Q_INVOKABLE void set(QString name, int value, diff --git a/src/util.cpp b/src/util.cpp index 48a1611022..acb4c49c1b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -823,3 +823,13 @@ QString Util::getConversionAdvice(Mlt::Producer *producer) } return advice; } + +mlt_color Util::mltColorFromQColor(const QColor &color) +{ + return mlt_color { + static_cast(color.red()), + static_cast(color.green()), + static_cast(color.blue()), + static_cast(color.alpha()) + }; +} diff --git a/src/util.h b/src/util.h index 6b1e24b861..33c2e97f72 100644 --- a/src/util.h +++ b/src/util.h @@ -77,6 +77,7 @@ class Util static QString trcString(int trc); static bool trcIsCompatible(int trc); static QString getConversionAdvice(Mlt::Producer *producer); + static mlt_color mltColorFromQColor(const QColor &color); }; #endif // UTIL_H