[vlmc-devel] commit: TracksView: Bound clip effects to their target clips. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Sep 13 00:00:01 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Sep 12 23:59:08 2010 +0200| [f4cf352c832a7d99c0cc4bd3723a5b074001d2b4] | committer: Hugo Beauzée-Luyssen 

TracksView: Bound clip effects to their target clips.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=f4cf352c832a7d99c0cc4bd3723a5b074001d2b4
---

 src/Gui/timeline/TracksView.cpp |   30 +++++++++++++++++++++++++++++-
 src/Gui/timeline/TracksView.h   |    2 ++
 2 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 54bf197..1787345 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -229,6 +229,7 @@ TracksView::removeClip( const QUuid& uuid  )
 void
 TracksView::addItem( TrackWorkflow *tw, Workflow::Helper *helper, qint64 start )
 {
+    qDebug() << "Adding item:" << helper->uuid();
     Q_ASSERT( helper );
 
     //If for some reasons the clip was already loaded, don't add it twice.
@@ -422,6 +423,26 @@ TracksView::moveItem( TrackWorkflow *tw, const QUuid& uuid, qint64 time )
     Timeline::getInstance()->tracksRuler()->update();
 }
 
+QPoint
+TracksView::boundEffectInClip( GraphicsEffectItem *effectItem, QPoint position )
+{
+    if ( effectItem->effectHelper()->target()->effectType() == EffectUser::ClipEffectUser )
+    {
+        QList<QGraphicsItem*>   list = effectItem->collidingItems( Qt::IntersectsItemShape );
+        foreach ( QGraphicsItem *graphicsItem, list )
+        {
+            AbstractGraphicsMediaItem   *mediaItem = dynamic_cast<AbstractGraphicsMediaItem*>( graphicsItem );
+            if ( mediaItem == NULL )
+                continue ;
+            if ( position.x() < mediaItem->pos().x() )
+                position.setX( mediaItem->pos().x() );
+            if ( position.x() + effectItem->width() > mediaItem->pos().x() + mediaItem->width() )
+                position.setX( mediaItem->pos().x() + mediaItem->width() - effectItem->width() );
+        }
+    }
+    return position;
+}
+
 void
 TracksView::moveItem( AbstractGraphicsItem *item, QPoint position )
 {
@@ -430,6 +451,12 @@ TracksView::moveItem( AbstractGraphicsItem *item, QPoint position )
     if ( !m_lastKnownTrack )
         m_lastKnownTrack = getTrack( Workflow::VideoTrack, 0 );
 
+    QPoint  mappedPos = mapToScene( position ).toPoint();
+
+    GraphicsEffectItem  *effectItem = qgraphicsitem_cast<GraphicsEffectItem*>( item );
+    if ( effectItem != NULL )
+        mappedPos = boundEffectInClip( effectItem, mappedPos );
+
     QList<QGraphicsItem*> list = items( 0, position.y() );
     for ( int i = 0; i < list.size(); ++i )
     {
@@ -450,7 +477,7 @@ TracksView::moveItem( AbstractGraphicsItem *item, QPoint position )
 
     m_lastKnownTrack = track;
 
-    qreal time = ( mapToScene( position ).x() + 0.5 );
+    qreal time = mappedPos.x() + 0.5;
     moveItem( item, track->trackNumber(), (qint64)time);
 }
 
@@ -752,6 +779,7 @@ TracksView::dropEvent( QDropEvent *event )
             Commands::trigger( new Commands::Clip::Add( m_dragVideoItem->clipHelper(),
                                                                     m_dragVideoItem->track()->trackWorkflow(),
                                                                     (qint64)mappedXPos ) );
+            qDebug() << m_dragVideoItem->pos();
             m_dragVideoItem = NULL;
         }
 
diff --git a/src/Gui/timeline/TracksView.h b/src/Gui/timeline/TracksView.h
index f491964..7b0d1fc 100644
--- a/src/Gui/timeline/TracksView.h
+++ b/src/Gui/timeline/TracksView.h
@@ -312,6 +312,8 @@ private:
      * \sa moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
      */
     void                    moveItem( AbstractGraphicsItem *item, QPoint position );
+    QPoint                  boundEffectInClip( GraphicsEffectItem *effectItem, QPoint position );
+
     /**
      * \brief This is an overloaded method provided for convenience.
      * \param item Item to move.



More information about the Vlmc-devel mailing list