From 0f144df5e3474b9cca497f7f140c1f41ef76020d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Wed, 23 Sep 2020 22:31:19 +0200 Subject: [PATCH] Ensure a mixed clip cannot be moved further than its counterpart mix clip --- src/timeline2/model/timelinemodel.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/timeline2/model/timelinemodel.cpp b/src/timeline2/model/timelinemodel.cpp index 6d0bd0b0e..11805c492 100644 --- a/src/timeline2/model/timelinemodel.cpp +++ b/src/timeline2/model/timelinemodel.cpp @@ -659,7 +659,7 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool return true; }; if (old_trackId == trackId) { - // We are moving a group on same track + // We are moving a clip on same track if (finalMove && position >= mixData.first.firstClipInOut.second) { int subPlaylist = m_allClips[clipId]->getSubPlaylistIndex(); update_playlist = [this, clipId, subPlaylist]() { @@ -1139,6 +1139,27 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio position = snapped; } } + if (sourceTrackId == trackId) { + // Same track move, check if there is a mix and limit move + std::pair mixData = getTrackById_const(trackId)->getMixInfo(clipId); + if (mixData.first.firstClipId > -1) { + // Clip has start mix + int clipDuration = m_allClips[clipId]->getPlaytime(); + // ensure we don't move before first clip + position = qMax(position, mixData.first.firstClipInOut.first); + if (position + clipDuration <= mixData.first.firstClipInOut.second) { + position = mixData.first.firstClipInOut.second - clipDuration + 2; + } + } + if (mixData.second.firstClipId > -1) { + // Clip has end mix + int clipDuration = m_allClips[clipId]->getPlaytime(); + position = qMin(position, mixData.second.secondClipInOut.first); + if (position + clipDuration >= mixData.second.secondClipInOut.second) { + position = mixData.second.secondClipInOut.second - clipDuration - 2; + } + } + } // we check if move is possible bool possible = (m_editMode == TimelineMode::NormalEdit) ? requestClipMove(clipId, trackId, position, moveMirrorTracks, true, false, false) : requestFakeClipMove(clipId, trackId, position, true, false, false); -- GitLab