Keyframes can now be edited in timeline through keyboard: Click on a keyframe

Then Alt+Left/Right selects previous/next keyframe.
Left/Right moves the current keyframe
Plus/Minus increase/decrease current keyframe value
parent 7091e238
......@@ -292,6 +292,31 @@ bool KeyframeModel::updateKeyframe(GenTime pos, QVariant value, Fun &undo, Fun &
return res;
}
bool KeyframeModel::updateKeyframe(int pos, double newVal)
{
GenTime Pos(pos, pCore->getCurrentFps());
if (auto ptr = m_model.lock()) {
double min = ptr->data(m_index, AssetParameterModel::MinRole).toDouble();
double max = ptr->data(m_index, AssetParameterModel::MaxRole).toDouble();
double factor = ptr->data(m_index, AssetParameterModel::FactorRole).toDouble();
double norm = ptr->data(m_index, AssetParameterModel::DefaultRole).toDouble();
int logRole = ptr->data(m_index, AssetParameterModel::ScaleRole).toInt();
double realValue;
if (logRole == -1) {
// Logarythmic scale for lower than norm values
if (newVal >= 0.5) {
realValue = norm + (2 * (newVal - 0.5) * (max / factor - norm));
} else {
realValue = norm - pow(2 * (0.5 - newVal), 10.0 / 6) * (norm - min / factor);
}
} else {
realValue = (newVal * (max - min) + min) / factor;
}
return updateKeyframe(Pos, realValue);
}
return false;
}
bool KeyframeModel::updateKeyframe(GenTime pos, QVariant value)
{
QWriteLocker locker(&m_lock);
......
......@@ -103,6 +103,7 @@ public:
@param old is the position of the keyframe
@param value is the new value of the param
*/
Q_INVOKABLE bool updateKeyframe(int pos, double newVal);
bool updateKeyframe(GenTime pos, QVariant value);
bool updateKeyframeType(GenTime pos, int type, Fun &undo, Fun &redo);
bool updateKeyframe(GenTime pos, QVariant value, Fun &undo, Fun &redo);
......
......@@ -288,9 +288,9 @@ Rectangle {
onDoubleClicked: {
if (showKeyframes) {
// Add new keyframe
var xPos = mouse.x / timeline.scaleFactor
var xPos = Math.round(mouse.x / timeline.scaleFactor)
var yPos = (clipRoot.height - mouse.y) / clipRoot.height
keyframeModel.addKeyframe(xPos, yPos)
keyframeModel.addKeyframe(xPos + clipRoot.inPoint, yPos)
} else {
timeline.position = clipRoot.x / timeline.scaleFactor
}
......
......@@ -48,30 +48,34 @@ Rectangle
if (activeFrame < 0) {
activeFrame = 0
} else {
keyframeModel.moveKeyframe(oldFrame + inPoint, activeFrame + inPoint, true)
keyframeModel.moveKeyframe(oldFrame, activeFrame, true)
}
}
event.accepted = true
}
if (event.key == Qt.Key_Right) {
else if (event.key == Qt.Key_Right) {
if (event.modifiers & Qt.AltModifier) {
activeFrame = keyframes.itemAt(Math.min(keyframes.count - 1, ++activeIndex)).frame
} else {
var oldFrame = activeFrame
activeFrame += 1
keyframeModel.moveKeyframe(oldFrame + inPoint, activeFrame + inPoint, true)
keyframeModel.moveKeyframe(oldFrame + inPoint, activeFrame, true)
}
event.accepted = true
}
if (event.key == Qt.Key_Return || event.key == Qt.Key_Escape) {
focus = false
else if (event.key == Qt.Key_Return || event.key == Qt.Key_Escape) {
keyframeContainer.focus = false
event.accepted = true
}
if (event.key == Qt.Key_Tab) {
activeFrame = keyframes.itemAt(++activeIndex).frame
console.log('------------------------- TAB: ', activeFrame)
if (event.key == Qt.Key_Plus) {
var newVal = Math.min(keyframes.itemAt(activeIndex).value / parent.height + .05, 1)
keyframeModel.updateKeyframe(activeFrame, newVal)
event.accepted = true
}
else if (event.key == Qt.Key_Minus) {
var newVal = Math.max(keyframes.itemAt(activeIndex).value / parent.height - .05, 0)
keyframeModel.updateKeyframe(activeFrame, newVal)
event.accepted = true
focus = true
}
}
Repeater {
......
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