Commit ca06ebce authored by Ludovic Fauvet's avatar Ludovic Fauvet

Emit a signal when a clip is moved

parent 077b7674
......@@ -27,12 +27,12 @@
#include "GraphicsMovieItem.h"
#include "TracksView.h"
GraphicsMovieItem::GraphicsMovieItem( Media* media ) : m_media ( media ), m_width( 0 ), m_height( 0 )
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip ), m_width( 0 ), m_height( 0 )
{
QTime length = QTime().addMSecs( media->getLength() );
QTime length = QTime().addMSecs( clip->getParent()->getLength() );
QString tooltip( tr( "<p style='white-space:pre'><b>Name:</b> %1"
"<br><b>Length:</b> %2" )
.arg( media->getFileInfo()->fileName() )
.arg( clip->getParent()->getFileInfo()->fileName() )
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
}
......@@ -81,14 +81,14 @@ void GraphicsMovieItem::paintAudioSpectrum( QPainter* painter )
QLineF line;
for (int i = 0; i < m_media->getAudioFrameList().size(); i++)
for (int i = 0; i < m_clip->getParent()->getAudioFrameList().size(); i++)
{
//qDebug() << "Frame: " << i << "/" << m_media->getAudioFrameList().size();
for (unsigned int u = 0; u < m_media->getAudioNbSample(); u += 400)
for (unsigned int u = 0; u < m_clip->getParent()->getAudioNbSample(); u += 400)
{
int value = m_media->getAudioFrameList()[i][u];
int value = m_clip->getParent()->getAudioFrameList()[i][u];
value /= 30;
if( value > 48 ) value = 48;
if( value < 0 ) value = 0;
......@@ -114,7 +114,7 @@ void GraphicsMovieItem::paintAudioSpectrum( QPainter* painter )
}
}
Media* GraphicsMovieItem::media() const
Clip* GraphicsMovieItem::clip() const
{
return m_media;
return m_clip;
}
......@@ -24,6 +24,7 @@
#define GRAPHICSMOVIEITEM_H
#include "AbstractGraphicsMediaItem.h"
#include "Clip.h"
#include "Media.h"
#include "TracksView.h"
......@@ -32,24 +33,24 @@ class GraphicsMovieItem : public AbstractGraphicsMediaItem
Q_OBJECT
public:
enum { Type = UserType + 1 };
GraphicsMovieItem( Media* media );
GraphicsMovieItem( Clip* clip );
virtual ~GraphicsMovieItem();
virtual int type() const { return Type; }
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
virtual const QUuid& uuid() const { return m_media->getUuid(); }
virtual const QUuid& uuid() const { return m_clip->getUuid(); }
virtual QRectF boundingRect() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
void setWidth( int width );
void setHeight( int height );
Media* media() const;
Clip* clip() const;
//void setAudioSpectrum( QVector<float*> spectrum );
void paintAudioSpectrum( QPainter* painter );
private:
Media* m_media;
Clip* m_clip;
int m_width;
int m_height;
QVector<float*> m_audioSpectrum;
......
......@@ -139,7 +139,7 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
if ( m_dragItem ) delete m_dragItem;
m_dragItem = new GraphicsMovieItem( media );
m_dragItem = new GraphicsMovieItem( new Clip( media ) );
m_dragItem->setWidth( ( (double)media->getLength() / 1000 ) * m_fps );
m_dragItem->setHeight( tracksHeight() );
m_dragItem->setPos( mappedXPos, 0 );
......@@ -251,9 +251,9 @@ void TracksView::dropEvent( QDropEvent* event )
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
//FIXME this leaks, but it will be corrected once we really use Clip instead
// of Media
m_mainWorkflow->addClip( new Clip( m_dragItem->media() ),
m_videoTracksCounter + track, (qint64)mappedXPos );
m_mainWorkflow->addClip( m_dragItem->clip(),
m_videoTracksCounter + track,
(qint64)mappedXPos );
m_dragItem = NULL; // Temporary action
}
}
......@@ -358,12 +358,23 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
{
if ( m_actionMove )
{
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
m_actionMove = false;
m_actionRelativeX = -1;
m_actionItem = NULL;
GraphicsMovieItem* movieItem = qgraphicsitem_cast<GraphicsMovieItem*>( m_actionItem );
if ( movieItem )
{
updateDuration();
if ( m_layout->itemAt( 0 )->graphicsItem()->childItems().count() > 0 )
addVideoTrack();
int track = (unsigned int)( mapToScene( movieItem->pos().toPoint() ).y() / m_tracksHeight );
if ( track > m_numVideoTrack - 1)
track = m_numVideoTrack - 1;
emit clipMoved( movieItem->clip()->getUuid(),
m_videoTracksCounter + track,
(qint64)movieItem->pos().x() );
m_actionMove = false;
m_actionRelativeX = -1;
m_actionItem = NULL;
}
}
setDragMode( QGraphicsView::NoDrag );
......
......@@ -134,6 +134,7 @@ signals:
void zoomIn();
void zoomOut();
void durationChanged( int duration );
void clipMoved( const QUuid& uuid, int track, qint64 start );
};
#endif // TRACKSVIEW_H
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