Commit a4ec2cdb authored by luyikei's avatar luyikei

Timeline: Stop if any of selected clips collides

parent f9f71f78
...@@ -222,10 +222,31 @@ Item { ...@@ -222,10 +222,31 @@ Item {
var oldTrackId = drag.source.newTrackId; var oldTrackId = drag.source.newTrackId;
drag.source.newTrackId = trackId; drag.source.newTrackId = trackId;
// Check if there is any impossible move
for ( var i = 0; i < toMove.length; ++i ) { for ( var i = 0; i < toMove.length; ++i ) {
var target = findClipItem( toMove[i] ); var target = findClipItem( toMove[i] );
if ( target !== drag.source ) { if ( target !== drag.source ) {
target.newTrackId = Math.max( 0, trackId - oldTrackId + target.trackId ); var newTrackId = trackId - oldTrackId + target.trackId;
if ( newTrackId < 0 )
{
drag.source.newTrackId = oldTrackId;
drag.source.setPixelPosition( drag.source.pixelPosition() );
// Direction depends on its type
drag.source.y +=
drag.source.type === "Video"
? -( trackHeight * ( oldTrackId - trackId ) )
: trackHeight * ( oldTrackId - trackId )
return;
}
}
}
for ( i = 0; i < toMove.length; ++i ) {
target = findClipItem( toMove[i] );
if ( target !== drag.source ) {
newTrackId = trackId - oldTrackId + target.trackId;
target.newTrackId = Math.max( 0, newTrackId );
if ( target.newTrackId !== target.trackId ) { if ( target.newTrackId !== target.trackId ) {
// Let's move to the new tracks // Let's move to the new tracks
target.clipInfo["selected"] = true; target.clipInfo["selected"] = true;
...@@ -266,39 +287,49 @@ Item { ...@@ -266,39 +287,49 @@ Item {
// And if newX collides again, we don't move // And if newX collides again, we don't move
if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 ) if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 )
newX = oldX; deltaX = 0
else
deltaX = newX - oldX;
} }
else else
newX = oldX; deltaX = 0;
}
// We only want to update the length when the left edge of the timeline
// is exposed.
if ( sView.flickableItem.contentX + page.width > sView.width &&
length < ptof( newX + linkedClipItem.width ) ) {
length = ptof( newX + linkedClipItem.width );
} }
else
deltaX = newX - oldX;
linkedClipItem.setPixelPosition( newX );
var ind = toMove.indexOf( linkedClipItem.uuid ); var ind = toMove.indexOf( linkedClipItem.uuid );
if ( ind > 0 ) if ( ind > 0 )
toMove.splice( ind, 1 ); toMove.splice( ind, 1 );
} }
} }
newX = oldX + deltaX;
toMove.splice( 0, 1 );
}
// END of while ( toMove.length > 0 )
if ( deltaX === 0 && dMode === dropMode.Move ) {
drag.source.setPixelPosition( drag.source.pixelPosition() );
return;
}
for ( i = 0; i < selectedClips.length; ++i ) {
target = findClipItem( selectedClips[i] );
newX = target.pixelPosition() + deltaX;
// We only want to update the length when the left edge of the timeline
// is exposed.
if ( sView.flickableItem.contentX + page.width > sView.width && if ( sView.flickableItem.contentX + page.width > sView.width &&
length < ptof( newX + target.width ) ) { length < ptof( newX + target.width ) ) {
length = ptof( newX + target.width ); length = ptof( newX + target.width );
} }
target.setPixelPosition( newX ); target.setPixelPosition( newX );
toMove.splice( 0, 1 );
// Scroll if needed // Scroll if needed
if ( drag.source === target || dMode === dropMode.New ) if ( drag.source === target || dMode === dropMode.New )
target.scrollToThis(); target.scrollToThis();
} }
// END of while ( toMove.length > 0 )
if ( dMode === dropMode.Move ) if ( dMode === dropMode.Move )
lastX = drag.source.x; lastX = drag.source.x;
......
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