Commit 1c74c832 authored by luyikei's avatar luyikei

Timeline: Use signals to apply changes on Workflow to the timeline

parent 89eda27e
......@@ -96,11 +96,7 @@ Rectangle {
}
function move() {
// This function updates Backend
if ( newTrackId !== trackId )
moveClipTo( track.type, uuid, newTrackId );
else
workflow.moveClip( trackId, uuid, position )
moveClipTo( track.type, uuid, newTrackId, position );
}
function resize() {
......
......@@ -175,13 +175,11 @@ Item {
var pos = aClipInfo["position"];
var audioClipUuid = workflow.addClip( currentUuid, trackId, pos, true );
removeClipFromTrack( "Audio", trackId, "audioUuid" );
addClip( "Audio", trackId, workflow.clipInfo( audioClipUuid ) );
}
if ( vClipInfo ) {
pos = vClipInfo["position"];
var videoClipUuid = workflow.addClip( currentUuid, trackId, pos, false );
removeClipFromTrack( "Video", trackId, "videoUuid" );
addClip( "Video", trackId, workflow.clipInfo( videoClipUuid ) );
}
if ( audioClipUuid && videoClipUuid ) {
findClipItem( audioClipUuid ).linkedClip = videoClipUuid;
......
......@@ -95,6 +95,8 @@ Rectangle {
newDict["name"] = clipDict["name"];
newDict["linkedClip"] = clipDict["linkedClip"] ? clipDict["linkedClip"] : "";
var tracks = trackContainer( trackType )["tracks"];
while ( trackId > tracks.count - 1 )
addTrack( trackType );
tracks.get( trackId )["clips"].append( newDict );
if ( clipDict["uuid"] === "tempUuid" )
......@@ -129,6 +131,12 @@ Rectangle {
removeClipFromTrack( trackType, i, uuid );
}
function removeClip( uuid )
{
removeClipFromTrackContainer( "Audio", uuid );
removeClipFromTrackContainer( "Video", uuid );
}
function findClipFromTrackContainer( trackType, uuid )
{
var tracks = trackContainer( trackType )["tracks"];
......@@ -168,16 +176,15 @@ Rectangle {
return null;
}
function moveClipTo( trackType, uuid, trackId )
function moveClipTo( trackType, uuid, trackId, position )
{
var clip = findClipFromTrackContainer( trackType, uuid );
if ( !clip )
return;
var oldId = clip["trackId"];
clip["trackId"] = trackId;
workflow.moveClip( trackId, uuid, clip["position"] );
addClip( trackType, trackId, clip );
removeClipFromTrack( trackType, oldId, uuid );
findClipItem( uuid ).position = position;
workflow.moveClip( trackId, uuid, position );
}
function adjustTracks( trackType ) {
......@@ -459,10 +466,8 @@ Rectangle {
icon: StandardIcon.Question
standardButtons: StandardButton.Yes | StandardButton.No
onYes: {
while ( selectedClips.length ) {
workflow.removeClip( selectedClips[0] );
removeClipFromTrackContainer( selectedClips[0].type, selectedClips[0].uuid );
}
while ( selectedClips.length )
workflow.removeClip( selectedClips[0].uuid );
}
}
......@@ -489,6 +494,38 @@ Rectangle {
zoomIn( sView.width / ( ftop( length ) + initPosOfCursor + 100 ) );
}
}
onClipAdded: {
var clipInfo = workflow.clipInfo( uuid );
var type = clipInfo["audio"] ? "Audio" : "Video";
addClip( type, clipInfo["trackId"], clipInfo );
}
onClipMoved: {
var clipInfo = workflow.clipInfo( uuid );
var type = clipInfo["audio"] ? "Audio" : "Video";
var oldClip = findClipFromTrackContainer( type, uuid );
if ( clipInfo["trackId"] !== oldClip["trackId"] ) {
addClip( type, clipInfo["trackId"], clipInfo );
removeClipFromTrack( type, oldClip["trackId"], uuid );
}
else if ( oldClip["position"] !== clipInfo["position"] ) {
findClipItem( uuid ).position = clipInfo["position"];
}
}
onClipRemoved: {
removeClip( uuid );
}
onClipResized: {
var clipInfo = workflow.clipInfo( uuid );
var clip = findClipItem( uuid );
clip.position = clipInfo["position"];
clip.end = clipInfo["end"];
clip.begin = clipInfo["begin"];
}
}
Connections {
......
......@@ -190,7 +190,7 @@ MainWorkflow::addClip( const QString& uuid, quint32 trackId, qint32 pos, bool is
newClip->setFormats( Clip::Video );
Commands::trigger( new Commands::Clip::Add( newClip, track( trackId ), pos ) );
emit clipAdded( newClip->uuid().toString() );
return newClip->uuid().toString();
}
......@@ -224,6 +224,7 @@ MainWorkflow::clipInfo( const QString& uuid )
h["audio"] = clip->formats().testFlag( Clip::Audio );
h["video"] = clip->formats().testFlag( Clip::Video );
h["position"] = track( it.key() )->getClipPosition( uuid );
h["trackId"] = it.key();
return QJsonObject::fromVariantHash( h );
}
}
......@@ -247,6 +248,7 @@ MainWorkflow::moveClip( quint32 trackId, const QString& uuid, qint64 startFrame
m_clips.erase( it );
m_clips.insertMulti( trackId, clip );
emit clipMoved( clip->uuid().toString() );
return;
}
}
......@@ -263,6 +265,7 @@ MainWorkflow::resizeClip( const QString& uuid, qint64 newBegin, qint64 newEnd, q
auto clip = it.value();
Commands::trigger( new Commands::Clip::Resize( track( trackId ), clip, newBegin, newEnd, newPos ) );
emit clipResized( uuid );
return;
}
}
......@@ -278,7 +281,8 @@ MainWorkflow::removeClip( const QString& uuid )
auto trackId = it.key();
auto clip = it.value();
Commands::trigger( new Commands::Clip::Remove( clip, track( trackId) ) );
Commands::trigger( new Commands::Clip::Remove( clip, track( trackId ) ) );
emit clipRemoved( uuid );
return;
}
}
......
......@@ -234,6 +234,11 @@ class MainWorkflow : public QObject
* \param newLength The new length, in frames
*/
void lengthChanged( qint64 length );
void clipAdded( const QString& uuid );
void clipResized( const QString& uuid );
void clipRemoved( const QString& uuid );
void clipMoved( const QString& uuid );
};
#endif // MAINWORKFLOW_H
......@@ -84,7 +84,6 @@ TrackWorkflow::addClip( std::shared_ptr<Clip> const& clip, qint64 start )
{
trackFromFormats( clip->formats() )->insertAt( *clip->input(), start );
m_clips.insertMulti( start, clip );
emit clipAdded( this, clip, start );
}
qint64
......@@ -138,7 +137,6 @@ TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
m_clips.erase( it );
m_clips.insertMulti( startingFrame, clip );
emit clipMoved( this, clip->uuid(), startingFrame );
return ;
}
++it;
......@@ -180,7 +178,6 @@ TrackWorkflow::clipDestroyed( const QUuid& id )
auto clip = it.value();
m_clips.erase( it );
clip->disconnect( this );
emit clipRemoved( this, id );
return ;
}
++it;
......@@ -204,7 +201,6 @@ TrackWorkflow::removeClip( const QUuid& id )
track->remove( track->clipIndexAt( it.key() ) );
m_clips.erase( it );
clip->disconnect( this );
emit clipRemoved( this, clip->uuid() );
return clip;
}
++it;
......@@ -245,6 +241,7 @@ TrackWorkflow::loadFromVariant( const QVariant &variant )
c->setFormats( (Clip::Formats)m["formats"].toInt() );
EffectHelper::loadFromVariant( m["filters"], c->input() );
addClip( c, m["startFrame"].toLongLong() );
emit Core::instance()->workflow()->clipAdded( c->uuid().toString() );
}
EffectHelper::loadFromVariant( variant.toMap()["filters"], m_multitrack );
}
......
......@@ -107,9 +107,6 @@ class TrackWorkflow : public QObject
signals:
void lengthChanged( qint64 newLength );
void clipAdded( TrackWorkflow*, std::shared_ptr<Clip> const& clip, qint64 );
void clipRemoved( TrackWorkflow*, const QUuid& );
void clipMoved( TrackWorkflow*, const QUuid&, qint64 );
//these signals are here to ease connection with tracksview, as it only
//monitors tracks
......
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