Commit 2e78912e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Various fixes for remove space in subtitle track

parent 66cf639f
Pipeline #141448 passed with stage
in 7 minutes
......@@ -486,7 +486,7 @@ std::unordered_set<int> SubtitleModel::getItemsInRange(int startFrame, int endFr
// Outside range
continue;
}
if (subtitles.first >= startTime || subtitles.second.second >= startTime) {
if (subtitles.first >= startTime || subtitles.second.second > startTime) {
int sid = getIdForStartPos(subtitles.first);
if (sid > -1) {
matching.emplace(sid);
......@@ -1204,33 +1204,27 @@ QDomElement SubtitleModel::toXml(int sid, QDomDocument &document)
return container;
}
int SubtitleModel::getBlankSizeAtPos(int pos) const
bool SubtitleModel::isBlankAt(int pos) const
{
GenTime matchPos(pos, pCore->getCurrentFps());
std::unordered_set<int> matching;
GenTime min;
GenTime max;
for (const auto &subtitles : m_subtitleList) {
if (subtitles.first > matchPos && (max == GenTime() || subtitles.first < max)) {
// Outside range
max = subtitles.first;
if (subtitles.first > matchPos) {
continue;
}
if (subtitles.second.second < matchPos && (min == GenTime() || subtitles.second.second > min)) {
min = subtitles.second.second;
if (subtitles.second.second > matchPos) {
return false;
}
}
return max.frames(pCore->getCurrentFps()) - min.frames(pCore->getCurrentFps());
return true;;
}
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)) {
if (subtitles.second.second <= matchPos && (min == GenTime() || subtitles.second.second > min)) {
min = subtitles.second.second;
found = true;
}
......
......@@ -127,10 +127,10 @@ public:
void allSnaps(std::vector<int> &snaps);
/** @brief Returns an xml representation of the subtitle with id \@sid */
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 Returns true is track is empty at pos */
bool isBlankAt(int pos) const;
/** @brief Switch a subtitle's grab state */
void switchGrab(int sid);
/** @brief Ungrab all items */
......@@ -152,6 +152,7 @@ public slots:
private:
std::shared_ptr<TimelineItemModel> m_timeline;
std::weak_ptr<DocUndoStack> m_undoStack;
/** @brief A list of subtitles as: start time, text, end time */
std::map<GenTime, std::pair<QString, GenTime>> m_subtitleList;
QString scriptInfoSection, styleSection,eventSection;
......
......@@ -2080,6 +2080,9 @@ bool TimelineFunctions::requestDeleteBlankAt(const std::shared_ptr<TimelineItemM
} else {
if (trackId == -2) {
// Subtitle track
if (!timeline->getSubtitleModel()->isBlankAt(position)) {
return false;
}
spaceStart = timeline->getSubtitleModel()->getBlankStart(position);
} else {
if (!timeline->getTrackById_const(trackId)->isBlankAt(position)) {
......
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