Start subtitle undo/redo integration

Related to #666
parent 05dea895
Pipeline #39783 passed with stage
in 14 minutes and 44 seconds
......@@ -248,7 +248,7 @@ GenTime SubtitleModel::stringtoTime(QString &str)
return pos;
}
void SubtitleModel::addSubtitle(GenTime start, GenTime end, QString &str)
void SubtitleModel::addSubtitle(GenTime start, GenTime end, const QString str)
{
if (start.frames(pCore->getCurrentFps()) < 0 || end.frames(pCore->getCurrentFps()) < 0) {
qDebug()<<"Time error: is negative";
......@@ -547,4 +547,5 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
qDebug()<<"Setting subtitle filter";
m_subtitleFilter->set("av.filename", outFile.toUtf8().constData());
m_tractor->attach(*m_subtitleFilter.get());
}
\ No newline at end of file
}
......@@ -53,7 +53,7 @@ public:
enum { SubtitleRole = Qt::UserRole + 1, StartPosRole, EndPosRole, StartFrameRole, EndFrameRole };
/** @brief Function that parses through a subtitle file */
void addSubtitle(GenTime start,GenTime end, QString &str);
void addSubtitle(GenTime start,GenTime end, const QString str);
/** @brief Converts string of time to GenTime */
GenTime stringtoTime(QString &str);
/** @brief Return model data item according to the role passed */
......
......@@ -48,7 +48,7 @@ Item {
console.log('IT IS PRESSED')
if (mouse.button == Qt.RightButton) {
console.log('RIGHT BUTTON CLICKED')
timeline.deleteSubtitle(subtitleBase.x / timeline.scaleFactor)
timeline.deleteSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + duration, subtitleEdit.text)
}
else {
root.autoScrolling = false
......
......@@ -3727,6 +3727,7 @@ void TimelineController::editSubtitle(int startFrame, QString text, int endFrame
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;
......@@ -3750,32 +3751,70 @@ void TimelineController::shiftSubtitle(int oldStartFrame, int newStartFrame, int
qDebug()<<"Shifting existing subtitle in controller from"<<oldStartFrame<<" to "<<newStartFrame;
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
GenTime oldStartPos(oldStartFrame, pCore->getCurrentFps());
GenTime newStartPos(newStartFrame, pCore->getCurrentFps());
GenTime endPos(endFrame, pCore->getCurrentFps());
subtitleModel->removeSubtitle(oldStartPos); //first delete subtitle at old start position
subtitleModel->addSubtitle(newStartPos, endPos, text); //next, add a new subtitle at new start position
pCore->refreshProjectRange({qMin(oldStartFrame, newStartFrame), endFrame});
int min = qMin(oldStartFrame, newStartFrame);
int max = qMax(oldStartFrame, newStartFrame);
int duration = endFrame - newStartFrame;
Fun local_redo = [subtitleModel, oldStartFrame, newStartFrame, endFrame, text, min, max, duration]() {
subtitleModel->removeSubtitle(GenTime(oldStartFrame, pCore->getCurrentFps()));
subtitleModel->addSubtitle(GenTime(newStartFrame, pCore->getCurrentFps()), GenTime(endFrame, pCore->getCurrentFps()), text);
if (max - min > duration) {
pCore->refreshProjectRange({min, min + duration});
pCore->refreshProjectRange({max, max + duration});
} else {
pCore->refreshProjectRange({min, max + duration});
}
return true;
};
Fun local_undo = [subtitleModel, oldStartFrame, newStartFrame, text, min, max, duration]() {
subtitleModel->removeSubtitle(GenTime(newStartFrame, pCore->getCurrentFps()));
subtitleModel->addSubtitle(GenTime(oldStartFrame, pCore->getCurrentFps()), GenTime(oldStartFrame + duration, pCore->getCurrentFps()), text);
if (max - min > duration) {
pCore->refreshProjectRange({min, min + duration});
pCore->refreshProjectRange({max, max + duration});
} else {
pCore->refreshProjectRange({min, max + duration});
}
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Move subtitle"));
}
void TimelineController::addSubtitle()
{
int startframe = pCore->getTimelinePosition();
int endframe = startframe + 50; //create basic subtitle clip of default width
GenTime start(startframe, pCore->getCurrentFps());
GenTime end(endframe, pCore->getCurrentFps());
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
QString text = "Add Text";
subtitleModel->addSubtitle(start, end, text);
pCore->refreshProjectRange({startframe, endframe});
Fun local_undo = [subtitleModel, startframe, endframe]() {
subtitleModel->removeSubtitle(GenTime(startframe, pCore->getCurrentFps()));
pCore->refreshProjectRange({startframe, endframe});
return true;
};
Fun local_redo = [subtitleModel, startframe, endframe]() {
subtitleModel->addSubtitle(GenTime(startframe, pCore->getCurrentFps()), GenTime(endframe, pCore->getCurrentFps()), i18n("Add text"));
pCore->refreshProjectRange({startframe, endframe});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Add subtitle"));
}
void TimelineController::deleteSubtitle(int frame)
void TimelineController::deleteSubtitle(int startframe, int endframe, QString text)
{
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
GenTime start(frame, pCore->getCurrentFps());
subtitleModel->removeSubtitle(start);
Fun local_redo = [subtitleModel, startframe, endframe]() {
subtitleModel->removeSubtitle(GenTime(startframe, pCore->getCurrentFps()));
pCore->refreshProjectRange({startframe, endframe});
return true;
};
Fun local_undo = [subtitleModel, startframe, endframe, text]() {
subtitleModel->addSubtitle(GenTime(startframe, pCore->getCurrentFps()), GenTime(endframe, pCore->getCurrentFps()), text);
pCore->refreshProjectRange({startframe, endframe});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Delete subtitle"));
return;
}
......@@ -571,11 +571,11 @@ public:
/** @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 */
Q_INVOKABLE void shiftSubtitle(int oldStartFrame, int newStartFrame, int endFrame=0, QString text="");
Q_INVOKABLE void shiftSubtitle(int oldStartFrame, int newStartFrame, int endFrame=0, QString text = QString());
/** @brief Add subtitle clip at cursor's position in timeline */
Q_INVOKABLE void addSubtitle();
/** @brief Delete subtitle clip with frame as start position*/
Q_INVOKABLE void deleteSubtitle(int frame);
Q_INVOKABLE void deleteSubtitle(int frameframe, int endframe, QString Ctext);
public slots:
void resetView();
......
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