When dragging a clip in insert mode, don't allow leaving empty space in timeline.

Related to #673
parent 367d056f
......@@ -727,6 +727,14 @@ QVariantList TimelineModel::suggestItemMove(int itemId, int trackId, int positio
return suggestCompositionMove(itemId, trackId, position, cursorPosition, snapDistance);
}
int TimelineModel::adjustFrame(int frame, int trackId)
{
if (m_editMode == TimelineMode::InsertEdit && isTrack(trackId)) {
frame = qMin(frame, getTrackById_const(trackId)->trackDuration());
}
return frame;
}
QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance, bool moveMirrorTracks)
{
QWriteLocker locker(&m_lock);
......@@ -744,6 +752,14 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
TRACE_RES(position);
return {position, trackId};
}
if (m_editMode == TimelineMode::InsertEdit) {
int maxPos = getTrackById_const(trackId)->trackDuration();
if (m_allClips[clipId]->getCurrentTrackId() == trackId) {
maxPos -= m_allClips[clipId]->getPlaytime();
}
qDebug()<<"=== TRYING CLIP MOVE AT: "<<position<<", MAX TK: "<<getTrackById_const(trackId)->trackDuration();
position = qMin(position, maxPos);
}
bool after = position > currentPos;
if (snapDistance > 0) {
std::vector<int> ignored_pts;
......
......@@ -389,6 +389,9 @@ public:
Q_INVOKABLE QVariantList suggestItemMove(int itemId, int trackId, int position, int cursorPosition, int snapDistance = -1);
Q_INVOKABLE QVariantList suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance = -1, bool moveMirrorTracks = true);
Q_INVOKABLE QVariantList suggestCompositionMove(int compoId, int trackId, int position, int cursorPosition, int snapDistance = -1);
/** @brief returns the frame pos adjusted to edit mode
*/
Q_INVOKABLE int adjustFrame(int frame, int trackId);
/* @brief Request clip insertion at given position. This action is undoable
Returns true on success. If it fails, nothing is modified.
......
......@@ -514,7 +514,8 @@ Rectangle {
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
} else {
// we want insert/overwrite mode, make a fake insert at end of timeline, then move to position
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, timeline.fullDuration, clipBeingDroppedData)
frame = controller.adjustFrame(frame, timeline.activeTrack)
clipBeingDroppedId = insertAndMaybeGroup(timeline.activeTrack, frame, clipBeingDroppedData)
if (clipBeingDroppedId > -1) {
var moveData = controller.suggestClipMove(clipBeingDroppedId, timeline.activeTrack, frame, root.consumerPosition, root.snapping)
fakeFrame = moveData[0]
......
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