Fix some crashes with locked subtitle track

parent e21a4d11
......@@ -1068,7 +1068,7 @@ void SubtitleModel::switchLocked()
m_subtitleFilter->set("kdenlive:locked", isLocked ? 0 : 1);
// En/disable snapping on lock
std::vector<std::weak_ptr<SnapInterface>> validSnapModels;
/*std::vector<std::weak_ptr<SnapInterface>> validSnapModels;
for (const auto &snapModel : m_regSnaps) {
if (auto ptr = snapModel.lock()) {
validSnapModels.push_back(snapModel);
......@@ -1093,7 +1093,7 @@ void SubtitleModel::switchLocked()
int id = m_selected.takeFirst();
updateSub(id, {SelectedRole});
}
}
}*/
}
......@@ -1117,3 +1117,11 @@ void SubtitleModel::loadProperties(QMap<QString, QString> subProperties)
++i;
}
}
void SubtitleModel::allSnaps(std::vector<int> &snaps)
{
for (const auto &subtitle : m_subtitleList) {
snaps.push_back(subtitle.first.frames(pCore->getCurrentFps()));
snaps.push_back(subtitle.second.second.frames(pCore->getCurrentFps()));
}
}
......@@ -137,6 +137,8 @@ public:
bool isLocked() const;
/** @brief Load some subtitle filter properties from file */
void loadProperties(QMap<QString, QString> subProperties);
/** @brief Add all subtitle items to snaps */
void allSnaps(std::vector<int> &snaps);
public slots:
/** @brief Function that parses through a subtitle file */
......
......@@ -1880,7 +1880,6 @@ bool TimelineModel::requestSubtitleDeletion(int clipId, Fun &undo, Fun &redo, bo
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
return true;
}
undo();
return false;
}
......@@ -2881,10 +2880,15 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
TRACE_RES(-1)
return -1;
}
int in = getItemPosition(itemId);
int in = 0;
int offset = getItemPlaytime(itemId);
int out = in + offset;
int tid = getItemTrackId(itemId);
int out = offset;
if (tid != -1) {
in = getItemPosition(itemId);
out += in;
size = requestItemResizeInfo(itemId, in, out, size, right, snapDistance);
}
offset -= size;
Fun undo = []() { return true; };
Fun redo = []() { return true; };
......@@ -2897,7 +2901,6 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
QList <int> tracksWithMixes;
all_items.insert(itemId);
if (logUndo && isClip(itemId)) {
int tid = getItemTrackId(itemId);
if (tid > -1) {
if (right) {
if (getTrackById_const(tid)->hasEndMix(itemId)) {
......@@ -3078,6 +3081,9 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
if (tid > -1 && getTrackById_const(tid)->isLocked()) {
continue;
}
if (tid == -2 && m_subtitleModel && m_subtitleModel->isLocked()) {
continue;
}
if (right) {
finalSize = finalPos - getItemPosition(id);
} else {
......@@ -3871,7 +3877,8 @@ int TimelineModel::getNextSnapPos(int pos, std::vector<int> &snaps)
}
++it;
}
if (tracks.isEmpty() || tracks.count() == (int) m_allTracks.size()) {
bool hasSubtitles = m_subtitleModel && !m_allSubtitles.empty();
if ((tracks.isEmpty() || tracks.count() == (int) m_allTracks.size()) && (!hasSubtitles || !m_subtitleModel->isLocked())) {
// No active track, use all possible snap points
return m_snaps->getNextPoint((int)pos);
}
......@@ -3883,6 +3890,11 @@ int TimelineModel::getNextSnapPos(int pos, std::vector<int> &snaps)
clip->allSnaps(snaps);
}
}
// Subtitle snaps
if (hasSubtitles && !m_subtitleModel->isLocked()) {
// Add subtitle snaps
m_subtitleModel->allSnaps(snaps);
}
// sort snaps
std::sort(snaps.begin(), snaps.end());
for (auto i : snaps) {
......@@ -3904,7 +3916,8 @@ int TimelineModel::getPreviousSnapPos(int pos, std::vector<int> &snaps)
}
++it;
}
if (tracks.isEmpty() || tracks.count() == (int) m_allTracks.size()) {
bool hasSubtitles = m_subtitleModel && !m_allSubtitles.empty();
if ((tracks.isEmpty() || tracks.count() == (int) m_allTracks.size()) && (!hasSubtitles || !m_subtitleModel->isLocked())) {
// No active track, use all possible snap points
return m_snaps->getPreviousPoint((int)pos);
}
......@@ -3916,6 +3929,11 @@ int TimelineModel::getPreviousSnapPos(int pos, std::vector<int> &snaps)
clip->allSnaps(snaps);
}
}
// Subtitle snaps
if (hasSubtitles && !m_subtitleModel->isLocked()) {
// Add subtitle snaps
m_subtitleModel->allSnaps(snaps);
}
// sort snaps
std::sort(snaps.begin(), snaps.end());
// sort descending
......
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