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

GraphicsEffectItem: Follow the container clip when moved

parent 09d27c79
......@@ -271,6 +271,7 @@ ELSE(NOT WITH_GUI)
Gui/settings/StringWidget.h
Gui/timeline/AbstractGraphicsItem.h
Gui/timeline/AbstractGraphicsMediaItem.h
Gui/timeline/GraphicsEffectItem.h
Gui/timeline/GraphicsCursorItem.h
Gui/timeline/GraphicsTrack.h
Gui/timeline/Timeline.h
......
......@@ -88,7 +88,7 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
GraphicsTrack* track();
/// Set the position of the item (in frames) for the x-axis.
void setStartPos( qint64 position );
virtual void setStartPos( qint64 position );
/// Return the position of the item (in frames) for the x-axis.
qint64 startPos();
......
......@@ -22,6 +22,7 @@
#include "GraphicsEffectItem.h"
#include "AbstractGraphicsMediaItem.h"
#include "Commands.h"
#include "EffectHelper.h"
#include "EffectInstance.h"
......@@ -36,7 +37,8 @@
GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
m_effect( effect ),
m_effectHelper( NULL )
m_effectHelper( NULL ),
m_container( NULL )
{
setOpacity( 0.8 );
m_effectHelper = new EffectHelper( effect->createInstance() );
......@@ -281,3 +283,15 @@ GraphicsEffectItem::containerMoved( qint64 pos )
{
setStartPos( m_effectHelper->begin() + pos );
}
void
GraphicsEffectItem::setContainer( AbstractGraphicsMediaItem *item )
{
if ( m_container != NULL )
m_container->disconnect( this );
m_container = item;
if ( item != NULL )
{
connect( item, SIGNAL( moved( qint64 ) ), this, SLOT( containerMoved( qint64 ) ) );
}
}
......@@ -27,11 +27,14 @@
#include "EffectsEngine.h"
class EffectUser;
class AbstractGraphicsMediaItem;
class QUuid;
class GraphicsEffectItem : public AbstractGraphicsItem
{
Q_OBJECT
public:
enum { Type = UserType + 3 };
GraphicsEffectItem( Effect *effect );
......@@ -56,6 +59,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
virtual qint64 itemHeight() const;
virtual qint32 zSelected() const;
virtual qint32 zNotSelected() const;
void setContainer( AbstractGraphicsMediaItem *item );
protected:
virtual bool hasResizeBoundaries() const;
/**
......@@ -76,6 +80,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
private:
Effect *m_effect;
EffectHelper *m_effectHelper;
AbstractGraphicsMediaItem *m_container;
};
#endif // GRAPHICSEFFECTITEM_H
......@@ -280,20 +280,39 @@ TracksView::addItem( TrackWorkflow *tw, Workflow::Helper *helper, qint64 start )
this, SLOT( split(AbstractGraphicsMediaItem*,qint64) ) );
}
item = mediaItem;
m_itemsLoaded.insert( helper->uuid() );
item->m_tracksView = this;
item->setHeight( item->itemHeight() );
item->setTrack( getTrack( trackType, track ) );
item->setStartPos( start );
item->m_oldTrack = tw;
moveItem( item, track, start );
}
else
{
EffectHelper *effectHelper = qobject_cast<EffectHelper*>( helper );
Q_ASSERT( effectHelper != NULL );
item = new GraphicsEffectItem( effectHelper );
GraphicsEffectItem *effectItem = new GraphicsEffectItem( effectHelper );
item = effectItem;
m_itemsLoaded.insert( helper->uuid() );
item->m_tracksView = this;
item->setHeight( item->itemHeight() );
item->setTrack( getTrack( trackType, track ) );
item->setStartPos( start );
item->m_oldTrack = tw;
moveItem( item, track, start );
QList<QGraphicsItem*> collidingItems = item->collidingItems();
effectItem->setContainer( NULL );
foreach ( QGraphicsItem *collider, collidingItems )
{
AbstractGraphicsMediaItem *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( collider );
if ( mediaItem != NULL )
{
effectItem->setContainer( mediaItem );
break ;
}
}
}
m_itemsLoaded.insert( helper->uuid() );
item->m_tracksView = this;
item->setHeight( item->itemHeight() );
item->setTrack( getTrack( trackType, track ) );
item->setStartPos( start );
item->m_oldTrack = tw;
moveItem( item, track, start );
updateDuration();
}
......@@ -795,6 +814,7 @@ TracksView::dropEvent( QDropEvent *event )
item->clipHelper()->clipWorkflow() ) );
m_dragEffectItem->m_oldTrack = item->track()->trackWorkflow();
event->acceptProposedAction();
m_dragEffectItem->setContainer( item );
}
else
{
......@@ -813,6 +833,7 @@ TracksView::dropEvent( QDropEvent *event )
track->trackWorkflow() ) );
event->acceptProposedAction();
m_dragEffectItem->setContainer( NULL );
break ;
}
}
......@@ -1088,10 +1109,12 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
qint64 targetPos = m_actionItem->startPos();
if ( effectItem != NULL )
{
effectItem->setContainer( NULL );
if ( m_effectTarget != NULL )
{
target = m_effectTarget->clipHelper()->clipWorkflow();
targetPos = m_actionItem->startPos() - m_effectTarget->startPos();
effectItem->setContainer( m_effectTarget );
}
UndoStack::getInstance()->beginMacro( "Move effect" );
}
......
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