Commit 9ea9b513 authored by luyikei's avatar luyikei

main.qml: Separate the sorting part of dragFinished

As we want to use it in onPositionChanged also
parent 2dc58b49
......@@ -242,12 +242,12 @@ Item {
else
deltaX = drag.x - lastX;
sortSelectedClips();
var alreadyCalculated = []; // Uuids of clips being already set new x position.
for ( i = 0; i < selectedClips.length; ++i ) {
target = selectedClips[i];
var uuid = target.uuid;
if ( alreadyCalculated.indexOf( uuid ) < 0 ) {
var oldX = target.pixelPosition();
var newX = Math.max( oldX + deltaX, 0 );
......
......@@ -292,16 +292,18 @@ Rectangle {
mainwindow.setScale( scale );
}
function dragFinished() {
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(
// Sort clips in a manner that clips won't overlap each other while they are being moved
function sortSelectedClips() {
// Workaround: We cannot sort selectedClips directly maybe because of a Qt bug
var sorted = selectedClips.slice();
sorted.sort(
function( clipA, clipB )
{
if ( clipA.newTrackId !== clipB.newTrackId )
if ( clipA.newTrackId > clipA.trackId )
{
return - ( clipA.newTrackId - clipB.newTrackId );
}
else if ( clipA.newTrackId < clipA.trackId )
{
return clipA.newTrackId - clipB.newTrackId;
}
......@@ -309,15 +311,22 @@ Rectangle {
{
return - ( clipA.position - clipB.position );
}
else if ( clipA.position < clipA.position )
else if ( clipA.position < clipA.lastPosition )
{
return clipA.position - clipB.position;
}
};
return 0;
}
);
selectedClips = sorted;
}
for ( i = 0; i < toMove.length; ++i )
moveClipTo( toMove[i].uuid, toMove[i].newTrackId, toMove[i].position );
function dragFinished() {
sortSelectedClips();
for ( var i = 0; i < selectedClips.length; ++i )
{
moveClipTo( selectedClips[i].uuid, selectedClips[i].newTrackId, selectedClips[i].position );
}
adjustTracks( "Audio" );
adjustTracks( "Video" );
......
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