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

Further progress in subtitle undo/redo

parent 1b936413
Pipeline #39892 passed with stage
in 12 minutes and 4 seconds
......@@ -93,8 +93,10 @@ Item {
selectByMouse: true
onEditingFinished: {
subtitleEdit.focus = false
timeline.editSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleEdit.displayText, (subtitleBase.x + subtitleBase.width)/ timeline.scaleFactor)
parent.textEditBegin = false
if (model.subtitle != subtitleEdit.text) {
timeline.editSubtitle(subtitleBase.x / timeline.scaleFactor, (subtitleBase.x + subtitleBase.width)/ timeline.scaleFactor, subtitleEdit.text, model.subtitle)
}
}
anchors.fill: parent
//visible: timeScale >= 6
......@@ -238,7 +240,7 @@ Item {
root.autoScrolling = timeline.autoScroll
rightend.anchors.right = subtitleBase.right
if (mouseX != oldMouseX || sizeChanged) {
timeline.editSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleEdit.text, subtitleBase.x / timeline.scaleFactor + duration)
timeline.resizeSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + duration, subtitleBase.x / timeline.scaleFactor + subtitleBase.duration)
sizeChanged = false
}
}
......
......@@ -3721,28 +3721,61 @@ void TimelineController::temporaryUnplug(QList<int> clipIds, bool hide)
}
}
void TimelineController::editSubtitle(int startFrame, QString text, int endFrame)
void TimelineController::editSubtitle(int startFrame, int endFrame, QString newText, QString oldText)
{
qDebug()<<"Editing existing subtitle in controller at:"<<startFrame<<"\n\n=====================";
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
Fun local_redo = [subtitleModel, startFrame, endFrame, newText]() {
subtitleModel->editSubtitle(GenTime(startFrame, pCore->getCurrentFps()), newText, GenTime(endFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({startFrame, endFrame});
return true;
};
Fun local_undo = [subtitleModel, startFrame, endFrame, oldText]() {
subtitleModel->editSubtitle(GenTime(startFrame, pCore->getCurrentFps()), oldText, GenTime(endFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({startFrame, endFrame});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Edit subtitle"));
}
void TimelineController::resizeSubtitle(int startFrame, int endFrame, int oldEndFrame)
{
qDebug()<<"Editing existing subtitle in controller at:"<<startFrame;
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
GenTime startPos(startFrame, pCore->getCurrentFps());
GenTime endPos(endFrame, pCore->getCurrentFps());
subtitleModel->editSubtitle(startPos, text, endPos);
pCore->refreshProjectRange({startFrame, endFrame});
return;
int max = qMax(endFrame, oldEndFrame);
Fun local_redo = [subtitleModel, startFrame, endFrame, max]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(endFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({startFrame, max});
return true;
};
Fun local_undo = [subtitleModel, startFrame, oldEndFrame, max]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(oldEndFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({startFrame, max});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Resize subtitle"));
}
void TimelineController::moveSubtitle(int oldStartFrame, int newStartFrame, int duration)
{
qDebug()<<"Moving existing subtitle start position in controller from"<<oldStartFrame<<" to "<<newStartFrame;
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
GenTime oldStartPos(oldStartFrame, pCore->getCurrentFps());
GenTime newStartPos(newStartFrame, pCore->getCurrentFps());
subtitleModel->moveSubtitle(oldStartPos, newStartPos);
int min = qMin(oldStartFrame, newStartFrame);
int max = qMax(oldStartFrame, newStartFrame);
pCore->refreshProjectRange({min, max + duration});
Fun local_redo = [subtitleModel, oldStartFrame, newStartFrame, duration, min]() {
subtitleModel->moveSubtitle(GenTime(oldStartFrame, pCore->getCurrentFps()), GenTime (newStartFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({min, oldStartFrame + duration});
return true;
};
Fun local_undo = [subtitleModel, oldStartFrame, newStartFrame, min, duration]() {
subtitleModel->moveSubtitle(GenTime (newStartFrame, pCore->getCurrentFps()), GenTime(oldStartFrame, pCore->getCurrentFps()));
pCore->refreshProjectRange({min, oldStartFrame + duration});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Resize subtitle"));
return;
}
......
......@@ -566,8 +566,10 @@ public:
Q_INVOKABLE void mixClip(int cid = -1, int delta = 0);
/** @brief Temporarily un/plug a list of clips in timeline. */
void temporaryUnplug(QList<int> clipIds, bool hide);
/** @brief Edit the subtitle text and/or end timings */
Q_INVOKABLE void editSubtitle(int startFrame, QString text, int endFrame);
/** @brief Edit the subtitle text*/
Q_INVOKABLE void editSubtitle(int startFrame, int endFrame, QString newText, QString oldText);
/** @brief Edit the subtitle end */
Q_INVOKABLE void resizeSubtitle(int startFrame, int endFrame, int oldEndFrame);
/** @brief Move position of subtitle start timing */
Q_INVOKABLE void moveSubtitle(int oldStartFrame, int newStartFrame, int duration);
/** @brief Shift subtitle clips without changing the clip duration */
......
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