Fix timeline operations (insert/overwrite/lift)

parent ad3f67d6
......@@ -2426,10 +2426,11 @@ void MainWindow::slotInsertClipOverwrite()
}
int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), true);
if (pos > 0) {
Kdenlive::MonitorId activeMonitor = pCore->monitorManager()->activeMonitor()->id();
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
m_projectMonitor->refreshMonitorIfActive(true);
getCurrentTimeline()->controller()->setPosition(pos);
pCore->monitorManager()->activateMonitor(Kdenlive::ClipMonitor);
pCore->monitorManager()->activateMonitor(activeMonitor);
}
}
......@@ -2442,10 +2443,11 @@ void MainWindow::slotInsertClipInsert()
}
int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), false);
if (pos > 0) {
Kdenlive::MonitorId activeMonitor = pCore->monitorManager()->activeMonitor()->id();
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
m_projectMonitor->refreshMonitorIfActive(true);
getCurrentTimeline()->controller()->setPosition(pos);
pCore->monitorManager()->activateMonitor(Kdenlive::ClipMonitor);
pCore->monitorManager()->activateMonitor(activeMonitor);
}
}
......
......@@ -295,7 +295,6 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool result = true;
int trackId = trackIds.first();
if (overwrite) {
// Cut all tracks
auto it = timeline->m_allTracks.cbegin();
......@@ -331,9 +330,11 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
result = result && TimelineFunctions::requestInsertSpace(timeline, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
}
if (result) {
int newId = -1;
QString binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
result = timeline->requestClipInsertion(binClipId, trackId, insertFrame, newId, true, true, true, undo, redo);
if (!trackIds.isEmpty()) {
int newId = -1;
QString binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
result = timeline->requestClipInsertion(binClipId, trackIds.first(), insertFrame, newId, true, true, true, undo, redo);
}
if (result) {
pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone"));
}
......@@ -376,8 +377,18 @@ bool TimelineFunctions::liftZone(const std::shared_ptr<TimelineItemModel> &timel
bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo)
{
Q_UNUSED(trackId)
std::unordered_set<int> clips = timeline->getItemsInRange(-1, zone.y() - 1, -1, true);
std::unordered_set<int> clips;
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->m_videoTarget == target_track || timeline->m_audioTarget == target_track || 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;
}
bool result = false;
if (!clips.empty()) {
int clipId = *clips.begin();
......@@ -401,12 +412,27 @@ bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &ti
return result;
}
bool TimelineFunctions::requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo)
bool TimelineFunctions::requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, bool followTargets)
{
timeline->requestClearSelection();
Fun local_undo = []() { return true; };
Fun local_redo = []() { return true; };
std::unordered_set<int> items = timeline->getItemsInRange(-1, zone.x(), -1, true);
std::unordered_set<int> items;
if (!followTargets) {
// Select clips in all tracks
items = timeline->getItemsInRange(-1, zone.x(), -1, true);
} else {
// Select clips in target and active tracks only
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->m_videoTarget == target_track || timeline->m_audioTarget == target_track || timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
std::unordered_set<int> subs = timeline->getItemsInRange(target_track, zone.x(), -1, true);
items.insert(subs.begin(), subs.end());
}
++it;
}
}
if (items.empty()) {
return true;
}
......
......@@ -88,7 +88,7 @@ struct TimelineFunctions
/** @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
*/
static bool requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo);
static bool requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, bool followTargets = true);
static bool insertZone(const std::shared_ptr<TimelineItemModel> &timeline, QList<int> trackIds, const QString &binId, int insertFrame, QPoint zone,
bool overwrite);
......
......@@ -1526,7 +1526,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
if (clip->hasVideo()) {
vTrack = videoTarget();
}
if (aTrack == -1 && vTrack == -1) {
/*if (aTrack == -1 && vTrack == -1) {
// No target tracks defined, use active track
if (m_model->getTrackById_const(m_activeTrack)->isAudioTrack()) {
aTrack = m_activeTrack;
......@@ -1535,7 +1535,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
vTrack = m_activeTrack;
aTrack = m_model->getMirrorAudioTrackId(vTrack);
}
}
}*/
int insertPoint;
QPoint sourceZone;
if (useRuler() && m_zone != QPoint()) {
......@@ -2070,7 +2070,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView,
// There is a clip, cut
res = res && TimelineFunctions::requestClipCut(m_model, startClipId, position, undo, redo);
}
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(position, position + duration), undo, redo);
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(position, position + duration), undo, redo, false);
}
res = res && m_model->getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, undo, redo);
if (res) {
......@@ -2184,7 +2184,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
res = res && TimelineFunctions::requestClipCut(m_model, startClipId, target_position, undo, redo);
}
}
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(min, max), undo, redo);
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(min, max), undo, redo, false);
}
for (int item : sorted_clips) {
if (m_model->isClip(item)) {
......
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