Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
49f47704
Commit
49f47704
authored
Dec 06, 2020
by
Jean-Baptiste Mardelle
Browse files
implement subtitle track lock
parent
bd13f3b8
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/bin/model/subtitlemodel.cpp
View file @
49f47704
...
...
@@ -88,7 +88,7 @@ void SubtitleModel::importSubtitle(const QString filePath, int offset, bool exte
* turn = 1 -> Add string to timeLine
* turn > 1 -> Add string to completeLine
*/
if
(
filePath
.
isEmpty
())
if
(
filePath
.
isEmpty
()
||
isLocked
()
)
return
;
Fun
redo
=
[]()
{
return
true
;
};
Fun
undo
=
[
this
]()
{
...
...
@@ -314,6 +314,9 @@ GenTime SubtitleModel::stringtoTime(QString &str)
bool
SubtitleModel
::
addSubtitle
(
GenTime
start
,
GenTime
end
,
const
QString
str
,
Fun
&
undo
,
Fun
&
redo
,
bool
updateFilter
)
{
if
(
isLocked
())
{
return
false
;
}
int
id
=
TimelineModel
::
getNextId
();
Fun
local_redo
=
[
this
,
id
,
start
,
end
,
str
,
updateFilter
]()
{
addSubtitle
(
id
,
start
,
end
,
str
,
false
,
updateFilter
);
...
...
@@ -331,7 +334,7 @@ bool SubtitleModel::addSubtitle(GenTime start, GenTime end, const QString str, F
bool
SubtitleModel
::
addSubtitle
(
int
id
,
GenTime
start
,
GenTime
end
,
const
QString
str
,
bool
temporary
,
bool
updateFilter
)
{
if
(
start
.
frames
(
pCore
->
getCurrentFps
())
<
0
||
end
.
frames
(
pCore
->
getCurrentFps
())
<
0
)
{
if
(
start
.
frames
(
pCore
->
getCurrentFps
())
<
0
||
end
.
frames
(
pCore
->
getCurrentFps
())
<
0
||
isLocked
()
)
{
qDebug
()
<<
"Time error: is negative"
;
return
false
;
}
...
...
@@ -439,7 +442,7 @@ QString SubtitleModel::getText(int id) const
bool
SubtitleModel
::
setText
(
int
id
,
const
QString
text
)
{
if
(
m_timeline
->
m_allSubtitles
.
find
(
id
)
==
m_timeline
->
m_allSubtitles
.
end
())
{
if
(
m_timeline
->
m_allSubtitles
.
find
(
id
)
==
m_timeline
->
m_allSubtitles
.
end
()
||
isLocked
()
)
{
return
false
;
}
GenTime
start
=
m_timeline
->
m_allSubtitles
.
at
(
id
);
...
...
@@ -463,6 +466,9 @@ bool SubtitleModel::setText(int id, const QString text)
std
::
unordered_set
<
int
>
SubtitleModel
::
getItemsInRange
(
int
startFrame
,
int
endFrame
)
const
{
if
(
isLocked
())
{
return
{};
}
GenTime
startTime
(
startFrame
,
pCore
->
getCurrentFps
());
GenTime
endTime
(
endFrame
,
pCore
->
getCurrentFps
());
std
::
unordered_set
<
int
>
matching
;
...
...
@@ -490,6 +496,9 @@ void SubtitleModel::cutSubtitle(int position)
bool
SubtitleModel
::
cutSubtitle
(
int
position
,
Fun
&
undo
,
Fun
&
redo
)
{
if
(
isLocked
())
{
return
false
;
}
GenTime
pos
(
position
,
pCore
->
getCurrentFps
());
GenTime
start
=
GenTime
(
-
1
);
for
(
const
auto
&
subtitles
:
m_subtitleList
)
{
...
...
@@ -600,6 +609,9 @@ bool SubtitleModel::requestResize(int id, int size, bool right)
bool
SubtitleModel
::
requestResize
(
int
id
,
int
size
,
bool
right
,
Fun
&
undo
,
Fun
&
redo
,
bool
logUndo
)
{
if
(
isLocked
())
{
return
false
;
}
Q_ASSERT
(
m_timeline
->
m_allSubtitles
.
find
(
id
)
!=
m_timeline
->
m_allSubtitles
.
end
());
GenTime
startPos
=
m_timeline
->
m_allSubtitles
.
at
(
id
);
GenTime
endPos
=
m_subtitleList
.
at
(
startPos
).
second
;
...
...
@@ -694,6 +706,9 @@ bool SubtitleModel::requestResize(int id, int size, bool right, Fun &undo, Fun &
void
SubtitleModel
::
editSubtitle
(
GenTime
startPos
,
QString
newSubtitleText
)
{
if
(
isLocked
())
{
return
;
}
if
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
<
0
)
{
qDebug
()
<<
"Time error: is negative"
;
return
;
...
...
@@ -711,6 +726,9 @@ void SubtitleModel::editSubtitle(GenTime startPos, QString newSubtitleText)
bool
SubtitleModel
::
removeSubtitle
(
int
id
,
bool
temporary
,
bool
updateFilter
)
{
qDebug
()
<<
"Deleting subtitle in model"
;
if
(
isLocked
())
{
return
false
;
}
if
(
m_timeline
->
m_allSubtitles
.
find
(
id
)
==
m_timeline
->
m_allSubtitles
.
end
())
{
qDebug
()
<<
"No Subtitle at pos in model"
;
return
false
;
...
...
@@ -744,6 +762,9 @@ bool SubtitleModel::removeSubtitle(int id, bool temporary, bool updateFilter)
void
SubtitleModel
::
removeAllSubtitles
()
{
if
(
isLocked
())
{
return
;
}
auto
ids
=
m_timeline
->
m_allSubtitles
;
for
(
const
auto
&
p
:
ids
)
{
removeSubtitle
(
p
.
first
);
...
...
@@ -769,7 +790,7 @@ void SubtitleModel::requestSubtitleMove(int clipId, GenTime position)
bool
SubtitleModel
::
moveSubtitle
(
int
subId
,
GenTime
newPos
,
bool
updateModel
,
bool
updateView
)
{
qDebug
()
<<
"Moving Subtitle"
;
if
(
m_timeline
->
m_allSubtitles
.
count
(
subId
)
==
0
)
{
if
(
m_timeline
->
m_allSubtitles
.
count
(
subId
)
==
0
||
isLocked
()
)
{
return
false
;
}
GenTime
oldPos
=
m_timeline
->
m_allSubtitles
.
at
(
subId
);
...
...
@@ -1012,6 +1033,9 @@ int SubtitleModel::getSubtitlePlaytime(int id) const
void
SubtitleModel
::
setSelected
(
int
id
,
bool
select
)
{
if
(
isLocked
())
{
return
;
}
if
(
select
)
{
m_selected
<<
id
;
}
else
{
...
...
@@ -1040,7 +1064,15 @@ void SubtitleModel::switchDisabled()
void
SubtitleModel
::
switchLocked
()
{
m_subtitleFilter
->
set
(
"kdenlive:locked"
,
1
-
m_subtitleFilter
->
get_int
(
"kdenlive:locked"
));
bool
isLocked
=
m_subtitleFilter
->
get_int
(
"kdenlive:locked"
)
==
1
;
m_subtitleFilter
->
set
(
"kdenlive:locked"
,
isLocked
?
0
:
1
);
if
(
!
isLocked
)
{
// Clear selection
while
(
!
m_selected
.
isEmpty
())
{
int
id
=
m_selected
.
takeFirst
();
updateSub
(
id
,
{
SelectedRole
});
}
}
}
...
...
@@ -1053,3 +1085,14 @@ bool SubtitleModel::isLocked() const
{
return
m_subtitleFilter
->
get_int
(
"kdenlive:locked"
)
==
1
;
}
void
SubtitleModel
::
loadProperties
(
QMap
<
QString
,
QString
>
subProperties
)
{
QMap
<
QString
,
QString
>::
const_iterator
i
=
subProperties
.
constBegin
();
while
(
i
!=
subProperties
.
constEnd
())
{
if
(
!
i
.
value
().
isEmpty
())
{
m_subtitleFilter
->
set
(
i
.
key
().
toUtf8
().
constData
(),
i
.
value
().
toUtf8
().
constData
());
}
++
i
;
}
}
src/bin/model/subtitlemodel.hpp
View file @
49f47704
...
...
@@ -135,6 +135,8 @@ public:
bool
isDisabled
()
const
;
void
switchLocked
();
bool
isLocked
()
const
;
/** @brief Load some subtitle filter properties from file */
void
loadProperties
(
QMap
<
QString
,
QString
>
subProperties
);
public
slots
:
/** @brief Function that parses through a subtitle file */
...
...
src/effects/effectstack/model/effectstackmodel.cpp
View file @
49f47704
...
...
@@ -921,7 +921,11 @@ void EffectStackModel::importEffects(const std::weak_ptr<Mlt::Service> &service,
// Required to load master audio effects
if
(
m_ownerId
.
first
==
ObjectType
::
Master
&&
filter
->
get
(
"mlt_service"
)
==
QLatin1String
(
"avfilter.subtitles"
))
{
// A subtitle filter, update project
pCore
->
window
()
->
slotEditSubtitle
(
true
);
QMap
<
QString
,
QString
>
subProperties
;
//subProperties.insert(QStringLiteral("av.filename"), filter->get("av.filename"));
subProperties
.
insert
(
QStringLiteral
(
"disable"
),
filter
->
get
(
"disable"
));
subProperties
.
insert
(
QStringLiteral
(
"kdenlive:locked"
),
filter
->
get
(
"kdenlive:locked"
));
pCore
->
window
()
->
slotEditSubtitle
(
subProperties
);
}
else
if
(
auto
ms
=
m_masterService
.
lock
())
{
ms
->
attach
(
*
filter
.
get
());
}
...
...
src/mainwindow.cpp
View file @
49f47704
...
...
@@ -4208,7 +4208,7 @@ void MainWindow::resetSubtitles()
}
}
void
MainWindow
::
slotEditSubtitle
(
bool
loadExisting
)
void
MainWindow
::
slotEditSubtitle
(
QMap
<
QString
,
QString
>
subProperties
)
{
std
::
shared_ptr
<
SubtitleModel
>
subtitleModel
=
pCore
->
getSubtitleModel
();
if
(
subtitleModel
==
nullptr
)
{
...
...
@@ -4224,6 +4224,7 @@ void MainWindow::slotEditSubtitle(bool loadExisting)
subFile
.
copy
(
workPath
);
subtitleModel
->
parseSubtitle
(
workPath
);
}
subtitleModel
->
loadProperties
(
subProperties
);
getMainTimeline
()
->
showSubtitles
=
true
;
m_buttonSubtitleEditTool
->
setChecked
(
true
);
getMainTimeline
()
->
connectSubtitleModel
(
true
);
...
...
src/mainwindow.h
View file @
49f47704
...
...
@@ -298,7 +298,7 @@ public slots:
void
slotSwitchTimelineZone
(
bool
toggled
);
/** @brief Open the online services search dialog. */
void
slotDownloadResources
();
void
slotEditSubtitle
(
bool
loadExisting
=
false
);
void
slotEditSubtitle
(
QMap
<
QString
,
QString
>
subProperties
=
{}
);
private
slots
:
/** @brief Shows the shortcut dialog. */
...
...
src/timeline2/view/qml/SubTitle.qml
View file @
49f47704
...
...
@@ -122,6 +122,7 @@ Item {
anchors.fill
:
parent
//visible: timeScale >= 6
enabled
:
parent
.
textEditBegin
opacity
:
root
.
subtitlesDisabled
?
0.5
:
1
onEnabledChanged
:
{
if
(
enabled
)
{
selectAll
()
...
...
@@ -135,7 +136,7 @@ Item {
wrapMode
:
TextField
.
WordWrap
horizontalAlignment
:
displayText
==
text
?
TextInput
.
AlignHCenter
:
TextInput
.
AlignLeft
background
:
Rectangle
{
color
:
enabled
?
"
#fff
"
:
'
#ccccff
'
color
:
root
.
subtitlesLocked
?
"
#ff6666
"
:
enabled
?
"
#fff
"
:
'
#ccccff
'
border
{
color
:
subtitleRoot
.
selected
?
root
.
selectionColor
:
"
#000
"
width
:
2
...
...
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