[vlmc-devel] Timeline: Imeplement grouping

Yikai Lu git at videolan.org
Tue Jul 19 19:41:57 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Wed Jul 20 02:40:35 2016 +0900| [48a5ba616cc7967b8260f671d547c266fd9ad271] | committer: Yikai Lu

Timeline: Imeplement grouping

> https://code.videolan.org/videolan/vlmc/commit/48a5ba616cc7967b8260f671d547c266fd9ad271
---

 src/Gui/timeline/Clip.qml            | 26 +++++++++++++++++++++++---
 src/Gui/timeline/ClipContextMenu.qml | 34 +++++++++++++++++-----------------
 src/Gui/timeline/main.qml            | 34 +++++++++++++++++++++++++++++++---
 3 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/Gui/timeline/Clip.qml b/src/Gui/timeline/Clip.qml
index 73e4c35..161da21 100644
--- a/src/Gui/timeline/Clip.qml
+++ b/src/Gui/timeline/Clip.qml
@@ -84,11 +84,19 @@ Rectangle {
     Component.onCompleted: {
         selected = true;
         newTrackId = trackId;
+        allClips.push( clip );
     }
 
     Component.onDestruction: {
         Drag.drop();
         selected = false;
+
+        for ( var i = 0; i < allClips.length; ++i ) {
+            if ( allClips[i] === clip ) {
+                allClips.splice( i, 1 );
+                return;
+            }
+        }
     }
 
     Text {
@@ -165,8 +173,7 @@ Rectangle {
 
         onClicked: {
             if ( mouse.button & Qt.RightButton ) {
-                var menu = Qt.createComponent( "ClipContextMenu.qml" ).createObject( parent );
-                menu.popup();
+                clipContextMenu.popup();
             }
         }
 
@@ -196,6 +203,11 @@ Rectangle {
         ]
     }
 
+    ClipContextMenu {
+        id: clipContextMenu
+        uuid: clip.uuid
+    }
+
     onYChanged: {
         // Don't move outside its TrackContainer
         // For Top
@@ -210,9 +222,17 @@ Rectangle {
     onSelectedChanged: {
         if ( selected === true ) {
             selectedClips.push( clip );
+
+            var group = findGroup( uuid );
+            for ( var i = 0; i < ( group ? group.length : 0 ); ++i ) {
+                for ( var j = 0; j < allClips.length; ++j ) {
+                    if ( group[i] === allClips[j].uuid )
+                        allClips[j].selected = true;
+                }
+            }
         }
         else {
-            for ( var i = 0; i < selectedClips.length; ++i )
+            for ( i = 0; i < selectedClips.length; ++i )
                 if ( !selectedClips[i] || selectedClips[i] === clip ) {
                     selectedClips.splice( i, 1 );
                     --i;
diff --git a/src/Gui/timeline/ClipContextMenu.qml b/src/Gui/timeline/ClipContextMenu.qml
index 87c832e..3e9fdc3 100644
--- a/src/Gui/timeline/ClipContextMenu.qml
+++ b/src/Gui/timeline/ClipContextMenu.qml
@@ -5,28 +5,28 @@ Menu {
     id: clipContextMenu
     title: "Edit"
 
-    MenuItem {
-        text: "Cut"
-        shortcut: "Ctrl+X"
-    }
-
-    MenuItem {
-        text: "Copy"
-        shortcut: "Ctrl+C"
-    }
+    property string uuid
 
     MenuItem {
-        text: "Paste"
-        shortcut: "Ctrl+V"
-    }
+        text: isGrouped ? "Ungroup" : "Group"
 
-    MenuSeparator { }
+        property bool isGrouped: findGroup( uuid )
 
-    Menu {
-        title: "More Stuff"
+        onTriggered: {
+            if ( selectedClips.length <= 1 )
+                return;
 
-        MenuItem {
-            text: "Do Nothing"
+            if ( isGrouped ) {
+                removeGroup( uuid );
+            }
+            else {
+                var l = [];
+                for ( var i = 0; i < selectedClips.length; ++i ) {
+                    l.push( "" + selectedClips[i].uuid );
+                }
+                addGroup( l );
+            }
+            isGrouped = Qt.binding( function(){ return findGroup( uuid ); } );
         }
     }
 }
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index 28c0c75..5d8bbb5 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -17,7 +17,9 @@ Rectangle {
     property double fps: 29.97
     property int maxZ: 100
     property int scale: 10
-    property var selectedClips: []
+    property var allClips: [] // Actual clip item objects
+    property var selectedClips: [] // Actual clip item objects
+    property var groups: [] // list of lists of clip uuids
     property alias isMagneticMode: magneticModeButton.selected
 
     property int trackHeight: 30
@@ -182,13 +184,39 @@ Rectangle {
             addTrack( trackType );
     }
 
-    function addMarker( pos )
-    {
+    function addMarker( pos ) {
         markers.append( {
                            "position": pos
                        } );
     }
 
+    function addGroup( clips ) {
+        groups.push( clips );
+    }
+
+    function findGroup( uuid ) {
+        for ( var i = 0; i < groups.length; ++i ) {
+            var group = groups[i];
+            for ( var j = 0; j < group.length; ++j ) {
+                if ( group[j] === uuid )
+                    return group;
+            }
+        }
+        return null;
+    }
+
+    function removeGroup( uuid ) {
+        for ( var i = 0; i < groups.length; ++i ) {
+            var group = groups[i];
+            for ( var j = 0; j < group.length; ++j ) {
+                if ( group[j] === uuid ) {
+                    groups.splice( i, 1 );
+                    return;
+                }
+            }
+        }
+    }
+
     function zoomIn( ratio ) {
         var newPpu = ppu;
         var newUnit = unit;



More information about the Vlmc-devel mailing list