Commit 3b18af39 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

TracksView: Refactoring to allow all items to use the same code.

This allow effects to be resized/moved/added/removed including from by
undoing/redoing
parent 6b60a05e
......@@ -251,7 +251,6 @@ Commands::Effect::Resize::Resize( EffectHelper *helper, qint64 newBegin, qint64
m_newBegin( newBegin ),
m_newEnd( newEnd )
{
setText( QObject::tr( "Resizing effect %1" ).arg( m_helper->effectInstance()->effect()->name() ) );
m_oldBegin = helper->begin();
m_oldEnd = helper->end();
}
......
......@@ -64,7 +64,7 @@ EffectUser::addEffect( EffectHelper *effectHelper )
m_filters.push_back( effectHelper );
else
m_mixers.push_back( effectHelper );
emit effectAdded( effectHelper );
emit effectAdded( effectHelper, effectHelper->begin() );
}
quint32*
......@@ -236,7 +236,7 @@ EffectUser::removeEffect( Effect::Type type, qint32 idx )
if ( idx < m_filters.size() )
{
EffectHelper *helper = m_filters.takeAt( idx );
emit effectRemoved( helper );
emit effectRemoved( helper->uuid() );
}
}
else if ( type == Effect::Mixer2 )
......@@ -244,7 +244,7 @@ EffectUser::removeEffect( Effect::Type type, qint32 idx )
if ( idx < m_mixers.size() )
{
EffectHelper *helper = m_mixers.takeAt( idx );
emit effectRemoved( helper );
emit effectRemoved( helper->uuid() );
}
}
else
......@@ -263,7 +263,7 @@ EffectUser::removeEffect(EffectHelper *helper)
if ( (*it)->uuid() == helper->uuid() )
{
m_filters.erase( it );
emit effectRemoved( (*it) );
emit effectRemoved( (*it)->uuid() );
return ;
}
}
......@@ -306,7 +306,7 @@ EffectUser::moveEffect( EffectHelper *helper, qint64 newPos )
{
qint64 offset = helper->begin() - newPos;
helper->setBoundaries( newPos, helper->end() - offset );
emit effectMoved( helper, newPos );
emit effectMoved( helper->uuid(), newPos );
return ;
}
}
......
......@@ -83,9 +83,9 @@ class EffectUser : public QObject
EffectsEngine::EffectList m_filters;
signals:
void effectAdded( EffectHelper *helper );
void effectMoved( EffectHelper *helper, qint64 newPos );
void effectRemoved( EffectHelper *helper );
void effectAdded( EffectHelper *helper, qint64 pos );
void effectMoved( const QUuid&, qint64 newPos );
void effectRemoved( const QUuid& );
};
#endif // EFFECTUSER_H
......@@ -143,7 +143,7 @@ void AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent
qint32 item1TrackId = item1->trackNumber();
Q_ASSERT( item1TrackId >= 0 );
item1->group( this );
tracksView()->moveMediaItem( item1, item1TrackId , startPos() );
tracksView()->moveItem( item1, item1TrackId , startPos() );
track()->trackWorkflow()->moveClip( item1->clipHelper()->uuid(), startPos() );
}
}
......
......@@ -24,6 +24,7 @@
#include "Commands.h"
#include "EffectHelper.h"
#include "EffectInstance.h"
#include "Timeline.h"
#include "TracksView.h"
#include "TrackWorkflow.h"
......@@ -38,6 +39,15 @@ GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
{
setOpacity( 0.8 );
m_effectHelper = new EffectHelper( effect->createInstance() );
setWidth( m_effectHelper->length() );
}
GraphicsEffectItem::GraphicsEffectItem( EffectHelper *helper ) :
m_effectHelper( helper )
{
setWidth( m_effectHelper->length() );
m_effect = helper->effectInstance()->effect();
setOpacity( 0.8 );
}
const QUuid&
......
......@@ -33,6 +33,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
public:
enum { Type = UserType + 3 };
GraphicsEffectItem( Effect *effect );
GraphicsEffectItem( EffectHelper *helper );
virtual const QUuid& uuid() const;
virtual int type() const;
......
......@@ -25,12 +25,14 @@
#include "ClipHelper.h"
#include "ClipWorkflow.h"
#include "Commands.h"
#include "Library.h"
#include "EffectHelper.h"
#include "GraphicsMovieItem.h"
#include "GraphicsAudioItem.h"
#include "GraphicsEffectItem.h"
#include "GraphicsCursorItem.h"
#include "GraphicsTrack.h"
#include "Helper.h"
#include "Library.h"
#include "Media.h"
//Ugly part {
#include "Timeline.h"
......@@ -126,12 +128,20 @@ TracksView::addTrack( Workflow::TrackType type )
m_layout->activate();
m_cursorLine->setHeight( m_layout->contentsRect().height() );
m_scene->invalidate(); // Redraw the background
connect( track->trackWorkflow(), SIGNAL( clipAdded( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( addMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
//Clips part:
connect( track->trackWorkflow(), SIGNAL( clipAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
this, SLOT( addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( clipRemoved( TrackWorkflow*, const QUuid& ) ),
this, SLOT( removeMediaItem( TrackWorkflow*, const QUuid& ) ) );
this, SLOT( removeItem( TrackWorkflow*, const QUuid& ) ) );
connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, const QUuid&, qint64 ) ),
this, SLOT( moveMediaItem( TrackWorkflow*, const QUuid&, qint64 ) ) );
this, SLOT( moveItem( TrackWorkflow*, const QUuid&, qint64 ) ) );
//Effect part:
connect( track->trackWorkflow(), SIGNAL( effectAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
this, SLOT(addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( effectRemoved( TrackWorkflow*, QUuid ) ),
this, SLOT( removeItem( TrackWorkflow*, QUuid ) ) );
connect( track->trackWorkflow(), SIGNAL( effectMoved( TrackWorkflow*, QUuid, qint64 ) ),
this, SLOT( moveItem( TrackWorkflow*, QUuid, qint64 ) ) );
if ( type == Workflow::VideoTrack )
{
......@@ -208,7 +218,7 @@ TracksView::removeClip( const QUuid& uuid )
if ( item->uuid() == uuid )
{
// Remove the item from the timeline
removeMediaItem( item->track()->trackWorkflow(), item->uuid() );
removeItem( item->track()->trackWorkflow(), item->uuid() );
// Removing the item from the backend.
item->track()->trackWorkflow()->removeClip( item->uuid() );
......@@ -217,14 +227,14 @@ TracksView::removeClip( const QUuid& uuid )
}
void
TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start )
TracksView::addItem( TrackWorkflow *tw, Workflow::Helper *helper, qint64 start )
{
Q_ASSERT( ch );
Q_ASSERT( helper );
//If for some reasons the clip was already loaded, don't add it twice.
//This would likely happen when adding a clip from the timeline, as an element will
//already be created (by the drag and drop operation)
if ( m_clipsLoaded.contains( ch->uuid() ) )
if ( m_itemsLoaded.contains( helper->uuid() ) )
return ;
qint32 track = tw->trackId();
Workflow::TrackType trackType = tw->type();
......@@ -250,26 +260,38 @@ TracksView::addMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 start )
}
}
AbstractGraphicsMediaItem *item = 0;
if ( trackType == Workflow::VideoTrack )
AbstractGraphicsItem *item = NULL;
ClipHelper *clipHelper = qobject_cast<ClipHelper*>( helper );
if ( clipHelper != NULL )
{
item = new GraphicsMovieItem( ch );
connect( item, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
AbstractGraphicsMediaItem *mediaItem = NULL;
if ( trackType == Workflow::VideoTrack )
{
mediaItem = new GraphicsMovieItem( clipHelper );
connect( mediaItem, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
else if ( trackType == Workflow::AudioTrack )
{
mediaItem = new GraphicsAudioItem( clipHelper );
connect( mediaItem, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
item = mediaItem;
}
else if ( trackType == Workflow::AudioTrack )
else
{
item = new GraphicsAudioItem( ch );
connect( item, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
EffectHelper *effectHelper = qobject_cast<EffectHelper*>( helper );
Q_ASSERT( effectHelper != NULL );
item = new GraphicsEffectItem( effectHelper );
}
m_clipsLoaded.insert( ch->uuid() );
m_itemsLoaded.insert( helper->uuid() );
item->m_tracksView = this;
item->setHeight( tracksHeight() );
item->setTrack( getTrack( trackType, track ) );
item->setStartPos( start );
item->m_oldTrack = tw;
moveMediaItem( item, track, start );
moveItem( item, track, start );
updateDuration();
}
......@@ -337,18 +359,18 @@ TracksView::clipDragEnterEvent( QDragEnterEvent *event )
clip->getMedia()->hasVideoTrack() == true )
m_dragVideoItem->group( m_dragAudioItem );
if ( clip->getMedia()->hasVideoTrack() == false )
moveMediaItem( m_dragAudioItem, event->pos() );
moveItem( m_dragAudioItem, event->pos() );
else
moveMediaItem( m_dragVideoItem, event->pos() );
moveItem( m_dragVideoItem, event->pos() );
}
void
TracksView::dragMoveEvent( QDragMoveEvent *event )
{
if ( m_dragVideoItem != NULL )
moveMediaItem( m_dragVideoItem, event->pos() );
moveItem( m_dragVideoItem, event->pos() );
else if ( m_dragAudioItem != NULL)
moveMediaItem( m_dragAudioItem, event->pos() );
moveItem( m_dragAudioItem, event->pos() );
else if ( m_dragEffectItem != NULL )
{
//Only get medias from here, as we much drag an effect to a media or a track
......@@ -382,7 +404,7 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
}
void
TracksView::moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
TracksView::moveItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
{
QList<QGraphicsItem*> sceneItems = m_scene->items();
......@@ -392,7 +414,7 @@ TracksView::moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
dynamic_cast<AbstractGraphicsItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != uuid )
continue;
moveMediaItem( item, tw->trackId(), time );
moveItem( item, tw->trackId(), time );
break ;
}
updateDuration();
......@@ -400,7 +422,7 @@ TracksView::moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
}
void
TracksView::moveMediaItem( AbstractGraphicsItem *item, QPoint position )
TracksView::moveItem( AbstractGraphicsItem *item, QPoint position )
{
GraphicsTrack *track = NULL;
......@@ -427,11 +449,11 @@ TracksView::moveMediaItem( AbstractGraphicsItem *item, QPoint position )
m_lastKnownTrack = track;
qreal time = ( mapToScene( position ).x() + 0.5 );
moveMediaItem( item, track->trackNumber(), (qint64)time);
moveItem( item, track->trackNumber(), (qint64)time);
}
void
TracksView::moveMediaItem( AbstractGraphicsItem *item, qint32 track, qint64 time )
TracksView::moveItem( AbstractGraphicsItem *item, qint32 track, qint64 time )
{
// Add missing tracks
if ( item->trackType() == Workflow::AudioTrack )
......@@ -643,7 +665,7 @@ TracksView::findPosition( AbstractGraphicsItem *item, qint32 track, qint64 time
}
void
TracksView::removeMediaItem( TrackWorkflow *tw, const QUuid &uuid )
TracksView::removeItem( TrackWorkflow *tw, const QUuid &uuid )
{
GraphicsTrack *track = getTrack( tw->type(), tw->trackId() );
......@@ -653,19 +675,18 @@ TracksView::removeMediaItem( TrackWorkflow *tw, const QUuid &uuid )
for ( int i = 0; i < trackItems.size(); ++i )
{
AbstractGraphicsMediaItem *item =
dynamic_cast<AbstractGraphicsMediaItem*>( trackItems.at( i ) );
AbstractGraphicsItem *item = dynamic_cast<AbstractGraphicsItem*>( trackItems.at( i ) );
if ( !item || item->uuid() != uuid )
continue;
removeMediaItem( item );
removeItem( item );
}
}
void
TracksView::removeMediaItem( AbstractGraphicsMediaItem *item )
TracksView::removeItem( AbstractGraphicsItem *item )
{
m_itemsLoaded.remove( item->uuid() );
delete item;
m_clipsLoaded.remove( item->clipHelper()->uuid() );
updateDuration();
}
......@@ -699,7 +720,7 @@ TracksView::dropEvent( QDropEvent *event )
if ( m_dragAudioItem )
{
m_clipsLoaded.insert( m_dragAudioItem->clipHelper()->uuid() );
m_itemsLoaded.insert( m_dragAudioItem->clipHelper()->uuid() );
updateDuration();
if ( getTrack( Workflow::AudioTrack, m_numAudioTrack - 1 )->childItems().count() > 0 )
......@@ -716,7 +737,7 @@ TracksView::dropEvent( QDropEvent *event )
if ( m_dragVideoItem )
{
m_clipsLoaded.insert( m_dragVideoItem->clipHelper()->uuid() );
m_itemsLoaded.insert( m_dragVideoItem->clipHelper()->uuid() );
updateDuration();
if ( getTrack( Workflow::VideoTrack, m_numVideoTrack - 1 )->childItems().count() > 0 )
......@@ -844,7 +865,7 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
m_actionItem->setOpacity( 0.6 );
if ( m_actionRelativeX < 0 )
m_actionRelativeX = event->pos().x() - mapFromScene( m_actionItem->pos() ).x();
moveMediaItem( m_actionItem, QPoint( event->pos().x() - m_actionRelativeX, event->pos().y() ) );
moveItem( m_actionItem, QPoint( event->pos().x() - m_actionRelativeX, event->pos().y() ) );
}
else if ( event->modifiers() == Qt::NoModifier &&
event->buttons() == Qt::LeftButton &&
......
......@@ -38,6 +38,7 @@ class QGraphicsLinearLayout;
class ClipHelper;
class Effect;
class EffectHelper;
class GraphicsAudioItem;
class GraphicsEffectItem;
class GraphicsMovieItem;
......@@ -59,11 +60,11 @@ public:
m_time = time;
}
qint32 track()
qint32 track() const
{
return m_track;
}
qint64 time()
qint64 time() const
{
return m_time;
}
......@@ -77,7 +78,7 @@ public:
m_time = time;
}
bool isValid()
bool isValid() const
{
if ( m_track < 0 || m_time < 0 )
return false;
......@@ -212,31 +213,30 @@ public slots:
void clear();
/**
* \brief Insert an item into the timeline.
* \param clip Clip to insert.
* \param track The track's number.
* \param trackType The type of the track (Audio or Video)
* \param start The position in frames.
* \param tw The track the item was added in.
* \param helper The helper's item.
* \param start The position in frames.
*/
void addMediaItem( TrackWorkflow* tw, ClipHelper *clipHelper, qint64 start );
void addItem( TrackWorkflow* tw, Workflow::Helper *helper, qint64 start );
/**
* \brief Move an item in the timeline.
* \param tw The TrackWorkflow in which the track was moved
* \param ch The clip that was moved.
* \param time The new position (in frames) of the item.
*/
void moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time );
void moveItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time );
/**
* \brief Remove an item from the timeline.
* \param tw The targeted TrackWorkflow
* \param uuid The Universally Unique Identifier of the item.
*/
void removeMediaItem( TrackWorkflow* tw, const QUuid& uuid );
void removeItem( TrackWorkflow* tw, const QUuid& uuid );
/**
* \brief This is an overloaded method provided for convenience.
* \param item A pointer to AbstractGraphicsMediaItem.
* \sa removeMediaItem( const QList<AbstractGraphicsMediaItem*>& )
*/
void removeMediaItem( AbstractGraphicsMediaItem *item );
void removeItem( AbstractGraphicsItem *item );
protected:
virtual void resizeEvent( QResizeEvent *event );
......@@ -311,7 +311,7 @@ private:
* \param position New position of the item.
* \sa moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
*/
void moveMediaItem( AbstractGraphicsItem *item, QPoint position );
void moveItem( AbstractGraphicsItem *item, QPoint position );
/**
* \brief This is an overloaded method provided for convenience.
* \param item Item to move.
......@@ -319,7 +319,7 @@ private:
* \param time The new position (in frames) of the item.
* \sa moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
*/
void moveMediaItem( AbstractGraphicsItem *item, qint32 track, qint64 time );
void moveItem( AbstractGraphicsItem *item, qint32 track, qint64 time );
ItemPosition findPosition( AbstractGraphicsItem *item, qint32 track, qint64 time );
......@@ -352,7 +352,7 @@ private:
AbstractGraphicsItem::From m_actionResizeType;
AbstractGraphicsItem *m_actionItem;
GraphicsTrack *m_lastKnownTrack;
QSet<QUuid> m_clipsLoaded;
QSet<QUuid> m_itemsLoaded;
signals:
/**
......
......@@ -25,6 +25,7 @@
#include <QObject>
#include <QUuid>
#include <QMetaType>
namespace Workflow
{
......@@ -54,4 +55,6 @@ namespace Workflow
};
}
Q_DECLARE_METATYPE( Workflow::Helper* );
#endif // IHELPER_H
......@@ -51,6 +51,13 @@ TrackWorkflow::TrackWorkflow( Workflow::TrackType type, quint32 trackId ) :
m_renderOneFrameMutex = new QMutex;
m_clipsLock = new QReadWriteLock;
m_mixerBuffer = new Workflow::Frame;
connect( this, SIGNAL( effectAdded( EffectHelper*, qint64 ) ),
this, SLOT( __effectAdded( EffectHelper*, qint64) ) );
connect( this, SIGNAL( effectMoved( QUuid, qint64 ) ),
this, SLOT( __effectMoved( QUuid, qint64 ) ) );
connect( this, SIGNAL( effectRemoved( QUuid ) ),
this, SLOT( __effectRemoved(QUuid ) ) );
}
TrackWorkflow::~TrackWorkflow()
......@@ -619,3 +626,21 @@ TrackWorkflow::mixers()
{
return &m_mixers;
}
void
TrackWorkflow::__effectAdded( EffectHelper* helper, qint64 pos )
{
emit effectAdded( this, helper, pos );
}
void
TrackWorkflow::__effectRemoved( const QUuid& uuid )
{
emit effectRemoved( this, uuid );
}
void
TrackWorkflow::__effectMoved( const QUuid& uuid, qint64 pos )
{
emit effectMoved( this, uuid, pos );
}
......@@ -33,6 +33,10 @@
class Clip;
class ClipHelper;
class ClipWorkflow;
namespace Workflow
{
class Helper;
}
class QDomElement;
class QDomElement;
......@@ -126,11 +130,22 @@ class TrackWorkflow : public EffectUser
double m_fps;
const quint32 m_trackId;
private slots:
void __effectAdded( EffectHelper*, qint64 );
void __effectRemoved( const QUuid& );
void __effectMoved( const QUuid&, qint64 );
signals:
void lengthChanged( qint64 newLength );
void clipAdded( TrackWorkflow*, ClipHelper*, qint64 );
void clipAdded( TrackWorkflow*, Workflow::Helper*, 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, and not generics EffectUsers
void effectAdded( TrackWorkflow*, Workflow::Helper*, qint64 );
void effectRemoved( TrackWorkflow*, const QUuid& );
void effectMoved( TrackWorkflow*, const QUuid&, qint64 );
};
#endif // TRACKWORKFLOW_H
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