Commit 9db68961 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix various spacer issues.

Fixes #1093
parent 6431ce25
Pipeline #64169 passed with stage
in 8 minutes and 2 seconds
......@@ -1225,3 +1225,18 @@ int SubtitleModel::getBlankSizeAtPos(int pos) const
}
return max.frames(pCore->getCurrentFps()) - min.frames(pCore->getCurrentFps());
}
int SubtitleModel::getBlankStart(int pos) const
{
GenTime matchPos(pos, pCore->getCurrentFps());
std::unordered_set<int> matching;
bool found = false;
GenTime min;
for (const auto &subtitles : m_subtitleList) {
if (subtitles.second.second < matchPos && (min == GenTime() || subtitles.second.second > min)) {
min = subtitles.second.second;
found = true;
}
}
return found ? min.frames(pCore->getCurrentFps()) + 1 : 0;
}
......@@ -144,6 +144,8 @@ public:
QDomElement toXml(int sid, QDomDocument &document);
/** @brief Returns the size of the space between subtitles */
int getBlankSizeAtPos(int pos) const;
/** @brief Returns the position of the first blank frame before a position */
int getBlankStart(int pos) const;
/** @brief Switch a subtitle's grab state */
void switchGrab(int sid);
/** @brief Ungrab all items */
......
......@@ -1925,14 +1925,31 @@ bool TimelineFunctions::pasteTimelineClips(const std::shared_ptr<TimelineItemMod
bool TimelineFunctions::requestDeleteBlankAt(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, int position, bool affectAllTracks)
{
// find blank duration
int spaceDuration;
if (trackId == -2) {
// Subtitle track
spaceDuration = timeline->getSubtitleModel()->getBlankSizeAtPos(position);
int spaceStart = 0;
if (affectAllTracks) {
int lastFrame = 0;
for (const auto &track: timeline->m_allTracks) {
lastFrame = track->getBlankStart(position);
if (lastFrame > spaceStart) {
spaceStart = lastFrame;
}
}
// check subtitle track
if (timeline->getSubtitleModel()) {
lastFrame = timeline->getSubtitleModel()->getBlankStart(position);
if (lastFrame > spaceStart) {
spaceStart = lastFrame;
}
}
} else {
spaceDuration = timeline->getTrackById_const(trackId)->getBlankSizeAtPos(position);
if (trackId == -2) {
// Subtitle track
spaceStart = timeline->getSubtitleModel()->getBlankStart(position);
} else {
spaceStart = timeline->getTrackById_const(trackId)->getBlankStart(position);
}
}
if (spaceDuration <= 0) {
if (spaceStart == position) {
return false;
}
int cid = requestSpacerStartOperation(timeline, affectAllTracks ? -1 : trackId, position);
......@@ -1943,7 +1960,7 @@ bool TimelineFunctions::requestDeleteBlankAt(const std::shared_ptr<TimelineItemM
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
requestSpacerEndOperation(timeline, cid, start, start - spaceDuration, affectAllTracks ? -1 : trackId, !KdenliveSettings::lockedGuides(), undo, redo);
requestSpacerEndOperation(timeline, cid, start, spaceStart, affectAllTracks ? -1 : trackId, !KdenliveSettings::lockedGuides(), undo, redo);
return true;
}
......
......@@ -459,8 +459,9 @@ int TrackModel::getBlankSizeAtPos(int frame)
int min_length = 0;
int blank_length = 0;
for (auto &m_playlist : m_playlists) {
if (frame >= m_playlist.get_length()) {
blank_length = frame - m_playlist.get_length() + 1;
int playlistLength = m_playlist.get_length();
if (frame >= playlistLength) {
continue;
} else {
int ix = m_playlist.get_clip_index_at(frame);
if (m_playlist.is_blank(ix)) {
......@@ -474,6 +475,10 @@ int TrackModel::getBlankSizeAtPos(int frame)
min_length = blank_length;
}
}
if (blank_length == 0) {
// playlists are shorter than frame
return -1;
}
return min_length;
}
......
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