Commit 0d7dd3b6 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix spacer track sometimes not allowing to reduce space

parent e0edf3e8
......@@ -341,6 +341,7 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
std::unordered_set<int> groupsToRemove;
int firstCid = -1;
int firstPosition = -1;
QMap<int,int>firstPositions;
for (int r : roots) {
if (timeline->isGroup(r)) {
std::unordered_set<int> leaves = timeline->m_groups->getLeaves(r);
......@@ -352,6 +353,15 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
leavesToRemove.insert(l);
} else {
leavesToKeep.insert(l);
int tid = timeline->getItemTrackId(l);
// Check space in all tracks
if (!firstPositions.contains(tid)) {
firstPositions.insert(tid, pos);
} else {
if (pos < firstPositions.value(tid)) {
firstPositions.insert(tid, pos);
}
}
// Find first item
if (firstPosition == -1 || pos < firstPosition) {
firstCid = l;
......@@ -374,6 +384,15 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
}
} else {
int pos = timeline->getItemPosition(r);
int tid = timeline->getItemTrackId(r);
// Check space in all tracks
if (!firstPositions.contains(tid)) {
firstPositions.insert(tid, pos);
} else {
if (pos < firstPositions.value(tid)) {
firstPositions.insert(tid, pos);
}
}
if (firstPosition == -1 || pos < firstPosition) {
firstCid = r;
firstPosition = pos;
......@@ -391,7 +410,7 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
timeline->m_groups->ungroupItem(i.key(), undo, redo);
}
timeline->requestSetSelection(roots);
if (firstPosition > 0) {
if (!firstPositions.isEmpty()) {
// Find minimum position, parse all tracks
if (trackId > -1) {
// Easy, check blank size
......@@ -404,7 +423,12 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
auto it = timeline->m_allTracks.cbegin();
int space = -1;
while (it != timeline->m_allTracks.cend()) {
int spaceDuration = timeline->getTrackById_const((*it)->getId())->getBlankSizeAtPos(firstPosition - 1);
int tid = (*it)->getId();
if (!firstPositions.contains(tid)) {
++it;
continue;
}
int spaceDuration = (*it)->getBlankSizeAtPos(firstPositions.value(tid) - 1);
if (space == -1 || spaceDuration < space) {
space = spaceDuration;
}
......
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