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

TracksView: Trying to reduce the usage of ClipHelpers

AS the TracksView will soon handle non clip GraphicsItems.
More methods have been moved from the AbstractGraphicsMovieItem class to the
AbstractGraphicsItem class.
parent 105882de
......@@ -32,7 +32,8 @@ AbstractGraphicsItem::AbstractGraphicsItem() :
m_tracksView( NULL ),
m_oldTrack( NULL ),
m_width( 0 ),
m_height( 0 )
m_height( 0 ),
m_group( NULL )
{
setFlags( QGraphicsItem::ItemIsSelectable );
setAcceptHoverEvents( true );
......@@ -216,3 +217,28 @@ AbstractGraphicsItem::resizeZone( const QPointF& position )
}
return false;
}
AbstractGraphicsItem*
AbstractGraphicsItem::groupItem()
{
return m_group;
}
void
AbstractGraphicsItem::group( AbstractGraphicsItem* item )
{
Q_ASSERT( item );
if ( m_group )
ungroup();
item->m_group = this;
m_group = item;
}
void
AbstractGraphicsItem::ungroup()
{
if ( m_group == NULL )
return;
m_group->m_group = NULL;
m_group = NULL;
}
......@@ -30,6 +30,10 @@ class TrackWorkflow;
class TracksScene;
class TracksView;
class QUuid;
#include "Types.h"
class AbstractGraphicsItem : public QObject, public QGraphicsItem
{
Q_OBJECT
......@@ -47,6 +51,11 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
AbstractGraphicsItem();
virtual ~AbstractGraphicsItem();
virtual const QUuid& uuid() const = 0;
/// Return the type of the media
virtual Workflow::TrackType trackType() const = 0;
/// Return the Type of the MediaItem (see http://doc.trolltech.com/4.5/qgraphicsitem.html#type)
virtual int type() const = 0;
/// Defines the outer bounds of the item as a rectangle
......@@ -87,6 +96,18 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
*/
qint64 resize( qint64 size, qint64 newBegin, qint64 clipPos, From from = BEGINNING );
/**
* \brief Return a pointer to the linked item.
* \details This method will return NULL if there is no linked item.
*/
AbstractGraphicsItem* groupItem();
/// Group two items together
void group( AbstractGraphicsItem* item );
/// Ungroup two items
void ungroup();
protected:
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
......@@ -122,13 +143,15 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
protected:
/// This pointer will be set when inserted in the tracksView.
TracksView* m_tracksView;
QColor m_itemColor;
TracksView* m_tracksView;
QColor m_itemColor;
private:
TrackWorkflow *m_oldTrack;
qint64 m_width;
qint64 m_height;
TrackWorkflow *m_oldTrack;
qint64 m_width;
qint64 m_height;
/// Pointer used to save the address of a linked item.
AbstractGraphicsItem* m_group;
protected slots:
/**
......
......@@ -39,7 +39,6 @@
#include <QtDebug>
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
m_group( NULL ),
m_muted( false )
{
m_clipHelper = new ClipHelper( clip );
......@@ -53,7 +52,6 @@ AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( ClipHelper* ch ) :
m_clipHelper( ch ),
m_group( NULL ),
m_muted( false )
{
// Adjust the width
......@@ -69,27 +67,6 @@ AbstractGraphicsMediaItem::~AbstractGraphicsMediaItem()
ungroup();
}
void AbstractGraphicsMediaItem::group( AbstractGraphicsMediaItem* item )
{
Q_ASSERT( item );
if ( m_group )
ungroup();
item->m_group = this;
m_group = item;
}
void AbstractGraphicsMediaItem::ungroup()
{
if ( !m_group ) return;
m_group->m_group = NULL;
m_group = NULL;
}
AbstractGraphicsMediaItem* AbstractGraphicsMediaItem::groupItem()
{
return m_group;
}
void AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent* event )
{
if ( !tracksView() )
......@@ -135,13 +112,13 @@ void AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent
{
tracksView()->m_mainWorkflow->muteClip( uuid(),
trackId,
mediaType() );
trackType() );
}
else
{
tracksView()->m_mainWorkflow->unmuteClip( uuid(),
trackId,
mediaType() );
trackType() );
}
}
else if ( selectedAction == linkAction )
......@@ -161,7 +138,7 @@ void AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent
item1 = item2;
//From here, the item we click on is "this" and the item to group is "item1"
if ( item1->mediaType() != mediaType() )
if ( item1->trackType() != trackType() )
{
qint32 item1TrackId = item1->trackNumber();
Q_ASSERT( item1TrackId >= 0 );
......
......@@ -25,7 +25,6 @@
class ClipHelper;
#include "AbstractGraphicsItem.h"
#include "Types.h"
#include <QUuid>
......@@ -50,26 +49,11 @@ public:
/// Should return the unique uid of the contained media.
virtual const QUuid& uuid() const;
/// Return the type of the media
virtual Workflow::TrackType mediaType() const = 0;
/// Group two items together
void group( AbstractGraphicsMediaItem* item );
/// Ungroup two items
void ungroup();
ClipHelper *clipHelper();
const ClipHelper* clipHelper() const;
virtual void setEmphasized( bool value );
/**
* \brief Return a pointer to the linked item.
* \details This method will return NULL if there is no linked item.
*/
AbstractGraphicsMediaItem* groupItem();
protected:
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
......@@ -91,9 +75,6 @@ private slots:
void clipDestroyed( Clip* clip );
private:
/// Pointer used to save the address of a linked item.
AbstractGraphicsMediaItem* m_group;
bool m_muted;
signals:
......
......@@ -63,7 +63,7 @@ GraphicsAudioItem::~GraphicsAudioItem()
{
}
Workflow::TrackType GraphicsAudioItem::mediaType() const
Workflow::TrackType GraphicsAudioItem::trackType() const
{
return Workflow::AudioTrack;
}
......
......@@ -51,7 +51,7 @@ public:
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual Workflow::TrackType mediaType() const;
virtual Workflow::TrackType trackType() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
protected:
......
......@@ -60,7 +60,7 @@ GraphicsMovieItem::~GraphicsMovieItem()
{
}
Workflow::TrackType GraphicsMovieItem::mediaType() const
Workflow::TrackType GraphicsMovieItem::trackType() const
{
return Workflow::VideoTrack;
}
......
......@@ -52,7 +52,7 @@ public:
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual Workflow::TrackType mediaType() const;
virtual Workflow::TrackType trackType() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
protected:
......
......@@ -129,8 +129,8 @@ TracksView::addTrack( Workflow::TrackType type )
this, SLOT( addMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( clipRemoved( TrackWorkflow*, ClipHelper* ) ),
this, SLOT( removeMediaItem( TrackWorkflow*, ClipHelper* ) ) );
connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, ClipHelper*, qint64 ) ),
this, SLOT( moveMediaItem( TrackWorkflow*, ClipHelper*, qint64 ) ) );
connect( track->trackWorkflow(), SIGNAL( clipMoved( TrackWorkflow*, const QUuid&, qint64 ) ),
this, SLOT( moveMediaItem( TrackWorkflow*, const QUuid&, qint64 ) ) );
if ( type == Workflow::VideoTrack )
{
......@@ -322,7 +322,7 @@ TracksView::clipDragEnterEvent( QDragEnterEvent *event )
m_dragAudioItem = new GraphicsAudioItem( clip );
m_dragAudioItem->m_tracksView = this;
m_dragAudioItem->setHeight( tracksHeight() );
m_dragAudioItem->setTrack( getTrack( m_dragAudioItem->mediaType(), 0 ) );
m_dragAudioItem->setTrack( getTrack( m_dragAudioItem->trackType(), 0 ) );
connect( m_dragAudioItem, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
......@@ -332,7 +332,7 @@ TracksView::clipDragEnterEvent( QDragEnterEvent *event )
m_dragVideoItem = new GraphicsMovieItem( clip );
m_dragVideoItem->m_tracksView = this;
m_dragVideoItem->setHeight( tracksHeight() );
m_dragVideoItem->setTrack( getTrack( m_dragVideoItem->mediaType(), 0 ) );
m_dragVideoItem->setTrack( getTrack( m_dragVideoItem->trackType(), 0 ) );
connect( m_dragVideoItem, SIGNAL( split(AbstractGraphicsMediaItem*,qint64) ),
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
......@@ -367,7 +367,7 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
{
foreach ( AbstractGraphicsMediaItem* item, clips )
{
if ( item->mediaType() != Workflow::VideoTrack )
if ( item->trackType() != Workflow::VideoTrack )
continue ;
m_effectEmphasizedItems.insert( item );
item->setEmphasized( true );
......@@ -390,15 +390,15 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
}
void
TracksView::moveMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 time )
TracksView::moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
{
QList<QGraphicsItem*> sceneItems = m_scene->items();
for ( int i = 0; i < sceneItems.size(); ++i )
{
AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != ch->uuid() )
AbstractGraphicsItem* item =
dynamic_cast<AbstractGraphicsItem*>( sceneItems.at( i ) );
if ( !item || item->uuid() != uuid )
continue;
moveMediaItem( item, tw->trackId(), time );
break ;
......@@ -439,15 +439,15 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, QPoint position )
}
void
TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64 time )
TracksView::moveMediaItem( AbstractGraphicsItem *item, qint32 track, qint64 time )
{
// Add missing tracks
if ( item->mediaType() == Workflow::AudioTrack )
if ( item->trackType() == Workflow::AudioTrack )
{
while ( track >= m_numAudioTrack )
addTrack( Workflow::AudioTrack );
}
else if ( item->mediaType() == Workflow::VideoTrack )
else if ( item->trackType() == Workflow::VideoTrack )
{
while ( track >= m_numVideoTrack )
addTrack( Workflow::VideoTrack );
......@@ -460,12 +460,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64
bool validPosFound = false;
// Add missing tracks for the target
if ( item->groupItem()->mediaType() == Workflow::AudioTrack )
if ( item->groupItem()->trackType() == Workflow::AudioTrack )
{
while ( p.track() >= m_numAudioTrack )
addTrack( Workflow::AudioTrack );
}
else if ( item->groupItem()->mediaType() == Workflow::VideoTrack )
else if ( item->groupItem()->trackType() == Workflow::VideoTrack )
{
while ( p.track() >= m_numVideoTrack )
addTrack( Workflow::VideoTrack );
......@@ -475,12 +475,12 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64
ItemPosition p2 = findPosition( item->groupItem(), track, time );
// Add missing tracks for the source
if ( item->mediaType() == Workflow::AudioTrack )
if ( item->trackType() == Workflow::AudioTrack )
{
while ( p2.track() >= m_numAudioTrack )
addTrack( Workflow::AudioTrack );
}
else if ( item->mediaType() == Workflow::VideoTrack )
else if ( item->trackType() == Workflow::VideoTrack )
{
while ( p2.track() >= m_numVideoTrack )
addTrack( Workflow::VideoTrack );
......@@ -516,11 +516,11 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64
// We've found a valid position that fit for the two items.
// Move the primary item to the target destination.
item->setStartPos( p.time() );
item->setTrack( getTrack( item->mediaType(), p.track() ) );
item->setTrack( getTrack( item->trackType(), p.track() ) );
// Move the linked item to the target destination.
item->groupItem()->setStartPos( p2.time() );
item->groupItem()->setTrack( getTrack( item->groupItem()->mediaType(), p2.track() ) );
item->groupItem()->setTrack( getTrack( item->groupItem()->trackType(), p2.track() ) );
}
}
else
......@@ -528,18 +528,18 @@ TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64
if ( p.isValid() )
{
item->setStartPos( p.time() );
item->setTrack( getTrack( item->mediaType(), p.track() ) );
item->setTrack( getTrack( item->trackType(), p.track() ) );
}
}
}
ItemPosition
TracksView::findPosition( AbstractGraphicsMediaItem *item, qint32 track, qint64 time )
TracksView::findPosition( AbstractGraphicsItem *item, qint32 track, qint64 time )
{
// Create a fake item for computing collisions
QGraphicsRectItem *chkItem = new QGraphicsRectItem( item->boundingRect() );
chkItem->setParentItem( getTrack( item->mediaType(), track ) );
chkItem->setParentItem( getTrack( item->trackType(), track ) );
chkItem->setPos( time, 0 );
QGraphicsItem *oldParent = item->parentItem();
......@@ -574,9 +574,9 @@ TracksView::findPosition( AbstractGraphicsMediaItem *item, qint32 track, qint64
else if ( trackId <= track )
{
int higherTrack = 0;
if ( item->mediaType() == Workflow::VideoTrack )
if ( item->trackType() == Workflow::VideoTrack )
higherTrack = m_numVideoTrack;
else if ( item->mediaType() == Workflow::AudioTrack )
else if ( item->trackType() == Workflow::AudioTrack )
higherTrack = m_numAudioTrack;
if ( track >= higherTrack - 1 )
......@@ -587,8 +587,8 @@ TracksView::findPosition( AbstractGraphicsMediaItem *item, qint32 track, qint64
}
track += 1;
}
Q_ASSERT( getTrack( item->mediaType(), track ) != NULL );
chkItem->setParentItem( getTrack( item->mediaType(), track ) );
Q_ASSERT( getTrack( item->trackType(), track ) != NULL );
chkItem->setParentItem( getTrack( item->trackType(), track ) );
}
}
if ( !itemCollision )
......@@ -889,7 +889,7 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
Q_ASSERT( trackId >= 0 );
//FIXME: BEGIN UGLY
GraphicsTrack *track = getTrack( m_actionItem->mediaType(), trackId );
GraphicsTrack *track = getTrack( m_actionItem->trackType(), trackId );
Q_ASSERT( track );
QPointF collidePos = track->sceneBoundingRect().topRight();
......
......@@ -214,7 +214,7 @@ public slots:
* \param ch The clip that was moved.
* \param time The new position (in frames) of the item.
*/
void moveMediaItem( TrackWorkflow *tw, ClipHelper *ch, qint64 time );
void moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time );
/**
* \brief Remove an item from the timeline.
* \param uuid The Universally Unique Identifier of the item.
......@@ -310,9 +310,9 @@ private:
* \param time The new position (in frames) of the item.
* \sa moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
*/
void moveMediaItem( AbstractGraphicsMediaItem *item, qint32 track, qint64 time );
void moveMediaItem( AbstractGraphicsItem *item, qint32 track, qint64 time );
ItemPosition findPosition( AbstractGraphicsMediaItem *item, qint32 track, qint64 time );
ItemPosition findPosition( AbstractGraphicsItem *item, qint32 track, qint64 time );
/**
* \brief Return a pointer to the specified track.
......
......@@ -376,7 +376,7 @@ void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
m_clips[startingFrame] = cw;
cw->requireResync();
computeLength();
emit clipMoved( this, cw->getClipHelper(), startingFrame );
emit clipMoved( this, cw->getClipHelper()->uuid(), startingFrame );
return ;
}
++it;
......
......@@ -130,7 +130,7 @@ class TrackWorkflow : public EffectUser
void lengthChanged( qint64 newLength );
void clipAdded( TrackWorkflow*, ClipHelper*, qint64 );
void clipRemoved( TrackWorkflow*, ClipHelper* );
void clipMoved( TrackWorkflow*, ClipHelper*, qint64 );
void clipMoved( 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