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