Allow moving subtitle through subtitle widget

parent 69ca3d75
......@@ -688,6 +688,22 @@ void SubtitleModel::removeAllSubtitles()
}
}
void SubtitleModel::requestSubtitleMove(int clipId, GenTime position)
{
GenTime oldPos = getStartPosForId(clipId);
Fun local_redo = [this, clipId, position]() {
return moveSubtitle(clipId, position, true, true);
};
Fun local_undo = [this, clipId, oldPos]() {
return moveSubtitle(clipId, oldPos, true, true);
};
bool res = local_redo();
if (res) {
pCore->pushUndo(local_undo, local_redo, i18n("Move subtitle"));
}
}
bool SubtitleModel::moveSubtitle(int subId, GenTime newPos, bool updateModel, bool updateView)
{
qDebug()<<"Moving Subtitle";
......
......@@ -103,6 +103,7 @@ public:
@param newPos is new start position of subtitle
*/
bool moveSubtitle(int subId, GenTime newPos, bool updateModel, bool updateView);
void requestSubtitleMove(int clipId, GenTime position);
/** @brief Function that imports a subtitle file */
void importSubtitle(const QString filePath, int offset = 0, bool externalImport = false);
......
......@@ -65,6 +65,7 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
buttonIn->setIcon(QIcon::fromTheme(QStringLiteral("zone-in")));
buttonOut->setIcon(QIcon::fromTheme(QStringLiteral("zone-out")));
buttonDelete->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
buttonLock->setIcon(QIcon::fromTheme(QStringLiteral("kdenlive-lock")));
auto *keyFilter = new ShiftEnterFilter(this);
subText->installEventFilter(keyFilter);
connect(keyFilter, &ShiftEnterFilter::triggerUpdate, this, &SubtitleEdit::updateSubtitle);
......@@ -95,15 +96,25 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
if (buttonApply->isEnabled()) {
updateSubtitle();
}
GenTime duration = m_endPos - GenTime(value, pCore->getCurrentFps());
m_model->requestResize(m_activeSub, duration.frames(pCore->getCurrentFps()), false);
if (buttonLock->isChecked()) {
// Perform a move instead of a resize
m_model->requestSubtitleMove(m_activeSub, GenTime(value, pCore->getCurrentFps()));
} else {
GenTime duration = m_endPos - GenTime(value, pCore->getCurrentFps());
m_model->requestResize(m_activeSub, duration.frames(pCore->getCurrentFps()), false);
}
});
connect(m_endPosition, &TimecodeDisplay::timeCodeEditingFinished, [this] (int value) {
if (buttonApply->isEnabled()) {
updateSubtitle();
}
GenTime duration = GenTime(value, pCore->getCurrentFps()) - m_startPos;
m_model->requestResize(m_activeSub, duration.frames(pCore->getCurrentFps()), true);
if (buttonLock->isChecked()) {
// Perform a move instead of a resize
m_model->requestSubtitleMove(m_activeSub, GenTime(value, pCore->getCurrentFps()) - (m_endPos - m_startPos));
} else {
GenTime duration = GenTime(value, pCore->getCurrentFps()) - m_startPos;
m_model->requestResize(m_activeSub, duration.frames(pCore->getCurrentFps()), true);
}
});
connect(m_duration, &TimecodeDisplay::timeCodeEditingFinished, [this] (int value) {
if (buttonApply->isEnabled()) {
......@@ -113,10 +124,11 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
});
connect(buttonAdd, &QToolButton::clicked, this, &SubtitleEdit::addSubtitle);
connect(buttonCut, &QToolButton::clicked, [this]() {
qDebug()<<"=== READY TO CUT SUB";
if (m_activeSub > -1 && subText->hasFocus()) {
int pos = subText->textCursor().position();
qDebug()<<"=== READY TO CUT SUB AT : "<<pos;
if (buttonApply->isEnabled()) {
updateSubtitle();
}
emit cutSubtitle(m_activeSub, pos);
}
});
......
......@@ -2236,22 +2236,9 @@ bool TimelineModel::requestGroupMove(int itemId, int groupId, int delta_track, i
Fun undo_subs = []() { return true; };
// Move subtitles
if (!sorted_subtitles.empty()) {
GenTime deltaTime(delta_pos, pCore->getCurrentFps());
redo_subs = [this, deltaTime, sorted_subtitles, finalMove, updateView]() {
for (auto &item : sorted_subtitles) {
m_subtitleModel->moveSubtitle(item.first, item.second + deltaTime, finalMove, updateView);
}
return true;
};
undo_subs = [this, sorted_subtitles, finalMove, updateView]() {
for (auto &item : sorted_subtitles) {
m_subtitleModel->moveSubtitle(item.first, item.second, finalMove, updateView);
}
return true;
};
redo_subs();
PUSH_LAMBDA(redo_subs, local_redo);
PUSH_LAMBDA(undo_subs, local_undo);
for (auto &item : sorted_subtitles) {
requestSubtitleMove(item.first, item.second.frames(pCore->getCurrentFps()) + delta_pos, updateView, finalMove, finalMove, local_undo, local_redo);
}
}
// Check if there is a track move
......
......@@ -80,9 +80,6 @@
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<layout class="QHBoxLayout" name="duration_box"/>
</item>
<item row="4" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
......@@ -133,6 +130,22 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QToolButton" name="buttonLock">
<property name="text">
<string>...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<layout class="QHBoxLayout" name="duration_box"/>
</item>
</layout>
</widget>
<resources/>
......
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