[vlmc-devel] Timeline: Save selected clips as uuids

Yikai Lu git at videolan.org
Mon Jul 10 18:31:32 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Jul 10 22:17:23 2017 +0900| [20c03ca8ff8dd406f17c44a45a6b12ab3f78282e] | committer: Yikai Lu

Timeline: Save selected clips as uuids

> https://code.videolan.org/videolan/vlmc/commit/20c03ca8ff8dd406f17c44a45a6b12ab3f78282e
---

 src/Gui/timeline/Clip.qml            | 19 ++++++++++---------
 src/Gui/timeline/ClipContextMenu.qml | 10 +++++-----
 src/Gui/timeline/Track.qml           | 13 +++++++------
 src/Gui/timeline/main.qml            | 17 +++++++++++------
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/src/Gui/timeline/Clip.qml b/src/Gui/timeline/Clip.qml
index 89890e6b..34188617 100644
--- a/src/Gui/timeline/Clip.qml
+++ b/src/Gui/timeline/Clip.qml
@@ -72,7 +72,7 @@ Rectangle {
             return false;
         for ( var i = 0; i < selectedClips.length; ++i ) {
             for ( var j = i + 1; j < selectedClips.length; ++j ) {
-                if ( selectedClips[i].linkedClips.indexOf( selectedClips[j].uuid ) === -1 )
+                if ( findClipItem( selectedClips[i] ).linkedClips.indexOf( selectedClips[j] ) === -1 )
                     return false;
             }
         }
@@ -169,23 +169,24 @@ Rectangle {
     }
 
     onSelectedChanged: {
-        for ( var i = 0; i < selectedClips.length; ++i )
-            if ( !selectedClips[i] || selectedClips[i] === clip ) {
-                selectedClips.splice( i, 1 );
-                --i;
-            }
-
         if ( selected === true ) {
-            selectedClips.push( clip );
+            selectedClips.push( uuid );
 
             var group = findGroup( uuid );
-            for ( i = 0; i < ( group ? group.length : 0 ); ++i ) {
+            for ( var i = 0; i < ( group ? group.length : 0 ); ++i ) {
                 var clipItem = findClipItem( group[i] );
                 if ( clipItem )
                     clipItem.selected = true;
             }
             selectLinkedClip();
         }
+        else
+            for ( i = 0; i < selectedClips.length; ++i )
+                if ( selectedClips[i] === uuid ) {
+                    selectedClips.splice( i, 1 );
+                    --i;
+                    break;
+                }
     }
 
     Component.onCompleted: {
diff --git a/src/Gui/timeline/ClipContextMenu.qml b/src/Gui/timeline/ClipContextMenu.qml
index c3af4f24..59bd9788 100644
--- a/src/Gui/timeline/ClipContextMenu.qml
+++ b/src/Gui/timeline/ClipContextMenu.qml
@@ -23,7 +23,7 @@ Menu {
             else {
                 var l = [];
                 for ( var i = 0; i < selectedClips.length; ++i ) {
-                    l.push( "" + selectedClips[i].uuid );
+                    l.push( "" + selectedClips[i] );
                 }
                 addGroup( l );
             }
@@ -38,16 +38,16 @@ Menu {
             if ( linked === true ) {
                 for ( var i = 0; i < selectedClips.length; ++i ) {
                     for ( var j = i + 1; j < selectedClips.length; ++j ) {
-                        if ( selectedClips[i].linkedClips.indexOf( selectedClips[j].uuid ) !== -1 )
-                            workflow.unlinkClips( selectedClips[i].uuid, selectedClips[j].uuid );
+                        if ( findClipItem( selectedClips[i] ).linkedClips.indexOf( selectedClips[j] ) !== -1 )
+                            workflow.unlinkClips( selectedClips[i], selectedClips[j] );
                     }
                 }
             }
             else {
                 for ( i = 0; i < selectedClips.length; ++i ) {
                     for ( j = i + 1; j < selectedClips.length; ++j ) {
-                        if ( selectedClips[i].linkedClips.indexOf( selectedClips[j].uuid ) === -1 )
-                            workflow.linkClips( selectedClips[i].uuid, selectedClips[j].uuid );
+                        if (findClipItem( selectedClips[i] ).linkedClips.indexOf( selectedClips[j] ) === -1 )
+                            workflow.linkClips( selectedClips[i], selectedClips[j] );
                     }
                 }
             }
diff --git a/src/Gui/timeline/Track.qml b/src/Gui/timeline/Track.qml
index 26bb7c0a..df1c7bcc 100644
--- a/src/Gui/timeline/Track.qml
+++ b/src/Gui/timeline/Track.qml
@@ -196,21 +196,22 @@ Item {
                 else
                     dMode = dropMode.Move;
 
-                var toMove = [];
-                for ( var i = 0; i < selectedClips.length; ++i )
-                    toMove.push( selectedClips[i].uuid );
+                var toMove = selectedClips.concat();
 
                 if ( dMode === dropMode.Move ) {
                     // Prepare newTrackId for all the selected clips
-                    for ( i = 0; i < toMove.length; ++i ) {
+                    for ( var 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 ) {
-                                if ( drag.source !== selectedClips[j] )
-                                    selectedClips[j].newTrackId = Math.max( 0, trackId - oldTrackId + selectedClips[j].trackId );
+                                if ( drag.source.uuid !== selectedClips[j] )
+                                {
+                                    var clip = findClipItem( selectedClips[j] );
+                                    clip.newTrackId = Math.max( 0, trackId - oldTrackId + clip.trackId );
+                                }
                             }
                         }
                         // Let's move to the new tracks
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index c55fd8bb..d1e04ff8 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -19,7 +19,7 @@ Rectangle {
     property int scale: 4
     property var allClips: [] // Actual clip item objects
     property var allClipsDict: ({}) // Actual clip item objects
-    property var selectedClips: [] // Actual clip item objects
+    property var selectedClips: [] // Selected clip uuids
     property var groups: [] // list of lists of clip uuids
     property var linkedClipsDict: ({}) // Uuid
     property alias isMagneticMode: magneticModeButton.selected
@@ -29,7 +29,7 @@ Rectangle {
 
     function clearSelectedClips() {
         while ( selectedClips.length ) {
-            var clip = selectedClips.pop();
+            var clip = findClipItem( selectedClips.pop() );
             if ( clip )
                 clip.selected = false;
         }
@@ -299,8 +299,10 @@ Rectangle {
         // Workaround: We cannot sort selectedClips directly maybe because of a Qt bug
         var sorted = selectedClips.slice();
         sorted.sort(
-                    function( clipA, clipB )
+                    function( clipAUuid, clipBUuid )
                     {
+                        var clipA = findClipItem( clipAUuid );
+                        var clipB = findClipItem( clipBUuid );
                         if ( clipA.newTrackId > clipA.trackId )
                         {
                             return - ( clipA.newTrackId - clipB.newTrackId );
@@ -320,7 +322,6 @@ Rectangle {
                         return 0;
                     }
                     );
-        selectedClips = sorted;
     }
 
     function dragFinished() {
@@ -330,7 +331,10 @@ Rectangle {
         // I'm aware that it's not the best solution but it's the safest solution for sure
         var toMove = [];
         for ( var i = 0; i < selectedClips.length; ++i )
-            toMove.push( [selectedClips[i].uuid, selectedClips[i].newTrackId, selectedClips[i].position] );
+        {
+            var clip = findClipItem( selectedClips[i] );
+            toMove.push( [clip.uuid, clip.newTrackId, clip.position] );
+        }
         for ( i = 0; i < toMove.length; ++i )
             workflow.moveClip( toMove[i][0], toMove[i][1], toMove[i][2] );
 
@@ -581,7 +585,8 @@ Rectangle {
         icon: StandardIcon.Question
         standardButtons: StandardButton.Yes | StandardButton.No
         onYes: {
-            workflow.removeClip( selectedClips[0].uuid );
+            while ( selectedClips.length > 0 )
+                workflow.removeClip( selectedClips[0] );
         }
     }
 



More information about the Vlmc-devel mailing list