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