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
787f822c
Commit
787f822c
authored
May 18, 2020
by
Jean-Baptiste Mardelle
Browse files
Fix insert drag affecting all tracks, and fix snapping on insert/overwrite drag
Related to
#673
parent
5e52a8de
Pipeline
#20439
passed with stage
in 9 minutes and 39 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/timeline2/model/clipmodel.cpp
View file @
787f822c
...
...
@@ -93,9 +93,9 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
return
id
;
}
void
ClipModel
::
allSnaps
(
std
::
vector
<
int
>
&
snaps
)
void
ClipModel
::
allSnaps
(
std
::
vector
<
int
>
&
snaps
,
int
offset
)
{
m_clipMarkerModel
->
allSnaps
(
snaps
);
m_clipMarkerModel
->
allSnaps
(
snaps
,
offset
);
}
int
ClipModel
::
construct
(
const
std
::
shared_ptr
<
TimelineModel
>
&
parent
,
const
QString
&
binClipId
,
const
std
::
shared_ptr
<
Mlt
::
Producer
>
&
producer
,
...
...
src/timeline2/model/clipmodel.hpp
View file @
787f822c
...
...
@@ -108,7 +108,7 @@ public:
QDomElement
toXml
(
QDomDocument
&
document
);
/* @brief Retrieve a list of all snaps for this clip */
void
allSnaps
(
std
::
vector
<
int
>
&
snaps
);
void
allSnaps
(
std
::
vector
<
int
>
&
snaps
,
int
offset
=
0
);
protected:
// helper functions that creates the lambda
...
...
src/timeline2/model/clipsnapmodel.cpp
View file @
787f822c
...
...
@@ -89,17 +89,17 @@ void ClipSnapModel::removeAllSnaps()
}
}
void
ClipSnapModel
::
allSnaps
(
std
::
vector
<
int
>
&
snaps
)
void
ClipSnapModel
::
allSnaps
(
std
::
vector
<
int
>
&
snaps
,
int
offset
)
{
snaps
.
push_back
(
m_position
);
snaps
.
push_back
(
m_position
-
offset
);
if
(
auto
ptr
=
m_registeredSnap
.
lock
())
{
for
(
const
auto
&
snap
:
m_snapPoints
)
{
if
(
snap
>=
m_inPoint
*
m_speed
&&
snap
<
m_outPoint
*
m_speed
)
{
snaps
.
push_back
(
m_speed
<
0
?
ceil
(
m_outPoint
+
m_position
+
snap
/
m_speed
-
m_inPoint
)
:
ceil
(
m_position
+
snap
/
m_speed
-
m_inPoint
));
snaps
.
push_back
(
m_speed
<
0
?
ceil
(
m_outPoint
+
m_position
+
snap
/
m_speed
-
m_inPoint
-
offset
)
:
ceil
(
m_position
+
snap
/
m_speed
-
m_inPoint
-
offset
));
}
}
}
snaps
.
push_back
(
m_position
+
m_outPoint
-
m_inPoint
+
1
);
snaps
.
push_back
(
m_position
+
m_outPoint
-
m_inPoint
+
1
-
offset
);
}
void
ClipSnapModel
::
registerSnapModel
(
const
std
::
weak_ptr
<
SnapModel
>
&
snapModel
,
int
position
,
int
in
,
int
out
,
double
speed
)
...
...
src/timeline2/model/clipsnapmodel.hpp
View file @
787f822c
...
...
@@ -54,7 +54,7 @@ public:
void
updateSnapModelPos
(
int
newPos
);
void
updateSnapModelInOut
(
std
::
pair
<
int
,
int
>
newInOut
);
/* @brief Retrieve all snap points */
void
allSnaps
(
std
::
vector
<
int
>
&
snaps
);
void
allSnaps
(
std
::
vector
<
int
>
&
snaps
,
int
offset
=
0
);
private:
...
...
src/timeline2/model/timelinefunctions.cpp
View file @
787f822c
...
...
@@ -414,7 +414,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
bool
result
=
true
;
QVector
<
int
>
affectedTracks
;
auto
it
=
timeline
->
m_allTracks
.
cbegin
();
if
(
!
useTargets
&&
overwrite
)
{
if
(
!
useTargets
)
{
// Timeline drop in overwrite mode
for
(
int
target_track
:
trackIds
)
{
if
(
!
timeline
->
getTrackById_const
(
target_track
)
->
isLocked
())
{
...
...
@@ -424,7 +424,7 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
}
else
{
while
(
it
!=
timeline
->
m_allTracks
.
cend
())
{
int
target_track
=
(
*
it
)
->
getId
();
if
(
!
useTargets
||
timeline
->
getTrackById_const
(
target_track
)
->
shouldReceiveTimelineOp
())
{
if
(
timeline
->
getTrackById_const
(
target_track
)
->
shouldReceiveTimelineOp
())
{
affectedTracks
<<
target_track
;
}
else
if
(
trackIds
.
contains
(
target_track
))
{
// Track is marked as target but not active, remove it
...
...
src/timeline2/model/timelinemodel.cpp
View file @
787f822c
...
...
@@ -640,11 +640,6 @@ bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, b
QWriteLocker
locker
(
&
m_lock
);
TRACE
(
clipId
,
trackId
,
position
,
updateView
,
logUndo
,
invalidateTimeline
)
Q_ASSERT
(
m_allClips
.
count
(
clipId
)
>
0
);
if
(
m_allClips
[
clipId
]
->
getPosition
()
==
position
&&
m_allClips
[
clipId
]
->
getFakeTrackId
()
==
trackId
)
{
TRACE_RES
(
true
);
qDebug
()
<<
"........
\n
ABORTING MOVE; SAME POS/TRACK
\n
.........."
;
return
true
;
}
if
(
m_groups
->
isInGroup
(
clipId
))
{
// element is in a group.
int
groupId
=
m_groups
->
getRootId
(
clipId
);
...
...
@@ -738,20 +733,21 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
TRACE
(
clipId
,
trackId
,
position
,
cursorPosition
,
snapDistance
);
Q_ASSERT
(
isClip
(
clipId
));
Q_ASSERT
(
isTrack
(
trackId
));
int
currentPos
=
getClipPosition
(
clipId
);
int
currentPos
=
m_editMode
==
TimelineMode
::
NormalEdit
?
getClipPosition
(
clipId
)
:
m_allClips
[
clipId
]
->
getFakePosition
();
int
offset
=
m_editMode
==
TimelineMode
::
NormalEdit
?
0
:
getClipPosition
(
clipId
)
-
currentPos
;
int
sourceTrackId
=
(
m_editMode
!=
TimelineMode
::
NormalEdit
)
?
m_allClips
[
clipId
]
->
getFakeTrackId
()
:
getClipTrackId
(
clipId
);
if
(
sourceTrackId
>
-
1
&&
getTrackById_const
(
trackId
)
->
isAudioTrack
()
!=
getTrackById_const
(
sourceTrackId
)
->
isAudioTrack
())
{
// Trying move on incompatible track type, stay on same track
trackId
=
sourceTrackId
;
}
if
(
currentPos
==
position
&&
m_editMode
==
TimelineMode
::
NormalEdit
&&
sourceTrackId
==
trackId
)
{
if
(
currentPos
==
position
&&
sourceTrackId
==
trackId
)
{
TRACE_RES
(
position
);
return
{
position
,
trackId
};
}
bool
after
=
position
>
currentPos
;
if
(
snapDistance
>
0
)
{
// For snapping, we must ignore all in/outs of the clips of the group being moved
std
::
vector
<
int
>
ignored_pts
;
// For snapping, we must ignore all in/outs of the clips of the group being moved
std
::
unordered_set
<
int
>
all_items
=
{
clipId
};
if
(
m_groups
->
isInGroup
(
clipId
))
{
int
groupId
=
m_groups
->
getRootId
(
clipId
);
...
...
@@ -760,17 +756,16 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
for
(
int
current_clipId
:
all_items
)
{
if
(
getItemTrackId
(
current_clipId
)
!=
-
1
)
{
if
(
isClip
(
current_clipId
))
{
m_allClips
[
current_clipId
]
->
allSnaps
(
ignored_pts
);
m_allClips
[
current_clipId
]
->
allSnaps
(
ignored_pts
,
offset
);
}
else
{
// Composition
int
in
=
getItemPosition
(
current_clipId
);
int
in
=
getItemPosition
(
current_clipId
)
-
offset
;
ignored_pts
.
push_back
(
in
);
ignored_pts
.
push_back
(
in
+
getItemPlaytime
(
current_clipId
));
}
}
}
int
snapped
=
getBestSnapPos
(
currentPos
,
position
-
currentPos
,
m_editMode
==
TimelineMode
::
NormalEdit
?
ignored_pts
:
std
::
vector
<
int
>
(),
cursorPosition
,
snapDistance
);
int
snapped
=
getBestSnapPos
(
currentPos
,
position
-
currentPos
,
ignored_pts
,
cursorPosition
,
snapDistance
);
// qDebug() << "Starting suggestion " << clipId << position << currentPos << "snapped to " << snapped;
if
(
snapped
>=
0
)
{
position
=
snapped
;
...
...
@@ -779,9 +774,6 @@ QVariantList TimelineModel::suggestClipMove(int clipId, int trackId, int positio
// we check if move is possible
bool
possible
=
(
m_editMode
==
TimelineMode
::
NormalEdit
)
?
requestClipMove
(
clipId
,
trackId
,
position
,
moveMirrorTracks
,
true
,
false
,
false
)
:
requestFakeClipMove
(
clipId
,
trackId
,
position
,
true
,
false
,
false
);
/*} else {
possible = requestClipMoveAttempt(clipId, trackId, position);
}*/
if
(
possible
)
{
TRACE_RES
(
position
);
if
(
m_editMode
!=
TimelineMode
::
NormalEdit
)
{
...
...
@@ -2906,7 +2898,9 @@ int TimelineModel::suggestSnapPoint(int pos, int snapDistance)
int
TimelineModel
::
getBestSnapPos
(
int
referencePos
,
int
diff
,
std
::
vector
<
int
>
pts
,
int
cursorPosition
,
int
snapDistance
)
{
if
(
!
pts
.
empty
())
{
m_snaps
->
ignore
(
pts
);
if
(
m_editMode
==
TimelineMode
::
NormalEdit
)
{
m_snaps
->
ignore
(
pts
);
}
}
else
{
return
-
1
;
}
...
...
@@ -2927,7 +2921,9 @@ int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> p
}
}
}
m_snaps
->
unIgnore
();
if
(
m_editMode
==
TimelineMode
::
NormalEdit
)
{
m_snaps
->
unIgnore
();
}
m_snaps
->
removePoint
(
cursorPosition
);
return
closest
;
}
...
...
src/timeline2/view/timelinecontroller.cpp
View file @
787f822c
...
...
@@ -2861,7 +2861,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView,
// There is a clip, cut
res
=
res
&&
TimelineFunctions
::
requestClipCut
(
m_model
,
startClipId
,
position
,
undo
,
redo
);
}
res
=
res
&&
TimelineFunctions
::
requestInsertSpace
(
m_model
,
QPoint
(
position
,
position
+
duration
),
undo
,
redo
);
res
=
res
&&
TimelineFunctions
::
requestInsertSpace
(
m_model
,
QPoint
(
position
,
position
+
duration
),
undo
,
redo
,
{
currentTrack
}
);
}
res
=
res
&&
m_model
->
getTrackById
(
trackId
)
->
requestClipInsertion
(
clipId
,
position
,
updateView
,
invalidateTimeline
,
undo
,
redo
);
if
(
res
)
{
...
...
@@ -2968,7 +2968,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
}
}
}
else
if
(
m_model
->
m_editMode
==
TimelineMode
::
InsertEdit
)
{
Q
List
<
int
>
processedTracks
;
Q
Vector
<
int
>
processedTracks
;
for
(
int
item
:
sorted_clips
)
{
int
target_track
=
new_track_ids
[
item
];
if
(
processedTracks
.
contains
(
target_track
))
{
...
...
@@ -2983,7 +2983,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
res
=
res
&&
TimelineFunctions
::
requestClipCut
(
m_model
,
startClipId
,
target_position
,
undo
,
redo
);
}
}
res
=
res
&&
TimelineFunctions
::
requestInsertSpace
(
m_model
,
QPoint
(
min
,
max
),
undo
,
redo
);
res
=
res
&&
TimelineFunctions
::
requestInsertSpace
(
m_model
,
QPoint
(
min
,
max
),
undo
,
redo
,
processedTracks
);
}
for
(
int
item
:
sorted_clips
)
{
if
(
m_model
->
isClip
(
item
))
{
...
...
Write
Preview
Supports
Markdown
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