Commit 0667503b authored by luyikei's avatar luyikei

Timeline: Move clips in a manner that clips won't overlap each other.

parent 0171c988
...@@ -27,6 +27,7 @@ Rectangle { ...@@ -27,6 +27,7 @@ Rectangle {
// Usualy it is trackId, the clip will be moved to the new track immediately. // Usualy it is trackId, the clip will be moved to the new track immediately.
property int newTrackId property int newTrackId
property int position property int position
property int lastPosition
property int begin property int begin
property int end property int end
property string libraryUuid // Library UUID: For thumbnails property string libraryUuid // Library UUID: For thumbnails
...@@ -52,7 +53,7 @@ Rectangle { ...@@ -52,7 +53,7 @@ Rectangle {
} }
function move() { function move() {
moveClipTo( track.type, uuid, newTrackId, position ); moveClipTo( uuid, newTrackId, position );
} }
function resize() { function resize() {
......
...@@ -340,6 +340,7 @@ Item { ...@@ -340,6 +340,7 @@ Item {
uuid: model.uuid uuid: model.uuid
libraryUuid: model.libraryUuid libraryUuid: model.libraryUuid
position: model.position position: model.position
lastPosition: model.lastPosition
begin: model.begin begin: model.begin
end: model.end end: model.end
linkedClip: model.linkedClip linkedClip: model.linkedClip
......
...@@ -90,6 +90,7 @@ Rectangle { ...@@ -90,6 +90,7 @@ Rectangle {
newDict["begin"] = clipDict["begin"]; newDict["begin"] = clipDict["begin"];
newDict["end"] = clipDict["end"]; newDict["end"] = clipDict["end"];
newDict["position"] = clipDict["position"]; newDict["position"] = clipDict["position"];
newDict["lastPosition"] = clipDict["position"];
newDict["length"] = clipDict["length"]; newDict["length"] = clipDict["length"];
newDict["libraryUuid"] = clipDict["libraryUuid"]; newDict["libraryUuid"] = clipDict["libraryUuid"];
newDict["uuid"] = clipDict["uuid"]; newDict["uuid"] = clipDict["uuid"];
...@@ -172,7 +173,7 @@ Rectangle { ...@@ -172,7 +173,7 @@ Rectangle {
return null; return null;
} }
function moveClipTo( trackType, uuid, trackId, position ) function moveClipTo( uuid, trackId, position )
{ {
var clip = findClipItem( uuid ); var clip = findClipItem( uuid );
if ( !clip ) if ( !clip )
...@@ -293,7 +294,32 @@ Rectangle { ...@@ -293,7 +294,32 @@ Rectangle {
} }
function dragFinished() { function dragFinished() {
selectedClips[0].move(); var toMove = [];
for ( var i = 0; i < selectedClips.length; ++i )
toMove.push( selectedClips[i] );
// Move clips in a manner that clips won't overlap each other.
toMove.sort(
function( clipA, clipB )
{
if ( clipA.newTrackId !== clipB.newTrackId )
{
return clipA.newTrackId - clipB.newTrackId;
}
else if ( clipA.position > clipA.lastPosition )
{
return - ( clipA.position - clipB.position );
}
else if ( clipA.position < clipA.position )
{
return clipA.position - clipB.position;
}
}
);
for ( i = 0; i < toMove.length; ++i )
moveClipTo( toMove[i].uuid, toMove[i].newTrackId, toMove[i].position );
adjustTracks( "Audio" ); adjustTracks( "Audio" );
adjustTracks( "Video" ); adjustTracks( "Video" );
} }
...@@ -592,9 +618,8 @@ Rectangle { ...@@ -592,9 +618,8 @@ Rectangle {
addClip( type, clipInfo["trackId"], clipInfo ); addClip( type, clipInfo["trackId"], clipInfo );
removeClipFromTrack( type, oldClip["trackId"], uuid ); removeClipFromTrack( type, oldClip["trackId"], uuid );
} }
else if ( oldClip["position"] !== clipInfo["position"] ) { findClipItem( uuid ).position = clipInfo["position"];
findClipItem( uuid ).position = clipInfo["position"]; findClipItem( uuid ).lastPosition = clipInfo["position"];
}
adjustTracks( type ); adjustTracks( type );
} }
......
...@@ -115,8 +115,7 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos ) ...@@ -115,8 +115,7 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos )
c->pos = pos; c->pos = pos;
} }
emit clipMoved( uuid.toString() ); emit clipMoved( uuid.toString() );
// TODO: If we detect collision too strictly, there will be a problem if we want to move multiple // CAUTION: You must not move a clip to a place where it would overlap another clip!
// clips at the same time.
return true; return true;
} }
......
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