Commit 787f822c authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix insert drag affecting all tracks, and fix snapping on insert/overwrite drag

Related to #673
parent 5e52a8de
Pipeline #20439 passed with stage
in 9 minutes and 39 seconds
...@@ -93,9 +93,9 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt ...@@ -93,9 +93,9 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
return id; return id;
} }
void ClipModel::allSnaps(std::vector<int> &snaps) void ClipModel::allSnaps(std::vector<int> &snaps, int offset)
{ {
m_clipMarkerModel->allSnaps(snaps); m_clipMarkerModel->allSnaps(snaps, offset);
} }
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, const std::shared_ptr<Mlt::Producer> &producer, int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, const std::shared_ptr<Mlt::Producer> &producer,
......
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
QDomElement toXml(QDomDocument &document); QDomElement toXml(QDomDocument &document);
/* @brief Retrieve a list of all snaps for this clip */ /* @brief Retrieve a list of all snaps for this clip */
void allSnaps(std::vector<int> &snaps); void allSnaps(std::vector<int> &snaps, int offset = 0);
protected: protected:
// helper functions that creates the lambda // helper functions that creates the lambda
......
...@@ -89,17 +89,17 @@ void ClipSnapModel::removeAllSnaps() ...@@ -89,17 +89,17 @@ void ClipSnapModel::removeAllSnaps()
} }
} }
void ClipSnapModel::allSnaps(std::vector<int> &snaps) void ClipSnapModel::allSnaps(std::vector<int> &snaps, int offset)
{ {
snaps.push_back(m_position); snaps.push_back(m_position - offset);
if (auto ptr = m_registeredSnap.lock()) { if (auto ptr = m_registeredSnap.lock()) {
for (const auto &snap : m_snapPoints) { for (const auto &snap : m_snapPoints) {
if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) { if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) {
snaps.push_back(m_speed < 0 ? ceil(m_outPoint + m_position + snap / m_speed - m_inPoint) : ceil(m_position + snap / m_speed - m_inPoint)); snaps.push_back(m_speed < 0 ? ceil(m_outPoint + m_position + snap / m_speed - m_inPoint - offset) : ceil(m_position + snap / m_speed - m_inPoint - offset));
} }
} }
} }
snaps.push_back(m_position + m_outPoint - m_inPoint + 1); snaps.push_back(m_position + m_outPoint - m_inPoint + 1 - offset);
} }
void ClipSnapModel::registerSnapModel(const std::weak_ptr<SnapModel> &snapModel, int position, int in, int out, double speed) void ClipSnapModel::registerSnapModel(const std::weak_ptr<SnapModel> &snapModel, int position, int in, int out, double speed)
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
void updateSnapModelPos(int newPos); void updateSnapModelPos(int newPos);
void updateSnapModelInOut(std::pair<int, int> newInOut); void updateSnapModelInOut(std::pair<int, int> newInOut);
/* @brief Retrieve all snap points */ /* @brief Retrieve all snap points */
void allSnaps(std::vector<int> &snaps); void allSnaps(std::vector<int> &snaps, int offset = 0);
private: private:
......
...@@ -414,7 +414,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim ...@@ -414,7 +414,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
bool result = true; bool result = true;
QVector<int> affectedTracks; QVector<int> affectedTracks;
auto it = timeline->m_allTracks.cbegin(); auto it = timeline->m_allTracks.cbegin();
if (!useTargets && overwrite) { if (!useTargets) {
// Timeline drop in overwrite mode // Timeline drop in overwrite mode
for (int target_track : trackIds) { for (int target_track : trackIds) {
if (!timeline->getTrackById_const(target_track)->isLocked()) { if (!timeline->getTrackById_const(target_track)->isLocked()) {
...@@ -424,7 +424,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim ...@@ -424,7 +424,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
} else { } else {
while (it != timeline->m_allTracks.cend()) { while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId(); int target_track = (*it)->getId();
if (!useTargets || timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) { if (timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
affectedTracks << target_track; affectedTracks << target_track;
} else if (trackIds.contains(target_track)) { } else if (trackIds.contains(target_track)) {
// Track is marked as target but not active, remove it // Track is marked as target but not active, remove it
......
...@@ -640,11 +640,6 @@ bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, b ...@@ -640,11 +640,6 @@ bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, b
QWriteLocker locker(&m_lock); QWriteLocker locker(&m_lock);
TRACE(clipId, trackId, position, updateView, logUndo, invalidateTimeline) TRACE(clipId, trackId, position, updateView, logUndo, invalidateTimeline)
Q_ASSERT(m_allClips.count(clipId) > 0); Q_ASSERT(m_allClips.count(clipId) > 0);
if (m_allClips[clipId]->getPosition() == position && m_allClips[clipId]->getFakeTrackId() == trackId) {
TRACE_RES(true);
qDebug()<<"........\nABORTING MOVE; SAME POS/TRACK\n..........";
return true;
}
if (m_groups->isInGroup(clipId)) { if (m_groups->isInGroup(clipId)) {
// element is in a group. // element is in a group.
int groupId = m_groups->getRootId(clipId); int groupId = m_groups->getRootId(clipId);
...@@ -738,20 +733,21 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio ...@@ -738,20 +733,21 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
TRACE(clipId, trackId, position, cursorPosition, snapDistance); TRACE(clipId, trackId, position, cursorPosition, snapDistance);
Q_ASSERT(isClip(clipId)); Q_ASSERT(isClip(clipId));
Q_ASSERT(isTrack(trackId)); Q_ASSERT(isTrack(trackId));
int currentPos = getClipPosition(clipId); int currentPos = m_editMode == TimelineMode::NormalEdit ? getClipPosition(clipId) : m_allClips[clipId]->getFakePosition();
int offset = m_editMode == TimelineMode::NormalEdit ? 0 : getClipPosition(clipId) - currentPos;
int sourceTrackId = (m_editMode != TimelineMode::NormalEdit) ? m_allClips[clipId]->getFakeTrackId() : getClipTrackId(clipId); int sourceTrackId = (m_editMode != TimelineMode::NormalEdit) ? m_allClips[clipId]->getFakeTrackId() : getClipTrackId(clipId);
if (sourceTrackId > -1 && getTrackById_const(trackId)->isAudioTrack() != getTrackById_const(sourceTrackId)->isAudioTrack()) { if (sourceTrackId > -1 && getTrackById_const(trackId)->isAudioTrack() != getTrackById_const(sourceTrackId)->isAudioTrack()) {
// Trying move on incompatible track type, stay on same track // Trying move on incompatible track type, stay on same track
trackId = sourceTrackId; trackId = sourceTrackId;
} }
if (currentPos == position && m_editMode == TimelineMode::NormalEdit && sourceTrackId == trackId) { if (currentPos == position && sourceTrackId == trackId) {
TRACE_RES(position); TRACE_RES(position);
return {position, trackId}; return {position, trackId};
} }
bool after = position > currentPos; bool after = position > currentPos;
if (snapDistance > 0) { if (snapDistance > 0) {
// For snapping, we must ignore all in/outs of the clips of the group being moved
std::vector<int> ignored_pts; std::vector<int> ignored_pts;
// For snapping, we must ignore all in/outs of the clips of the group being moved
std::unordered_set<int> all_items = {clipId}; std::unordered_set<int> all_items = {clipId};
if (m_groups->isInGroup(clipId)) { if (m_groups->isInGroup(clipId)) {
int groupId = m_groups->getRootId(clipId); int groupId = m_groups->getRootId(clipId);
...@@ -760,17 +756,16 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio ...@@ -760,17 +756,16 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
for (int current_clipId : all_items) { for (int current_clipId : all_items) {
if (getItemTrackId(current_clipId) != -1) { if (getItemTrackId(current_clipId) != -1) {
if (isClip(current_clipId)) { if (isClip(current_clipId)) {
m_allClips[current_clipId]->allSnaps(ignored_pts); m_allClips[current_clipId]->allSnaps(ignored_pts, offset);
} else { } else {
// Composition // Composition
int in = getItemPosition(current_clipId); int in = getItemPosition(current_clipId) - offset;
ignored_pts.push_back(in); ignored_pts.push_back(in);
ignored_pts.push_back(in + getItemPlaytime(current_clipId)); ignored_pts.push_back(in + getItemPlaytime(current_clipId));
} }
} }
} }
int snapped = getBestSnapPos(currentPos, position - currentPos, m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(), int snapped = getBestSnapPos(currentPos, position - currentPos, ignored_pts, cursorPosition, snapDistance);
cursorPosition, snapDistance);
// qDebug() << "Starting suggestion " << clipId << position << currentPos << "snapped to " << snapped; // qDebug() << "Starting suggestion " << clipId << position << currentPos << "snapped to " << snapped;
if (snapped >= 0) { if (snapped >= 0) {
position = snapped; position = snapped;
...@@ -779,9 +774,6 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio ...@@ -779,9 +774,6 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
// we check if move is possible // we check if move is possible
bool possible = (m_editMode == TimelineMode::NormalEdit) ? requestClipMove(clipId, trackId, position, moveMirrorTracks, true, false, false) bool possible = (m_editMode == TimelineMode::NormalEdit) ? requestClipMove(clipId, trackId, position, moveMirrorTracks, true, false, false)
: requestFakeClipMove(clipId, trackId, position, true, false, false); : requestFakeClipMove(clipId, trackId, position, true, false, false);
/*} else {
possible = requestClipMoveAttempt(clipId, trackId, position);
}*/
if (possible) { if (possible) {
TRACE_RES(position); TRACE_RES(position);
if (m_editMode != TimelineMode::NormalEdit) { if (m_editMode != TimelineMode::NormalEdit) {
...@@ -2906,7 +2898,9 @@ int TimelineModel::suggestSnapPoint(int pos, int snapDistance) ...@@ -2906,7 +2898,9 @@ int TimelineModel::suggestSnapPoint(int pos, int snapDistance)
int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> pts, int cursorPosition, int snapDistance) int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> pts, int cursorPosition, int snapDistance)
{ {
if (!pts.empty()) { if (!pts.empty()) {
m_snaps->ignore(pts); if (m_editMode == TimelineMode::NormalEdit) {
m_snaps->ignore(pts);
}
} else { } else {
return -1; return -1;
} }
...@@ -2927,7 +2921,9 @@ int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> p ...@@ -2927,7 +2921,9 @@ int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> p
} }
} }
} }
m_snaps->unIgnore(); if (m_editMode == TimelineMode::NormalEdit) {
m_snaps->unIgnore();
}
m_snaps->removePoint(cursorPosition); m_snaps->removePoint(cursorPosition);
return closest; return closest;
} }
......
...@@ -2861,7 +2861,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView, ...@@ -2861,7 +2861,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView,
// There is a clip, cut // There is a clip, cut
res = res && TimelineFunctions::requestClipCut(m_model, startClipId, position, undo, redo); 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, {currentTrack});
} }
res = res && m_model->getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, undo, redo); res = res && m_model->getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, undo, redo);
if (res) { if (res) {
...@@ -2968,7 +2968,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra ...@@ -2968,7 +2968,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
} }
} }
} else if (m_model->m_editMode == TimelineMode::InsertEdit) { } else if (m_model->m_editMode == TimelineMode::InsertEdit) {
QList<int> processedTracks; QVector<int> processedTracks;
for (int item : sorted_clips) { for (int item : sorted_clips) {
int target_track = new_track_ids[item]; int target_track = new_track_ids[item];
if (processedTracks.contains(target_track)) { if (processedTracks.contains(target_track)) {
...@@ -2983,7 +2983,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra ...@@ -2983,7 +2983,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::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, processedTracks);
} }
for (int item : sorted_clips) { for (int item : sorted_clips) {
if (m_model->isClip(item)) { 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