Lift previous clip on insert drag.

Related to #673
parent 787f822c
Pipeline #20468 passed with stage
in 9 minutes and 22 seconds
......@@ -386,7 +386,7 @@ bool TimelineFunctions::extractZone(const std::shared_ptr<TimelineItemModel> &ti
result = result && TimelineFunctions::liftZone(timeline, trackId, zone, undo, redo);
}
if (result && !liftOnly) {
result = TimelineFunctions::removeSpace(timeline, -1, zone, undo, redo, tracks);
result = TimelineFunctions::removeSpace(timeline, zone, undo, redo, tracks);
}
pCore->pushUndo(undo, redo, liftOnly ? i18n("Lift zone") : i18n("Extract zone"));
return result;
......@@ -501,18 +501,24 @@ bool TimelineFunctions::liftZone(const std::shared_ptr<TimelineItemModel> &timel
return true;
}
bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo, QVector<int> allowedTracks)
bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, QVector<int> allowedTracks, bool useTargets)
{
Q_UNUSED(trackId)
std::unordered_set<int> clips;
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
std::unordered_set<int> subs = timeline->getItemsInRange(target_track, zone.y() - 1, -1, true);
if (useTargets) {
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
std::unordered_set<int> subs = timeline->getItemsInRange(target_track, zone.y() - 1, -1, true);
clips.insert(subs.begin(), subs.end());
}
++it;
}
} else {
for (int &tid : allowedTracks) {
std::unordered_set<int> subs = timeline->getItemsInRange(tid, zone.y() - 1, -1, true);
clips.insert(subs.begin(), subs.end());
}
++it;
}
if (clips.size() == 0) {
// TODO: inform user no change will be performed
......
......@@ -89,7 +89,7 @@ struct TimelineFunctions
static bool requestSpacerEndOperation(const std::shared_ptr<TimelineItemModel> &timeline, int itemId, int startPosition, int endPosition);
static bool extractZone(const std::shared_ptr<TimelineItemModel> &timeline, QVector<int> tracks, QPoint zone, bool liftOnly);
static bool liftZone(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo);
static bool removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo, QVector<int> allowedTracks = QVector<int>());
static bool removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, QVector<int> allowedTracks = QVector<int>(), bool useTargets = true);
/** @brief This function will insert a blank space starting at zone.x, and ending at zone.y. This will affect all the tracks
@returns true on success, false otherwise
......
......@@ -2847,15 +2847,20 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView,
qDebug() << "//////\n//////\nENDING FAKE MNOVE: " << trackId << ", POS: " << position;
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
int startPos = m_model->getClipPosition(clipId);
int duration = m_model->getClipPlaytime(clipId);
int currentTrack = m_model->m_allClips[clipId]->getCurrentTrackId();
bool res = true;
if (currentTrack > -1) {
res = res && m_model->getTrackById(currentTrack)->requestClipDeletion(clipId, updateView, invalidateTimeline, undo, redo, false, false);
res = m_model->getTrackById(currentTrack)->requestClipDeletion(clipId, updateView, invalidateTimeline, undo, redo, false, false);
}
if (m_model->m_editMode == TimelineMode::OverwriteEdit) {
res = res && TimelineFunctions::liftZone(m_model, trackId, QPoint(position, position + duration), undo, redo);
} else if (m_model->m_editMode == TimelineMode::InsertEdit) {
// Remove space from previous location
if (currentTrack > -1) {
res = res && TimelineFunctions::removeSpace(m_model, {startPos,startPos + duration}, undo, redo, {currentTrack}, false);
}
int startClipId = m_model->getClipByPosition(trackId, position);
if (startClipId > -1) {
// There is a clip, cut
......@@ -2945,6 +2950,10 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
min = min < 0 ? old_position[item] + delta_pos : qMin(min, old_position[item] + delta_pos);
max = max < 0 ? old_position[item] + delta_pos + duration : qMax(max, old_position[item] + delta_pos + duration);
ok = ok && m_model->getTrackById(old_trackId)->requestClipDeletion(item, updateThisView, finalMove, undo, redo, false, false);
if (m_model->m_editMode == TimelineMode::InsertEdit) {
// Lift space left by removed clip
ok = ok && TimelineFunctions::removeSpace(m_model, {old_position[item],old_position[item] + duration}, undo, redo, {old_trackId}, false);
}
} else {
// ok = ok && getTrackById(old_trackId)->requestCompositionDeletion(item, updateThisView, local_undo, local_redo);
old_position[item] = m_model->m_allCompositions[item]->getPosition();
......
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