Update project duration accordingly when subtitles are added/moved

parent f1aae681
......@@ -351,6 +351,9 @@ bool SubtitleModel::addSubtitle(int id, GenTime start, GenTime end, const QStrin
endInsertRows();
addSnapPoint(start);
addSnapPoint(end);
if (!temporary && end.frames(pCore->getCurrentFps()) > m_timeline->duration()) {
m_timeline->updateDuration();
}
qDebug()<<"Added to model";
if (updateFilter) {
emit modelChanged();
......@@ -721,10 +724,18 @@ bool SubtitleModel::removeSubtitle(int id, bool temporary, bool updateFilter)
int row = m_timeline->getSubtitleIndex(id);
m_timeline->deregisterSubtitle(id, temporary);
beginRemoveRows(QModelIndex(), row, row);
bool lastSub = false;
if (start == m_subtitleList.rbegin()->first) {
// Check if this is the last subtitle
lastSub = true;
}
m_subtitleList.erase(start);
endRemoveRows();
removeSnapPoint(start);
removeSnapPoint(end);
if (lastSub) {
m_timeline->updateDuration();
}
if (updateFilter) {
emit modelChanged();
}
......@@ -789,6 +800,10 @@ bool SubtitleModel::moveSubtitle(int subId, GenTime newPos, bool updateModel, bo
if (updateModel) {
// Trigger update of the subtitle file
emit modelChanged();
if (newPos == m_subtitleList.rbegin()->first) {
// Check if this is the last subtitle
m_timeline->updateDuration();
}
}
return true;
}
......@@ -1009,3 +1024,11 @@ bool SubtitleModel::isSelected(int id) const
{
return m_selected.contains(id);
}
int SubtitleModel::trackDuration() const
{
if (m_subtitleList.empty()) {
return 0;
}
return m_subtitleList.rbegin()->second.second.frames(pCore->getCurrentFps());
}
......@@ -130,6 +130,7 @@ public:
int getNextSub(int id) const;
/** @brief Copy subtitle file to a new path */
void copySubtitle(const QString &path, bool checkOverwrite);
int trackDuration() const;
public slots:
/** @brief Function that parses through a subtitle file */
......
......@@ -3777,6 +3777,9 @@ void TimelineModel::updateDuration()
auto track = (*tck.second);
duration = qMax(duration, track->trackDuration());
}
if (m_subtitleModel) {
duration = qMax(duration, m_subtitleModel->trackDuration());
}
if (duration != current) {
// update black track length
m_blackClip->set("out", duration + TimelineModel::seekDuration);
......
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