Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Kdenlive
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
259
Issues
259
List
Boards
Labels
Service Desk
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Multimedia
Kdenlive
Commits
ca2c198e
Commit
ca2c198e
authored
Nov 20, 2020
by
Jean-Baptiste Mardelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Subtitles: when cutting from subtitle widget, split text at cursor position
parent
6e639f6a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
16 deletions
+78
-16
src/bin/model/subtitlemodel.cpp
src/bin/model/subtitlemodel.cpp
+4
-9
src/bin/model/subtitlemodel.hpp
src/bin/model/subtitlemodel.hpp
+2
-3
src/core.cpp
src/core.cpp
+5
-0
src/dialogs/subtitleedit.cpp
src/dialogs/subtitleedit.cpp
+15
-2
src/dialogs/subtitleedit.h
src/dialogs/subtitleedit.h
+1
-0
src/timeline2/view/timelinecontroller.cpp
src/timeline2/view/timelinecontroller.cpp
+42
-2
src/timeline2/view/timelinecontroller.h
src/timeline2/view/timelinecontroller.h
+2
-0
src/ui/editsub_ui.ui
src/ui/editsub_ui.ui
+7
-0
No files found.
src/bin/model/subtitlemodel.cpp
View file @
ca2c198e
...
...
@@ -396,12 +396,12 @@ bool SubtitleModel::setText(int id, const QString text)
QString
oldText
=
m_subtitleList
.
at
(
start
).
first
;
m_subtitleList
[
start
].
first
=
text
;
Fun
local_redo
=
[
this
,
start
,
end
,
text
]()
{
editSubtitle
(
start
,
text
,
end
);
editSubtitle
(
start
,
text
);
pCore
->
refreshProjectRange
({
start
.
frames
(
pCore
->
getCurrentFps
()),
end
.
frames
(
pCore
->
getCurrentFps
())});
return
true
;
};
Fun
local_undo
=
[
this
,
start
,
end
,
oldText
]()
{
editSubtitle
(
start
,
oldText
,
end
);
editSubtitle
(
start
,
oldText
);
pCore
->
refreshProjectRange
({
start
.
frames
(
pCore
->
getCurrentFps
()),
end
.
frames
(
pCore
->
getCurrentFps
())});
return
true
;
};
...
...
@@ -641,19 +641,14 @@ bool SubtitleModel::requestResize(int id, int size, bool right, Fun &undo, Fun &
return
true
;
}
void
SubtitleModel
::
editSubtitle
(
GenTime
startPos
,
QString
newSubtitleText
,
GenTime
endPos
)
void
SubtitleModel
::
editSubtitle
(
GenTime
startPos
,
QString
newSubtitleText
)
{
if
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
<
0
||
endPos
.
frames
(
pCore
->
getCurrentFps
())
<
0
)
{
if
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
<
0
)
{
qDebug
()
<<
"Time error: is negative"
;
return
;
}
if
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
>
endPos
.
frames
(
pCore
->
getCurrentFps
()))
{
qDebug
()
<<
"Time error: start should be less than end"
;
return
;
}
qDebug
()
<<
"Editing existing subtitle in model"
;
m_subtitleList
[
startPos
].
first
=
newSubtitleText
;
m_subtitleList
[
startPos
].
second
=
endPos
;
int
id
=
getIdForStartPos
(
startPos
);
qDebug
()
<<
startPos
.
frames
(
pCore
->
getCurrentFps
())
<<
m_subtitleList
[
startPos
].
first
<<
m_subtitleList
[
startPos
].
second
.
frames
(
pCore
->
getCurrentFps
());
int
row
=
m_timeline
->
getSubtitleIndex
(
id
);
...
...
src/bin/model/subtitlemodel.hpp
View file @
ca2c198e
...
...
@@ -83,12 +83,11 @@ public:
bool
requestResize
(
int
id
,
int
size
,
bool
right
);
bool
requestResize
(
int
id
,
int
size
,
bool
right
,
Fun
&
undo
,
Fun
&
redo
,
bool
logUndo
);
/** @brief Edit subtitle
, i.e. text and/or end time
/** @brief Edit subtitle
text
@param startPos is start timing position of subtitles
@param newSubtitleText is (new) subtitle text
@param endPos defines the (new) position of the end time
*/
void
editSubtitle
(
GenTime
startPos
,
QString
newSubtitleText
,
GenTime
endPos
);
void
editSubtitle
(
GenTime
startPos
,
QString
newSubtitleText
);
/** @brief Remove subtitle at start position (pos) */
bool
removeSubtitle
(
int
id
,
bool
temporary
=
false
);
...
...
src/core.cpp
View file @
ca2c198e
...
...
@@ -193,6 +193,11 @@ void Core::initGUI(const QUrl &Url, const QString &clipsToLoad)
m_mainWindow
->
getCurrentTimeline
()
->
controller
()
->
addSubtitle
();
}
});
connect
(
m_subtitleWidget
,
&
SubtitleEdit
::
cutSubtitle
,
[
this
](
int
id
,
int
cursorPos
)
{
if
(
m_guiConstructed
&&
m_mainWindow
->
getCurrentTimeline
()
->
controller
())
{
m_mainWindow
->
getCurrentTimeline
()
->
controller
()
->
cutSubtitle
(
id
,
cursorPos
);
}
});
// Producer queue, creating MLT::Producers on request
/*
...
...
src/dialogs/subtitleedit.cpp
View file @
ca2c198e
...
...
@@ -61,12 +61,16 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
setupUi
(
this
);
buttonApply
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"dialog-ok-apply"
)));
buttonAdd
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"list-add"
)));
buttonCut
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"edit-cut"
)));
auto
*
keyFilter
=
new
ShiftEnterFilter
(
this
);
subText
->
installEventFilter
(
keyFilter
);
connect
(
keyFilter
,
&
ShiftEnterFilter
::
triggerUpdate
,
this
,
&
SubtitleEdit
::
updateSubtitle
);
connect
(
subText
,
&
QPlainTextEdit
::
textChanged
,
[
this
]()
{
buttonApply
->
setEnabled
(
true
);
});
connect
(
subText
,
&
QPlainTextEdit
::
cursorPositionChanged
,
[
this
]()
{
buttonCut
->
setEnabled
(
true
);
});
m_position
=
new
TimecodeDisplay
(
pCore
->
timecode
(),
this
);
m_endPosition
=
new
TimecodeDisplay
(
pCore
->
timecode
(),
this
);
...
...
@@ -99,6 +103,14 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
m_model
->
requestResize
(
m_activeSub
,
value
,
true
);
});
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
;
emit
cutSubtitle
(
m_activeSub
,
pos
);
}
});
connect
(
buttonApply
,
&
QToolButton
::
clicked
,
this
,
&
SubtitleEdit
::
updateSubtitle
);
connect
(
buttonPrev
,
&
QToolButton
::
clicked
,
this
,
&
SubtitleEdit
::
goToPrevious
);
connect
(
buttonNext
,
&
QToolButton
::
clicked
,
this
,
&
SubtitleEdit
::
goToNext
);
...
...
@@ -110,6 +122,7 @@ void SubtitleEdit::setModel(std::shared_ptr<SubtitleModel> model)
m_activeSub
=
-
1
;
subText
->
setEnabled
(
false
);
buttonApply
->
setEnabled
(
false
);
buttonCut
->
setEnabled
(
false
);
if
(
m_model
==
nullptr
)
{
QSignalBlocker
bk
(
subText
);
subText
->
clear
();
...
...
@@ -134,9 +147,10 @@ void SubtitleEdit::updateSubtitle()
void
SubtitleEdit
::
setActiveSubtitle
(
int
id
)
{
m_activeSub
=
id
;
buttonApply
->
setEnabled
(
false
);
buttonCut
->
setEnabled
(
false
);
if
(
m_model
&&
id
>
-
1
)
{
subText
->
setEnabled
(
true
);
buttonApply
->
setEnabled
(
false
);
QSignalBlocker
bk
(
subText
);
m_position
->
setEnabled
(
true
);
m_endPosition
->
setEnabled
(
true
);
...
...
@@ -153,7 +167,6 @@ void SubtitleEdit::setActiveSubtitle(int id)
m_duration
->
setValue
(
duration
);
}
else
{
subText
->
setEnabled
(
false
);
buttonApply
->
setEnabled
(
false
);
m_position
->
setEnabled
(
false
);
m_endPosition
->
setEnabled
(
false
);
m_duration
->
setEnabled
(
false
);
...
...
src/dialogs/subtitleedit.h
View file @
ca2c198e
...
...
@@ -75,6 +75,7 @@ private:
signals:
void
addSubtitle
();
void
cutSubtitle
(
int
id
,
int
cursorPos
);
};
#endif
src/timeline2/view/timelinecontroller.cpp
View file @
ca2c198e
...
...
@@ -1449,6 +1449,46 @@ void TimelineController::cutClipUnderCursor(int position, int track)
}
}
void
TimelineController
::
cutSubtitle
(
int
id
,
int
cursorPos
)
{
qDebug
()
<<
"== READY TO CUT AT: "
<<
cursorPos
;
Q_ASSERT
(
m_model
->
isSubTitle
(
id
));
if
(
cursorPos
<=
0
)
{
return
requestClipCut
(
id
,
-
1
);
}
// Cut subtitle at edit position
int
timelinePos
=
pCore
->
getTimelinePosition
();
GenTime
position
(
timelinePos
,
pCore
->
getCurrentFps
());
GenTime
start
=
m_model
->
m_allSubtitles
.
at
(
id
);
auto
subtitleModel
=
pCore
->
getSubtitleModel
();
SubtitledTime
subData
=
subtitleModel
->
getSubtitle
(
start
);
if
(
position
>
start
&&
position
<
subData
.
end
())
{
QString
originalText
=
subData
.
subtitle
();
QString
firstText
=
originalText
;
QString
secondText
=
originalText
;
firstText
.
truncate
(
cursorPos
);
secondText
.
remove
(
0
,
originalText
.
length
()
-
cursorPos
);
Fun
undo
=
[]()
{
return
true
;
};
Fun
redo
=
[]()
{
return
true
;
};
bool
res
=
subtitleModel
->
cutSubtitle
(
timelinePos
,
undo
,
redo
);
qDebug
()
<<
"== DO CUT SUCCESS: "
<<
res
;
if
(
res
)
{
Fun
local_redo
=
[
subtitleModel
,
start
,
position
,
firstText
,
secondText
]()
{
subtitleModel
->
editSubtitle
(
start
,
firstText
);
subtitleModel
->
editSubtitle
(
position
,
secondText
);
return
true
;
};
Fun
local_undo
=
[
subtitleModel
,
start
,
originalText
]()
{
subtitleModel
->
editSubtitle
(
start
,
originalText
);
return
true
;
};
local_redo
();
UPDATE_UNDO_REDO_NOLOCK
(
local_redo
,
local_undo
,
undo
,
redo
);
pCore
->
pushUndo
(
undo
,
redo
,
i18n
(
"Cut clip"
));
}
}
}
void
TimelineController
::
cutAllClipsUnderCursor
(
int
position
)
{
if
(
position
==
-
1
)
{
...
...
@@ -3753,12 +3793,12 @@ void TimelineController::editSubtitle(int startFrame, int endFrame, QString newT
}
auto
subtitleModel
=
pCore
->
getSubtitleModel
();
Fun
local_redo
=
[
subtitleModel
,
startFrame
,
endFrame
,
newText
]()
{
subtitleModel
->
editSubtitle
(
GenTime
(
startFrame
,
pCore
->
getCurrentFps
()),
newText
,
GenTime
(
endFrame
,
pCore
->
getCurrentFps
())
);
subtitleModel
->
editSubtitle
(
GenTime
(
startFrame
,
pCore
->
getCurrentFps
()),
newText
);
pCore
->
refreshProjectRange
({
startFrame
,
endFrame
});
return
true
;
};
Fun
local_undo
=
[
subtitleModel
,
startFrame
,
endFrame
,
oldText
]()
{
subtitleModel
->
editSubtitle
(
GenTime
(
startFrame
,
pCore
->
getCurrentFps
()),
oldText
,
GenTime
(
endFrame
,
pCore
->
getCurrentFps
())
);
subtitleModel
->
editSubtitle
(
GenTime
(
startFrame
,
pCore
->
getCurrentFps
()),
oldText
);
pCore
->
refreshProjectRange
({
startFrame
,
endFrame
});
return
true
;
};
...
...
src/timeline2/view/timelinecontroller.h
View file @
ca2c198e
...
...
@@ -572,6 +572,8 @@ public:
Q_INVOKABLE
void
resizeSubtitle
(
int
startFrame
,
int
endFrame
,
int
oldEndFrame
,
bool
refreshModel
);
/** @brief Add subtitle clip at cursor's position in timeline */
Q_INVOKABLE
void
addSubtitle
(
int
startframe
=
-
1
);
/** @brief Cut a subtitle and split the text at @param pos */
void
cutSubtitle
(
int
id
,
int
cursorPos
);
/** @brief Delete subtitle clip with frame as start position*/
Q_INVOKABLE
void
deleteSubtitle
(
int
frameframe
,
int
endframe
,
QString
Ctext
);
/** @brief Import a subtitle file*/
...
...
src/ui/editsub_ui.ui
View file @
ca2c198e
...
...
@@ -74,6 +74,13 @@
</property>
</widget>
</item>
<item>
<widget
class=
"QToolButton"
name=
"buttonCut"
>
<property
name=
"text"
>
<string>
...
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QToolButton"
name=
"buttonApply"
>
<property
name=
"text"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment