[vlmc-devel] main.qml: Fix sortSelectedClips

Yikai Lu git at videolan.org
Mon Aug 7 19:18:39 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Tue Aug  8 01:42:06 2017 +0900| [84447c7f6c35c1796992a191841d39eeccf8f739] | committer: Yikai Lu

main.qml: Fix sortSelectedClips

We should take deltaTrackId and deltaPos explicitly because they affect the result of sorting.

> https://code.videolan.org/videolan/vlmc/commit/84447c7f6c35c1796992a191841d39eeccf8f739
---

 src/Gui/timeline/Clip.qml  |  2 +-
 src/Gui/timeline/Track.qml | 14 ++++++++------
 src/Gui/timeline/main.qml  | 14 +++++++-------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/Gui/timeline/Clip.qml b/src/Gui/timeline/Clip.qml
index 89cb32cc..d48ccf9a 100644
--- a/src/Gui/timeline/Clip.qml
+++ b/src/Gui/timeline/Clip.qml
@@ -361,7 +361,7 @@ Rectangle {
             if ( resizing === true && isCutMode === false )
                 resize();
             else if ( dragArea.drag.active )
-                dragFinished();
+                dragFinished( newTrackId - trackId, position - lastPosition );
         }
 
         states: [
diff --git a/src/Gui/timeline/Track.qml b/src/Gui/timeline/Track.qml
index e8226624..9880b956 100644
--- a/src/Gui/timeline/Track.qml
+++ b/src/Gui/timeline/Track.qml
@@ -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] );
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index c801939a..79f9f595 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -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



More information about the Vlmc-devel mailing list