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

Automatically update subtitle text when changing focus.

Fixes #935
parent efda2dc3
......@@ -48,6 +48,11 @@ bool ShiftEnterFilter::eventFilter(QObject *obj, QEvent *event)
return true;
}
}
if (event->type() == QEvent::FocusOut)
{
emit triggerUpdate();
return true;
}
return QObject::eventFilter(obj, event);
}
......@@ -69,10 +74,14 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
subText->installEventFilter(keyFilter);
connect(keyFilter, &ShiftEnterFilter::triggerUpdate, this, &SubtitleEdit::updateSubtitle);
connect(subText, &KTextEdit::textChanged, [this]() {
buttonApply->setEnabled(true);
if (m_activeSub > -1) {
buttonApply->setEnabled(true);
}
});
connect(subText, &KTextEdit::cursorPositionChanged, [this]() {
buttonCut->setEnabled(true);
if (m_activeSub > -1) {
buttonCut->setEnabled(true);
}
});
m_position = new TimecodeDisplay(pCore->timecode(), this);
......@@ -91,9 +100,7 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
spacer = new QSpacerItem(1, 1, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
duration_box->addSpacerItem(spacer);
connect(m_position, &TimecodeDisplay::timeCodeEditingFinished, [this] (int value) {
if (buttonApply->isEnabled()) {
updateSubtitle();
}
updateSubtitle();
if (buttonLock->isChecked()) {
// Perform a move instead of a resize
m_model->requestSubtitleMove(m_activeSub, GenTime(value, pCore->getCurrentFps()));
......@@ -103,9 +110,7 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
}
});
connect(m_endPosition, &TimecodeDisplay::timeCodeEditingFinished, [this] (int value) {
if (buttonApply->isEnabled()) {
updateSubtitle();
}
updateSubtitle();
if (buttonLock->isChecked()) {
// Perform a move instead of a resize
m_model->requestSubtitleMove(m_activeSub, GenTime(value, pCore->getCurrentFps()) - (m_endPos - m_startPos));
......@@ -115,9 +120,7 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
}
});
connect(m_duration, &TimecodeDisplay::timeCodeEditingFinished, [this] (int value) {
if (buttonApply->isEnabled()) {
updateSubtitle();
}
updateSubtitle();
m_model->requestResize(m_activeSub, value, true);
});
connect(buttonAdd, &QToolButton::clicked, this, [this]() {
......@@ -126,9 +129,7 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
connect(buttonCut, &QToolButton::clicked, this, [this]() {
if (m_activeSub > -1 && subText->hasFocus()) {
int pos = subText->textCursor().position();
if (buttonApply->isEnabled()) {
updateSubtitle();
}
updateSubtitle();
emit cutSubtitle(m_activeSub, pos);
}
});
......@@ -174,6 +175,10 @@ void SubtitleEdit::setModel(std::shared_ptr<SubtitleModel> model)
void SubtitleEdit::updateSubtitle()
{
if (!buttonApply->isEnabled()) {
return;
}
buttonApply->setEnabled(false);
if (m_activeSub > -1 && m_model) {
QString txt = subText->toPlainText().trimmed();
txt.replace(QLatin1String("\n\n"), QStringLiteral("\n"));
......
......@@ -44,6 +44,10 @@ Item {
if (!selected && isGrabbed) {
//timeline.grabCurrent()
}
if (subtitleBase.textEditBegin) {
// End editing on focus change
subtitleBase.textEditBegin = false
}
}
function grabItem() {
......
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