Commit d522d0de authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Timeline: don't allow moving a keyframe at same pos as another one.

Related to #686
parent e0ccc89e
......@@ -175,6 +175,8 @@ bool KeyframeModel::moveKeyframe(GenTime oldPos, GenTime pos, QVariant newVal, F
return updateKeyframe(pos, result);
}
if (oldPos != pos && hasKeyframe(pos)) {
// Move rejected, another keyframe is here
qDebug()<<"==== MOVE REJECTED!!";
return false;
}
KeyframeType oldType = m_keyframeList[oldPos].first;
......
......@@ -1276,3 +1276,18 @@ bool EffectStackModel::updateKeyFrame(int oldFrame, int newFrame, QVariant norma
}
return listModel->updateKeyframe(GenTime(oldFrame, pCore->getCurrentFps()), GenTime(newFrame, pCore->getCurrentFps()), std::move(normalisedVal));
}
bool EffectStackModel::hasKeyFrame(int frame)
{
if (rootItem->childCount() == 0) return false;
int ix = 0;
if (auto ptr = m_masterService.lock()) {
ix = ptr->get_int("kdenlive:activeeffect");
}
if (ix < 0) {
return false;
}
std::shared_ptr<EffectItemModel> sourceEffect = std::static_pointer_cast<EffectItemModel>(rootItem->child(ix));
std::shared_ptr<KeyframeModelList> listModel = sourceEffect->getKeyframeModel();
return listModel->hasKeyframe(frame);
}
......@@ -109,6 +109,8 @@ public:
bool removeKeyFrame(int frame);
/** Update a keyframe in all model parameters (with value updated only in first parameter)*/
bool updateKeyFrame(int oldFrame, int newFrame, QVariant normalisedVal);
/** Returns true if active effect has a keyframe at pos p*/
bool hasKeyFrame(int frame);
/** Remove unwanted fade effects, mostly after a cut operation */
void cleanFadeEffects(bool outEffects, Fun &undo, Fun &redo);
......
......@@ -148,7 +148,7 @@ Rectangle
if (newPos < 1) {
newPos = 1
}
if (newPos != dragPos) {
if (newPos != dragPos && (newPos == 0 || !timeline.hasKeyframeAt(masterObject.clipId, frame + newPos))) {
dragPos = newPos
parent.x = newPos * timeScale
keyframecanvas.requestPaint()
......@@ -222,7 +222,7 @@ Rectangle
if (frame + newPos <= inPoint) {
newPos = inPoint + 1 - frame
}
if (newPos != dragPos) {
if (newPos != dragPos && (newPos == 0 || !timeline.hasKeyframeAt(masterObject.clipId, frame + newPos))) {
dragPos = newPos
parent.x = newPos * timeScale - root.baseUnit / 2
keyframecanvas.requestPaint()
......
......@@ -3248,6 +3248,18 @@ void TimelineController::updateEffectKeyframe(int cid, int oldFrame, int newFram
}
}
bool TimelineController::hasKeyframeAt(int cid, int frame)
{
if (m_model->isClip(cid)) {
std::shared_ptr<EffectStackModel> destStack = m_model->getClipEffectStackModel(cid);
return destStack->hasKeyFrame(frame);
} else if (m_model->isComposition(cid)) {
std::shared_ptr<KeyframeModelList> listModel = m_model->m_allCompositions[cid]->getKeyframeModel();
return listModel->hasKeyframe(frame);
}
return false;
}
bool TimelineController::darkBackground() const
{
KColorScheme scheme(QApplication::palette().currentColorGroup());
......
......@@ -399,6 +399,7 @@ public:
Q_INVOKABLE void addEffectKeyframe(int cid, int frame, double val);
Q_INVOKABLE void removeEffectKeyframe(int cid, int frame);
Q_INVOKABLE void updateEffectKeyframe(int cid, int oldFrame, int newFrame, const QVariant &normalizedValue = QVariant());
Q_INVOKABLE bool hasKeyframeAt(int cid, int frame);
/** @brief Make current timeline track active/inactive*/
Q_INVOKABLE void switchTrackActive(int trackId = -1);
......
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