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

Refactoring resize to avoid using clip helpers, or item dependent methods.

parent a8e040de
......@@ -111,12 +111,14 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
/// Ungroup two items
void ungroup();
virtual qint64 begin() const = 0;
virtual qint64 end() const = 0;
virtual qint64 begin() const = 0;
virtual qint64 end() const = 0;
qint64 width() const;
virtual void triggerMove( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
Workflow::Helper *helper, qint64 pos ) = 0;
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos ) = 0;
virtual Workflow::Helper *helper() = 0;
protected:
......
......@@ -289,3 +289,14 @@ AbstractGraphicsMediaItem::helper()
{
return m_clipHelper;
}
void
AbstractGraphicsMediaItem::triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos )
{
ClipHelper *clipHelper = qobject_cast<ClipHelper*>( helper );
if ( clipHelper == NULL )
return ;
Commands::trigger( new Commands::MainWorkflow::ResizeClip( tw, clipHelper, newBegin,
newEnd, pos ) );
}
......@@ -59,6 +59,8 @@ public:
virtual Workflow::Helper *helper();
virtual void triggerMove( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
Workflow::Helper *helper, qint64 pos );
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
protected:
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
......
......@@ -213,3 +213,10 @@ GraphicsEffectItem::triggerMove( TrackWorkflow *oldTrack, TrackWorkflow *newTrac
{
//FIXME
}
void
GraphicsEffectItem::triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos )
{
//FIXME
}
......@@ -47,7 +47,8 @@ class GraphicsEffectItem : public AbstractGraphicsItem
virtual Workflow::Helper *helper();
virtual void triggerMove(TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
Workflow::Helper *helper, qint64 pos);
virtual void triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
qint64 newBegin, qint64 newEnd, qint64 pos );
protected:
virtual bool hasResizeBoundaries() const;
/**
......
......@@ -351,10 +351,11 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
moveMediaItem( m_dragAudioItem, event->pos() );
else if ( m_dragEffectItem != NULL )
{
QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() );
if ( clips.size() > 0 )
//Only get medias from here, as we much drag an effect to a media or a track
QList<AbstractGraphicsMediaItem*> itemList = mediaItems<AbstractGraphicsMediaItem>( event->pos() );
if ( itemList.size() > 0 )
{
AbstractGraphicsMediaItem *item = clips.first();
AbstractGraphicsMediaItem *item = itemList.first();
m_dragEffectItem->setWidth( item->clipHelper()->length() );
m_dragEffectItem->setStartPos( item->startPos() );
m_dragEffectItem->setHeight( tracksHeight() / 2 );
......@@ -399,7 +400,7 @@ TracksView::moveMediaItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
}
void
TracksView::moveMediaItem( AbstractGraphicsMediaItem *item, QPoint position )
TracksView::moveMediaItem( AbstractGraphicsItem *item, QPoint position )
{
GraphicsTrack *track = NULL;
......@@ -736,7 +737,7 @@ TracksView::dropEvent( QDropEvent *event )
}
else if ( m_dragEffectItem != NULL )
{
QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() );
QList<AbstractGraphicsMediaItem*> clips = mediaItems<AbstractGraphicsMediaItem>( event->pos() );
if ( clips.size() > 0 )
{
foreach ( AbstractGraphicsMediaItem *item, clips )
......@@ -893,7 +894,7 @@ TracksView::mouseMoveEvent( QMouseEvent *event )
void
TracksView::mousePressEvent( QMouseEvent *event )
{
QList<AbstractGraphicsMediaItem*> mediaCollisionList = mediaItems( event->pos() );
QList<AbstractGraphicsItem*> mediaCollisionList = mediaItems<AbstractGraphicsItem>( event->pos() );
// Reset the drag mode
setDragMode( QGraphicsView::NoDrag );
......@@ -908,7 +909,7 @@ TracksView::mousePressEvent( QMouseEvent *event )
tool() == TOOL_DEFAULT &&
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem *item = mediaCollisionList.at( 0 );
AbstractGraphicsItem *item = mediaCollisionList.at( 0 );
QPoint itemEndPos = mapFromScene( item->mapToScene( item->boundingRect().bottomRight() ) );
QPoint itemPos = mapFromScene( item->mapToScene( 0, 0 ) );
......@@ -938,7 +939,7 @@ TracksView::mousePressEvent( QMouseEvent *event )
tool() == TOOL_DEFAULT &&
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem *item = mediaCollisionList.at( 0 );
AbstractGraphicsItem *item = mediaCollisionList.at( 0 );
if ( !scene()->selectedItems().contains( item ) )
{
......@@ -951,7 +952,7 @@ TracksView::mousePressEvent( QMouseEvent *event )
tool() == TOOL_DEFAULT &&
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem *item = mediaCollisionList.at( 0 );
AbstractGraphicsItem *item = mediaCollisionList.at( 0 );
item->setSelected( !item->isSelected() );
event->accept();
}
......@@ -976,7 +977,7 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
//Check if the clip moved.
if ( m_actionItem->m_oldTrack == m_actionItem->track()->trackWorkflow() &&
m_actionItem->startPos() == m_actionItem->track()->trackWorkflow()->getClipPosition( m_actionItem->clipHelper()->uuid() ) )
m_actionItem->startPos() == m_actionItem->track()->trackWorkflow()->getClipPosition( m_actionItem->uuid() ) )
return ;
updateDuration();
......@@ -1010,22 +1011,20 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
}
else if ( m_action == TracksView::Resize )
{
ClipHelper *ch = m_actionItem->clipHelper();
qint64 newBegin;
qint64 newEnd;
if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
{
newEnd = ch->end();
newEnd = m_actionItem->helper()->end();
newBegin = newEnd - m_actionItem->width();
}
else
{
newBegin = ch->begin();
newBegin = m_actionItem->helper()->begin();
newEnd = newBegin + m_actionItem->width();
}
Commands::trigger( new Commands::MainWorkflow::ResizeClip( m_actionItem->track()->trackWorkflow(),
ch, newBegin, newEnd,
m_actionItem->pos().x() ) );
m_actionItem->triggerResize( m_actionItem->track()->trackWorkflow(), m_actionItem->helper(),
newBegin, newEnd, m_actionItem->pos().x() );
updateDuration();
}
......@@ -1054,22 +1053,6 @@ TracksView::wheelEvent( QWheelEvent *event )
}
}
QList<AbstractGraphicsMediaItem*>
TracksView::mediaItems( const QPoint &pos )
{
//TODO optimization needed!
QList<QGraphicsItem*> collisionList = items( pos );
QList<AbstractGraphicsMediaItem*> mediaCollisionList;
for ( int i = 0; i < collisionList.size(); ++i )
{
AbstractGraphicsMediaItem* item =
dynamic_cast<AbstractGraphicsMediaItem*>( collisionList.at( i ) );
if ( item )
mediaCollisionList.append( item );
}
return mediaCollisionList;
}
QList<AbstractGraphicsItem*>
TracksView::timelineItems()
{
......
......@@ -152,7 +152,22 @@ public:
* \warning Calling this method can be excessively slow!
* \sa mediaItems()
*/
QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint &pos );
template <typename T>
QList<T*> mediaItems( const QPoint &pos )
{
//TODO optimization needed!
QList<QGraphicsItem*> collisionList = items( pos );
QList<T*> mediaCollisionList;
for ( int i = 0; i < collisionList.size(); ++i )
{
T *item = dynamic_cast<T*>( collisionList.at( i ) );
if ( item != NULL )
mediaCollisionList.append( item );
}
return mediaCollisionList;
}
/**
* \brief This is an overloaded method provided for convenience.
* \warning Calling this method can be excessively slow!
......@@ -296,7 +311,7 @@ private:
* \param position New position of the item.
* \sa moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
*/
void moveMediaItem( AbstractGraphicsMediaItem *item, QPoint position );
void moveMediaItem( AbstractGraphicsItem *item, QPoint position );
/**
* \brief This is an overloaded method provided for convenience.
* \param item Item to move.
......@@ -334,8 +349,8 @@ private:
// Mouse actions on Medias
Action m_action;
int m_actionRelativeX;
AbstractGraphicsMediaItem::From m_actionResizeType;
AbstractGraphicsMediaItem *m_actionItem;
AbstractGraphicsItem::From m_actionResizeType;
AbstractGraphicsItem *m_actionItem;
GraphicsTrack *m_lastKnownTrack;
QSet<QUuid> m_clipsLoaded;
......
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