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

Fix subtitle resize undo

parent 36d1198e
Pipeline #40125 passed with stage
in 10 minutes and 22 seconds
......@@ -58,7 +58,6 @@ void SubtitleModel::setup()
connect(this, &SubtitleModel::rowsRemoved, this, &SubtitleModel::modelChanged);
connect(this, &SubtitleModel::rowsInserted, this, &SubtitleModel::modelChanged);
connect(this, &SubtitleModel::modelReset, this, &SubtitleModel::modelChanged);
connect(this, &SubtitleModel::dataChanged, this, &SubtitleModel::modelChanged);
}
std::shared_ptr<SubtitleModel> SubtitleModel::getModel()
......@@ -365,7 +364,7 @@ void SubtitleModel::addSnapPoint(GenTime startpos)
std::swap(m_regSnaps, validSnapModels);
}
void SubtitleModel::editEndPos(GenTime startPos, GenTime newEndPos)
void SubtitleModel::editEndPos(GenTime startPos, GenTime newEndPos, bool refreshModel)
{
qDebug()<<"Changing the sub end timings in model";
auto model = getModel();
......@@ -375,9 +374,12 @@ void SubtitleModel::editEndPos(GenTime startPos, GenTime newEndPos)
}
int row = static_cast<int>(std::distance(model->m_subtitleList.begin(), model->m_subtitleList.find(startPos)));
model->m_subtitleList[startPos].second = newEndPos;
emit model->dataChanged(model->index(row), model->index(row), QVector<int>() << EndPosRole);
// Trigger update of the qml view
emit model->dataChanged(model->index(row), model->index(row), QVector<int>() << EndFrameRole);
if (refreshModel) {
emit modelChanged();
}
qDebug()<<startPos.frames(pCore->getCurrentFps())<<m_subtitleList[startPos].second.frames(pCore->getCurrentFps());
return;
}
void SubtitleModel::editSubtitle(GenTime startPos, QString newSubtitleText, GenTime endPos)
......@@ -397,6 +399,7 @@ void SubtitleModel::editSubtitle(GenTime startPos, QString newSubtitleText, GenT
model->m_subtitleList[startPos].second = endPos;
qDebug()<<startPos.frames(pCore->getCurrentFps())<<m_subtitleList[startPos].first<<m_subtitleList[startPos].second.frames(pCore->getCurrentFps());
emit model->dataChanged(model->index(row), model->index(row), QVector<int>() << SubtitleRole);
emit modelChanged();
return;
}
......
......@@ -72,7 +72,7 @@ public:
@param oldPos is the old position of the end time
@param pos defines the new position of the end time
*/
void editEndPos(GenTime startPos, GenTime newEndPos);
void editEndPos(GenTime startPos, GenTime newEndPos, bool refreshModel = true);
/** @brief Edit subtitle , i.e. text and/or end time
@param startPos is start timing position of subtitles
......
......@@ -117,21 +117,20 @@ Item {
padding: 0
}
}
Rectangle {
Item {
id: leftstart
width: 2
width: root.baseUnit / 2
height: subtitleBase.height
x: model.startframe * timeScale;
anchors.top: subtitleBase.top
anchors.left: subtitleBase.left
color: 'green'
visible: true
MouseArea {
// Right resize handle to change end timing
id: startMouseArea
anchors.fill: parent
height: parent.height
width: 2
width: root.baseUnit / 2
hoverEnabled: true
enabled: true
property bool sizeChanged: false
......@@ -155,6 +154,7 @@ Item {
//console.log(subtitleBase.x)
originalDuration = subtitleBase.width/timeScale
console.log("originalDuration",originalDuration)
trimIn.opacity = 0
}
onPositionChanged: {
if (pressed) {
......@@ -191,17 +191,34 @@ Item {
timeline.moveSubtitle(oldStartFrame/timeline.scaleFactor , oldStartFrame/timeline.scaleFactor + delta, subtitleBase.duration)
}
}
onEntered: {
if (!pressed) {
trimIn.opacity = 1
}
}
onExited: trimIn.opacity = 0
Rectangle {
id: trimIn
anchors.left: parent.left
width: 2
height: parent.height
color: 'lawngreen'
opacity: 0
Drag.active: startMouseArea.drag.active
Drag.proposedAction: Qt.MoveAction
//visible: startMouseArea.pressed
}
}
}
Rectangle {
Item {
// end position resize handle
id: rightend
width: 2
width: root.baseUnit / 2
height: subtitleBase.height
x: model.endframe * timeScale;
anchors.right: subtitleBase.right
anchors.top: subtitleBase.top
color: 'blue' // to distinguish the resize handle
//Drag.active: endMouseArea.drag.active
//Drag.proposedAction: Qt.MoveAction
visible: true
......@@ -213,37 +230,65 @@ Item {
hoverEnabled: true
enabled: true
property bool sizeChanged: false
property int newEnd: -1
property int oldMouseX
acceptedButtons: Qt.LeftButton
cursorShape: Qt.SizeHorCursor
property int newDuration: subtitleRoot.duration
property int originalDuration
drag.target: rightend
drag.axis: Drag.XAxis
//drag.smoothed: false
onPressed: {
root.autoScrolling = false
newDuration = subtitleRoot.duration
originalDuration = subtitleRoot.duration
//rightend.anchors.right = undefined
oldMouseX = mouseX
trimOut.opacity = 0
}
onPositionChanged: {
if (pressed) {
newEnd = Math.round((mouseX + width) / timeScale)
if ((mouseX != oldMouseX && duration > 1) || (duration <= 1 && mouseX > oldMouseX)) {
sizeChanged = true
//duration = subtitleBase.width + (mouseX - oldMouseX)/ timeline.scaleFactor
duration = Math.round((subtitleBase.width/timeScale + (mouseX - oldMouseX)/timeScale))
newDuration = Math.round((subtitleBase.width/timeScale + (mouseX - oldMouseX)/timeScale))
// Perform resize without changing model
timeline.resizeSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + newDuration, subtitleBase.x / timeline.scaleFactor + subtitleRoot.duration, false)
}
}
}
onReleased: {
root.autoScrolling = timeline.autoScroll
rightend.anchors.right = subtitleBase.right
console.log(' GOT RESIZE: ', newDuration, ' > ', originalDuration)
if (mouseX != oldMouseX || sizeChanged) {
timeline.resizeSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + duration, subtitleBase.x / timeline.scaleFactor + subtitleBase.duration)
// Restore original size
timeline.resizeSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + subtitleRoot.duration, subtitleBase.x / timeline.scaleFactor + newDuration, false)
// Perform real resize
timeline.resizeSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + newDuration, subtitleBase.x / timeline.scaleFactor + originalDuration, true)
sizeChanged = false
}
}
onEntered: {
console.log('ENTER MOUSE END AREA')
if (!pressed) {
trimOut.opacity = 1
}
}
onExited: trimOut.opacity = 0
Rectangle {
id: trimOut
anchors.right: parent.right
width: 2
height: parent.height
color: 'red'
opacity: 0
Drag.active: endMouseArea.drag.active
Drag.proposedAction: Qt.MoveAction
//visible: endMouseArea.pressed
}
}
}
}
......@@ -3740,23 +3740,25 @@ void TimelineController::editSubtitle(int startFrame, int endFrame, QString newT
pCore->pushUndo(local_undo, local_redo, i18n("Edit subtitle"));
}
void TimelineController::resizeSubtitle(int startFrame, int endFrame, int oldEndFrame)
void TimelineController::resizeSubtitle(int startFrame, int endFrame, int oldEndFrame, bool refreshModel)
{
qDebug()<<"Editing existing subtitle in controller at:"<<startFrame;
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
int max = qMax(endFrame, oldEndFrame);
Fun local_redo = [subtitleModel, startFrame, endFrame, max]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(endFrame, pCore->getCurrentFps()));
Fun local_redo = [subtitleModel, startFrame, endFrame, max, refreshModel]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(endFrame, pCore->getCurrentFps()), refreshModel);
pCore->refreshProjectRange({startFrame, max});
return true;
};
Fun local_undo = [subtitleModel, startFrame, oldEndFrame, max]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(oldEndFrame, pCore->getCurrentFps()));
Fun local_undo = [subtitleModel, startFrame, oldEndFrame, max, refreshModel]() {
subtitleModel->editEndPos(GenTime(startFrame, pCore->getCurrentFps()), GenTime(oldEndFrame, pCore->getCurrentFps()), refreshModel);
pCore->refreshProjectRange({startFrame, max});
return true;
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Resize subtitle"));
if (refreshModel) {
pCore->pushUndo(local_undo, local_redo, i18n("Resize subtitle"));
}
}
void TimelineController::moveSubtitle(int oldStartFrame, int newStartFrame, int duration)
......
......@@ -569,7 +569,7 @@ public:
/** @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);
Q_INVOKABLE void resizeSubtitle(int startFrame, int endFrame, int oldEndFrame, bool refreshModel);
/** @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