Commit 84447c7f authored by luyikei's avatar luyikei

main.qml: Fix sortSelectedClips

We should take deltaTrackId and deltaPos explicitly because they affect the result of sorting.
parent 2092f0e3
......@@ -361,7 +361,7 @@ Rectangle {
if ( resizing === true && isCutMode === false )
resize();
else if ( dragArea.drag.active )
dragFinished();
dragFinished( newTrackId - trackId, position - lastPosition );
}
states: [
......
......@@ -132,10 +132,9 @@ Item {
if ( dMode === dropMode.Move )
drag.source.scrollToThis();
sortSelectedClips();
var toMove = selectedClips.concat();
if ( dMode === dropMode.Move ) {
deltaPos = ptof( drag.source.x ) - lastPos;
// Move to the top
drag.source.parent.parent.z = ++maxZ;
......@@ -143,6 +142,9 @@ Item {
var oldTrackId = drag.source.newTrackId;
drag.source.newTrackId = trackId;
sortSelectedClips( trackId - oldTrackId ,deltaPos );
var toMove = selectedClips.concat();
// Check if there is any impossible move
for ( var i = 0; i < toMove.length; ++i ) {
var target = findClipItem( toMove[i] );
......@@ -176,11 +178,11 @@ Item {
}
}
}
deltaPos = ptof( drag.source.x ) - lastPos;
}
else
else {
toMove = selectedClips.concat();
deltaPos = ptof( drag.x ) - lastPos;
}
while ( toMove.length > 0 ) {
target = findClipItem( toMove[0] );
......
......@@ -376,7 +376,7 @@ Rectangle {
}
// Sort clips in a manner that clips won't overlap each other while they are being moved
function sortSelectedClips() {
function sortSelectedClips( deltaTrackId, deltaPos ) {
// Workaround: We cannot sort selectedClips directly maybe because of a Qt bug
var sorted = selectedClips.concat();
sorted.sort(
......@@ -384,19 +384,19 @@ Rectangle {
{
var clipA = findClipItem( clipAUuid );
var clipB = findClipItem( clipBUuid );
if ( clipA.newTrackId > clipA.trackId )
if ( deltaTrackId > 0 )
{
return - ( clipA.newTrackId - clipB.newTrackId );
}
else if ( clipA.newTrackId < clipA.trackId )
else if ( deltaTrackId < 0 )
{
return clipA.newTrackId - clipB.newTrackId;
}
else if ( clipA.position > clipA.lastPosition )
else if ( deltaPos > 0 )
{
return - ( clipA.position - clipB.position );
}
else if ( clipA.position < clipA.lastPosition )
else if ( deltaPos < 0 )
{
return clipA.position - clipB.position;
};
......@@ -406,9 +406,9 @@ Rectangle {
selectedClips = sorted;
}
function dragFinished() {
function dragFinished( deltaTrackId, deltaPos ) {
dragging = false;
sortSelectedClips();
sortSelectedClips( deltaTrackId, deltaPos );
// We don't want to rely on selectedClips while moving since it "will" be changed
// I'm aware that it's not the best solution but it's the safest solution for sure
......
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