Commit 6bc6637b authored by luyikei's avatar luyikei

Timeline: Make able to have multiple linked clips

parent e0130fce
......@@ -32,8 +32,7 @@ Rectangle {
property int end
property string libraryUuid // Library UUID: For thumbnails
property string uuid // Instance UUID
property string linkedClip // Uuid
property bool linked: false
property var linkedClips: [] // Uuid
property string type
property bool selected: false
......@@ -62,8 +61,25 @@ Rectangle {
}
function selectLinkedClip() {
if ( selected === true && linked === true && linkedClip )
if ( selected === false )
return;
for ( var i = 0; i < linkedClips.length; ++i )
{
var linkedClip = linkedClips[i];
findClipItem( linkedClip ).selected = true;
}
}
function linked() {
if ( selectedClips.length < 2 )
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 )
return false;
}
}
return true;
}
function updateEffects( clipInfo ) {
......@@ -80,18 +96,20 @@ Rectangle {
}
function resizeLinkedClips( oldPos, oldBegin, oldEnd ) {
if ( !linkedClip )
return;
var lc = findClipItem( linkedClip );
if ( lc === null )
return;
// Don't resize from the begining if the clips didn't shared the same begin position
if ( lc.position === oldPos ) {
lc.position = position;
lc.begin = begin;
for ( var i = 0; i < linkedClips.length; ++i )
{
var linkedClip = linkedClips[i];
var lc = findClipItem( linkedClip );
if ( lc === null )
return;
// Don't resize from the begining if the clips didn't shared the same begin position
if ( lc.position === oldPos ) {
lc.position = position;
lc.begin = begin;
}
if ( lc.end === oldEnd )
lc.end = end;
}
if ( lc.end === oldEnd )
lc.end = end;
}
onXChanged: {
......@@ -124,7 +142,6 @@ Rectangle {
position = clipInfo["position"];
begin = clipInfo["begin"];
end = clipInfo["end"];
linkedClip = clipInfo["linkedClip"];
}
onPositionChanged: {
......@@ -139,34 +156,16 @@ Rectangle {
clipInfo["end"] = end;
}
onLinkedClipChanged: {
clipInfo["linkedClip"] = linkedClip;
if ( linkedClip ) {
linked = true;
onLinkedClipsChanged: {
for ( var i = 0; i < linkedClips.length; ++i )
{
var linkedClip = linkedClips[i];
var linkedClipItem = findClipItem( linkedClip );
if ( linkedClipItem ) {
linkedClipItem.linkedClip = clip.uuid;
linkedClipItem.linked = true;
if ( linkedClipItem.linkedClips.indexOf( uuid ) !== -1 )
linkedClipItem.linkedClips.push( uuid );
}
}
else
linked = false;
}
onLinkedChanged: {
selectLinkedClip();
if ( !linkedClip )
return;
var linkedClipItem = findClipItem( linkedClip );
if ( !linkedClipItem )
return;
if ( linked === true )
linkedClipItem.linked = true;
else
linkedClipItem.linked = false;
}
onSelectedChanged: {
......@@ -190,6 +189,10 @@ Rectangle {
}
Component.onCompleted: {
for ( var i = 0; i < allClips.length; ++i ) {
if ( allClips[i].linkedClips.indexOf( uuid ) !== -1 )
linkedClips.push( allClips[i].uuid );
}
if ( clipInfo["selected"] === false )
selected = false;
else
......@@ -208,13 +211,22 @@ Rectangle {
Drag.drop();
selected = false;
if ( linkedClip ) {
for ( var i = 0; i < linkedClips.length; ++i )
{
var linkedClip = linkedClips[i];
var linkedClipItem = findClipItem( linkedClip );
if ( linkedClipItem )
linkedClipItem.linkedClip = "";
for ( var j = 0; j < linkedClipItem.linkedClips.length; ++j )
{
if ( linkedClipItem.linkedClips[j] === uuid )
{
linkedClipItem.linkedClips.splice( j, 1 );
break;
}
}
}
for ( var i = 0; i < allClips.length; ++i ) {
for ( i = 0; i < allClips.length; ++i ) {
if ( allClips[i] === clip ) {
allClips.splice( i, 1 );
return;
......
......@@ -8,6 +8,7 @@ Menu {
property var clip
property bool grouped
property bool linked
MenuItem {
text: grouped ? "Ungroup" : "Group"
......@@ -30,20 +31,24 @@ Menu {
}
MenuItem {
text: clip.linked ? "Unlink" : "Link"
text: linked ? "Unlink" : "Link"
onTriggered: {
if ( clip.linked === true )
workflow.unlinkClips( uuid, clip.linkedClip );
else {
var selectedClip;
if ( linked === true ) {
for ( var i = 0; i < selectedClips.length; ++i ) {
if ( selectedClips[i].uuid !== uuid ) {
selectedClip = selectedClips[i].uuid;
break;
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 );
}
}
}
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 );
}
}
workflow.linkClips( clip.uuid, selectedClip );
}
}
}
......@@ -70,6 +75,7 @@ Menu {
}
onAboutToShow: {
linked = clip.linked();
grouped = findGroup( clip.uuid );
}
......
......@@ -258,8 +258,9 @@ Item {
newX = findNewPosition( newX, target, isMagneticMode );
// Let's find newX of the linked clip
if ( target.linked === true ) {
var linkedClipItem = findClipItem( target.linkedClip );
for ( j = 0; j < target.linkedClips.length; ++j )
{
var linkedClipItem = findClipItem( target.linkedClips[j] );
if ( linkedClipItem ) {
var newLinkedClipX = findNewPosition( newX, linkedClipItem, isMagneticMode );
......@@ -282,7 +283,7 @@ Item {
}
linkedClipItem.setPixelPosition( newX );
alreadyCalculated.push( target.linkedClip );
alreadyCalculated.push( target.linkedClips[j] );
}
}
......@@ -343,7 +344,6 @@ Item {
lastPosition: model.lastPosition
begin: model.begin
end: model.end
linkedClip: model.linkedClip
clipInfo: model
}
}
......
......@@ -97,7 +97,6 @@ Rectangle {
newDict["trackId"] = trackId;
newDict["name"] = clipDict["name"];
newDict["selected"] = clipDict["selected"] === false ? false : true ;
newDict["linkedClip"] = clipDict["linkedClip"] ? clipDict["linkedClip"] : "";
var tracks = trackContainer( trackType )["tracks"];
while ( trackId > tracks.count - 1 )
addTrack( trackType );
......@@ -639,13 +638,35 @@ Rectangle {
}
onClipLinked: {
findClipItem( uuidA ).linkedClip = uuidB;
findClipItem( uuidB ).linkedClip = uuidA;
var item = findClipItem( uuidA );
if ( item )
findClipItem( uuidA ).linkedClips.push( uuidB );
item = findClipItem( uuidB );
if ( item )
findClipItem( uuidB ).linkedClips.push( uuidA );
}
onClipUnlinked: {
findClipItem( uuidA ).linkedClip = "";
findClipItem( uuidB ).linkedClip = "";
var item = findClipItem( uuidA );
if ( item )
{
for ( var i = 0; i < item.linkedClips.length; ++i )
if ( item.linkedClips[i] === uuidB )
{
item.linkedClips.splice( i, 1 );
break;
}
}
item = findClipItem( uuidB );
if ( item )
{
for ( i = 0; i < item.linkedClips.length; ++i )
if ( item.linkedClips[i] === uuidA )
{
item.linkedClips.splice( i, 1 );
break;
}
}
}
onEffectsUpdated: {
......
......@@ -266,10 +266,14 @@ SequenceWorkflow::loadFromVariant( const QVariant& variant )
addClip( clip, m["trackId"].toUInt(), m["position"].toLongLong(), uuid, isAudio );
auto c = m_clips[uuid];
auto linkedClipsList = m["linkedClip"].toList();
for ( const auto& uuid : linkedClipsList )
auto linkedClipsList = m["linkedClips"].toList();
for ( const auto& uuidVar : linkedClipsList )
{
c->linkedClips.append( uuid.toUuid() );
auto linkedClipUuid = uuidVar.toUuid();
c->linkedClips.append( linkedClipUuid );
auto it = m_clips.find( linkedClipUuid );
if ( it != m_clips.end() )
emit clipLinked( uuid.toString(), linkedClipUuid.toString() );
}
EffectHelper::loadFromVariant( m["filters"], clip->input() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment