[vlmc-devel] Track.qml: Don't access selectedClips directly while moving clips

Yikai Lu git at videolan.org
Thu Jul 6 14:12:14 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Thu Jul  6 19:30:21 2017 +0900| [54302a9a52b0fdd31e8810b9f855b941f53b82ac] | committer: Yikai Lu

Track.qml: Don't access selectedClips directly while moving clips

Because selectedClips could be changed on the operation

> https://code.videolan.org/videolan/vlmc/commit/54302a9a52b0fdd31e8810b9f855b941f53b82ac
---

 src/Gui/timeline/Track.qml | 112 +++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 59 deletions(-)

diff --git a/src/Gui/timeline/Track.qml b/src/Gui/timeline/Track.qml
index f3f3369c..b53d7302 100644
--- a/src/Gui/timeline/Track.qml
+++ b/src/Gui/timeline/Track.qml
@@ -196,11 +196,16 @@ Item {
                 else
                     dMode = dropMode.Move;
 
+                var toMove = [];
+                for ( var i = 0; i < selectedClips.length; ++i )
+                    toMove.push( selectedClips[i].uuid );
+
                 if ( dMode === dropMode.Move ) {
                     // Prepare newTrackId for all the selected clips
-                    for ( var i = 0; i < selectedClips.length; ++i ) {
-                        var target = selectedClips[i];
+                    for ( i = 0; i < toMove.length; ++i ) {
+                        var target = findClipItem( toMove[i] );
                         if ( drag.source === target ) {
+                            drag.source.parent.parent.z = ++maxZ;
                             var oldTrackId = target.newTrackId;
                             target.newTrackId = trackId;
                             for ( var j = 0; j < selectedClips.length; ++j ) {
@@ -208,6 +213,12 @@ Item {
                                     selectedClips[j].newTrackId = Math.max( 0, trackId - oldTrackId + selectedClips[j].trackId );
                             }
                         }
+                        // Let's move to the new tracks
+                        else if ( target.newTrackId !== target.trackId ) {
+                                target.clipInfo["selected"] = true;
+                                addClip( target.type, target.newTrackId, target.clipInfo );
+                                removeClipFromTrack( target.type, target.trackId, target.uuid );
+                        }
                     }
 
                     drag.source.scrollToThis();
@@ -227,81 +238,64 @@ 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];
+                while ( toMove.length > 0 ) {
+                    target = findClipItem( toMove[0] );
 
                     var uuid = target.uuid;
-                    if ( alreadyCalculated.indexOf( uuid ) < 0 ) {
-                        var oldX = target.pixelPosition();
-                        var newX = Math.max( oldX + deltaX, 0 );
-
-                        newX = findNewPosition( newX, target, isMagneticMode );
+                    var oldX = target.pixelPosition();
+                    var newX = findNewPosition( Math.max( oldX + deltaX, 0 ), target, isMagneticMode );
 
-                        // Let's find newX of the linked clip
-                        for ( j = 0; j < target.linkedClips.length; ++j )
-                        {
-                            var linkedClipItem = findClipItem( target.linkedClips[j] );
-
-                            if ( linkedClipItem ) {
-                                var newLinkedClipX = findNewPosition( newX, linkedClipItem, isMagneticMode );
+                    // Let's find newX of the linked clip
+                    for ( j = 0; j < target.linkedClips.length; ++j )
+                    {
+                        var linkedClipItem = findClipItem( target.linkedClips[j] );
 
-                                // If linked clip collides
-                                if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 ) {
+                        if ( linkedClipItem ) {
+                            var newLinkedClipX = findNewPosition( newX, linkedClipItem, isMagneticMode );
 
-                                    // Recalculate target's newX
-                                    // This time, don't use magnets
-                                    newX = findNewPosition( newLinkedClipX, target, false );
-                                    newLinkedClipX = findNewPosition( newX, target, false );
+                            // If linked clip collides
+                            if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 ) {
 
-                                    // And if newX collides again, we don't move
-                                    if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 )
-                                        newX = oldX;
-                                }
+                                // Recalculate target's newX
+                                // This time, don't use magnets
+                                newX = findNewPosition( newLinkedClipX, target, false );
+                                newLinkedClipX = findNewPosition( newX, target, false );
 
-                                if ( length < ptof( newX + linkedClipItem.width ) ) {
-                                    length = ptof( newX + linkedClipItem.width );
-                                }
+                                // And if newX collides again, we don't move
+                                if ( ptof( Math.abs( newLinkedClipX - newX ) ) !== 0 )
+                                    newX = oldX;
+                            }
 
-                                linkedClipItem.setPixelPosition( newX );
-                                alreadyCalculated.push( target.linkedClips[j] );
+                            if ( length < ptof( newX + linkedClipItem.width ) ) {
+                                length = ptof( newX + linkedClipItem.width );
                             }
-                        }
 
-                        if ( length < ptof( newX + target.width ) ) {
-                            length = ptof( newX + target.width );
+                            linkedClipItem.setPixelPosition( newX );
+                            var ind = toMove.indexOf( linkedClipItem.uuid );
+                            if ( ind > 0 )
+                                toMove.splice( ind, 1 );
                         }
+                    }
 
-                        // Recalculate deltaX in case of drag.source being moved
-                        if ( drag.source === target ) {
-                            if ( oldTrackId === target.newTrackId )
-                                deltaX = newX - oldX;
-                            else
-                                // Don't move other clips if drag.source's track is changed
-                                deltaX = 0;
-                        }
+                    if ( length < ptof( newX + target.width ) ) {
+                        length = ptof( newX + target.width );
+                    }
 
-                        target.setPixelPosition( newX );
-                        alreadyCalculated.push( target.uuid );
+                    // Recalculate deltaX in case of drag.source being moved
+                    if ( drag.source === target ) {
+                        if ( oldTrackId === target.newTrackId )
+                            deltaX = newX - oldX;
+                        else
+                            // Don't move other clips if drag.source's track is changed
+                            deltaX = 0;
                     }
 
+                    target.setPixelPosition( newX );
+                    toMove.splice( 0, 1 );
+
                     // Scroll if needed
                     if ( drag.source === target || dMode === dropMode.New )
                         target.scrollToThis();
-
-                    // Let's move to the new tracks
-                    if ( dMode === dropMode.Move ) {
-                        if ( target.newTrackId !== target.trackId ) {
-                            drag.source.parent.parent.z = ++maxZ;
-                            if ( drag.source.uuid !== uuid ) {
-                                target.clipInfo["selected"] = true;
-                                addClip( target.type, target.newTrackId, target.clipInfo );
-                                removeClipFromTrack( target.type, target.trackId, uuid );
-                                --i;
-                            }
-                        }
-                    }
                 }
                 // END of for ( var i = 0; i < selectedClips.length; ++i )
 



More information about the Vlmc-devel mailing list