Commit b99c1c6e authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

New slot for moving an item using its uuid

parent 72a5bf84
...@@ -154,16 +154,33 @@ void TracksView::dragMoveEvent( QDragMoveEvent* event ) ...@@ -154,16 +154,33 @@ void TracksView::dragMoveEvent( QDragMoveEvent* event )
moveMediaItem( m_dragItem, event->pos() ); moveMediaItem( m_dragItem, event->pos() );
} }
void TracksView::moveMediaItem( const QUuid& uuid, int track, int 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() != uuid ) continue;
moveMediaItem( item, track, time );
}
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position ) void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position )
{ {
int track = (unsigned int)( mapToScene( position ).y() / m_tracksHeight ); int track = (unsigned int)( mapToScene( position ).y() / m_tracksHeight );
qreal time = ( mapToScene( position ).x() + 0.5 );
moveMediaItem( item, track, (int)time);
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time )
{
if ( track < 0 ) if ( track < 0 )
track = 0; track = 0;
else if ( track > m_numVideoTrack - 1) else if ( track > m_numVideoTrack - 1)
track = m_numVideoTrack - 1; track = m_numVideoTrack - 1;
qreal mappedXPos = ( mapToScene( position ).x() + 0.5 );
QPointF oldPos = item->pos(); QPointF oldPos = item->pos();
QGraphicsItem* oldParent = item->parentItem(); QGraphicsItem* oldParent = item->parentItem();
// Check for vertical collisions // Check for vertical collisions
...@@ -180,7 +197,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position ...@@ -180,7 +197,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
{ {
// Collision with an item of the same type // Collision with an item of the same type
itemCollision = true; itemCollision = true;
if ( currentItem->pos().y() < position.y() ) if ( currentItem->trackNumber() > track )
{ {
if ( track < 1 ) if ( track < 1 )
{ {
...@@ -192,7 +209,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position ...@@ -192,7 +209,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
Q_ASSERT( m_layout->itemAt( track )->graphicsItem() != NULL ); Q_ASSERT( m_layout->itemAt( track )->graphicsItem() != NULL );
item->setParentItem( m_layout->itemAt( track )->graphicsItem() ); item->setParentItem( m_layout->itemAt( track )->graphicsItem() );
} }
else if ( currentItem->pos().y() > position.y() ) else if ( currentItem->trackNumber() < track )
{ {
if ( track >= m_numVideoTrack - 1 ) if ( track >= m_numVideoTrack - 1 )
{ {
...@@ -210,7 +227,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position ...@@ -210,7 +227,7 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position
continueSearch = false; continueSearch = false;
} }
// Check for horizontal collisions // Check for horizontal collisions
mappedXPos = qMax( mappedXPos, (qreal)0 ); int mappedXPos = qMax( time, 0 );
item->setPos( mappedXPos, 0 ); item->setPos( mappedXPos, 0 );
QList<QGraphicsItem*> colliding = item->collidingItems( Qt::IntersectsItemShape ); QList<QGraphicsItem*> colliding = item->collidingItems( Qt::IntersectsItemShape );
for ( int i = 0; i < colliding.size(); ++i ) for ( int i = 0; i < colliding.size(); ++i )
......
...@@ -90,6 +90,9 @@ public: ...@@ -90,6 +90,9 @@ public:
void setScale( double scaleFactor ); void setScale( double scaleFactor );
QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint& pos ); QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint& pos );
public slots:
void moveMediaItem( const QUuid& uuid, int track, int time );
protected: protected:
virtual void resizeEvent( QResizeEvent* event ); virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect ); virtual void drawBackground( QPainter* painter, const QRectF& rect );
...@@ -111,6 +114,7 @@ private: ...@@ -111,6 +114,7 @@ private:
void addVideoTrack(); void addVideoTrack();
void addAudioTrack(); void addAudioTrack();
void moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position ); void moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
void moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time );
QGraphicsScene* m_scene; QGraphicsScene* m_scene;
int m_tracksHeight; int m_tracksHeight;
unsigned int m_tracksCount; unsigned int m_tracksCount;
......
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