Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

add keyframe by double click, correctly update on keyframe remove

parent 2ab2880a
......@@ -88,6 +88,19 @@ bool KeyframeModel::addKeyframe(GenTime pos, KeyframeType type, QVariant value,
return false;
}
bool KeyframeModel::addKeyframe(int frame, double normalizedValue)
{
if (auto ptr = m_model.lock()) {
Q_ASSERT(m_index.isValid());
double min = ptr->data(m_index, AssetParameterModel::MinRole).toDouble();
double max = ptr->data(m_index, AssetParameterModel::MaxRole).toDouble();
double realValue = normalizedValue * (max - min) + min;
//TODO: Use default configurable kf type
return addKeyframe(GenTime(frame, pCore->getCurrentFps()), KeyframeType::Linear, realValue);
}
return false;
}
bool KeyframeModel::addKeyframe(GenTime pos, KeyframeType type, QVariant value)
{
QWriteLocker locker(&m_lock);
......
......@@ -71,6 +71,7 @@ public:
@param type is the type of the keyframe.
*/
bool addKeyframe(GenTime pos, KeyframeType type, QVariant value);
Q_INVOKABLE bool addKeyframe(int frame, double normalizedValue);
protected:
/* @brief Same function but accumulates undo/redo
......
......@@ -58,6 +58,7 @@ Rectangle {
property double speed: 1.0
property color borderColor: 'black'
property bool reloadThumb: false
property alias kfrCount : keyframes.count
width : clipDuration * timeScale;
signal clicked(var clip, int shiftClick)
......@@ -75,6 +76,9 @@ Rectangle {
keyframecanvas.requestPaint()
}
onKfrCountChanged: {
keyframecanvas.requestPaint()
}
onClipDurationChanged: {
width = clipDuration * timeScale;
}
......@@ -229,7 +233,16 @@ Rectangle {
menu.show()
}
}
onDoubleClicked: timeline.position = clipRoot.x / timeline.scaleFactor
onDoubleClicked: {
if (showKeyframes) {
// Add new keyframe
var xPos = mouse.x / timeline.scaleFactor
var yPos = (clipRoot.height - mouse.y) / clipRoot.height
keyframeModel.addKeyframe(xPos, yPos)
} else {
timeline.position = clipRoot.x / timeline.scaleFactor
}
}
onWheel: zoomByWheel(wheel)
}
......@@ -432,41 +445,42 @@ Rectangle {
}
onPaint: {
context.beginPath()
context.fillStyle = Qt.rgba(0,0,0.8, 0.4);
//context.moveTo(0, parent.height)
paths = []
var xpos
var ypos
for(var i = 0; i < keyframes.count; i++)
{
xpos = keyframes.itemAt(i).x
if (type == 1) {
// discrete
// linear
paths.push(compline.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
if (keyframes.count == 0) {
return
}
ypos = parent.height - keyframes.itemAt(i).height
var type = keyframes.itemAt(i).type
if (type < 2) {
// linear
paths.push(compline.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
} else if (type == 2) {
// curve
paths.push(comp.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
context.beginPath()
context.fillStyle = Qt.rgba(0,0,0.8, 0.4);
paths = []
var xpos
var ypos
for(var i = 0; i < keyframes.count; i++)
{
xpos = keyframes.itemAt(i).x
if (type == 1) {
// discrete
paths.push(compline.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
}
ypos = parent.height - keyframes.itemAt(i).height
var type = keyframes.itemAt(i).type
if (type < 2) {
// linear
paths.push(compline.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
} else if (type == 2) {
// curve
paths.push(comp.createObject(keyframecanvas, {"x": xpos, "y": ypos} ))
}
}
paths.push(compline.createObject(keyframecanvas, {"x": parent.width, "y": ypos} ))
paths.push(compline.createObject(keyframecanvas, {"x": parent.width, "y": parent.height} ))
myPath.pathElements = paths
context.clearRect(0,0, width, height);
context.path = myPath;
context.closePath()
context.fill()
}
paths.push(compline.createObject(keyframecanvas, {"x": parent.width, "y": ypos} ))
paths.push(compline.createObject(keyframecanvas, {"x": parent.width, "y": parent.height} ))
myPath.pathElements = paths
context.clearRect(0,0, width, height);
context.path = myPath;
context.closePath()
context.fill()
}
}
}
}
states: [
State {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment