[vlmc-devel] main.qml: Separate the sorting part of dragFinished

Yikai Lu git at videolan.org
Sat Jul 1 14:55:04 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sat Jul  1 21:17:18 2017 +0900| [9ea9b5134ce11a4355ebc3274cba04211170b2e6] | committer: Yikai Lu

main.qml: Separate the sorting part of dragFinished

As we want to use it in onPositionChanged also

> https://code.videolan.org/videolan/vlmc/commit/9ea9b5134ce11a4355ebc3274cba04211170b2e6
---

 src/Gui/timeline/Track.qml |  2 +-
 src/Gui/timeline/main.qml  | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/Gui/timeline/Track.qml b/src/Gui/timeline/Track.qml
index dcbe16cf..6c617c16 100644
--- a/src/Gui/timeline/Track.qml
+++ b/src/Gui/timeline/Track.qml
@@ -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 );
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index 1cbe711d..77ad6b70 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -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" );



More information about the Vlmc-devel mailing list