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