Commit 6566340f authored by Ludovic Fauvet's avatar Ludovic Fauvet

Timeline: Implement clip splitting (not fully working)

Some bugs that can't be solved easily prevents this feature to function
properly. Anyway, I let the issue on hold on the bug tracker.
parent c8d48a58
......@@ -25,7 +25,7 @@
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem() :
oldTrackNumber( -1 ), oldPosition( -1 ), m_tracksView( NULL )
{
resetCursor();
}
TracksView* AbstractGraphicsMediaItem::tracksView()
......@@ -33,16 +33,6 @@ TracksView* AbstractGraphicsMediaItem::tracksView()
return m_tracksView;
}
void AbstractGraphicsMediaItem::mousePressEvent( QGraphicsSceneMouseEvent* )
{
setCursor( Qt::ClosedHandCursor );
}
void AbstractGraphicsMediaItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* )
{
setCursor( Qt::OpenHandCursor );
}
quint32 AbstractGraphicsMediaItem::trackNumber()
{
if ( parentItem() )
......@@ -53,8 +43,3 @@ quint32 AbstractGraphicsMediaItem::trackNumber()
}
return -1;
}
void AbstractGraphicsMediaItem::resetCursor()
{
setCursor( Qt::OpenHandCursor );
}
......@@ -53,9 +53,6 @@ public:
/// Return the current track of the item
quint32 trackNumber();
/// Reset the cursor to its default value
void resetCursor();
protected:
/**
* Returns the current tracksView for the item,
......@@ -72,9 +69,6 @@ protected:
*/
qint64 oldPosition;
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
private:
/// This pointer will be set when inserted in the tracksView.
TracksView* m_tracksView;
......
......@@ -83,7 +83,8 @@ void GraphicsMovieItem::setHeight( int height )
void GraphicsMovieItem::adjustLength()
{
//FIXME implement clip expanding.
Q_ASSERT( m_clip->getLength() <= m_width );
Q_ASSERT_X( m_clip->getLength() <= m_width, "adjustLength", "Clip expanding not supported!" );
prepareGeometryChange();
setWidth( m_clip->getLength() );
}
......@@ -234,7 +235,7 @@ void GraphicsMovieItem::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
switch ( tv->tool() )
{
case TOOL_DEFAULT:
resetCursor();
setCursor( Qt::OpenHandCursor );
break;
case TOOL_CUT:
......@@ -250,3 +251,20 @@ void GraphicsMovieItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
{
AbstractGraphicsMediaItem::hoverLeaveEvent( event );
}
void GraphicsMovieItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv->tool() == TOOL_DEFAULT )
setCursor( Qt::ClosedHandCursor );
else
emit split( this, qRound64( event->pos().x() ) );
}
void GraphicsMovieItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
Q_UNUSED( event );
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
......@@ -59,6 +59,8 @@ protected:
void paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
private slots:
void adjustLength();
......@@ -68,6 +70,9 @@ private:
int m_width;
int m_height;
QVector<float*> m_audioSpectrum;
signals:
void split( GraphicsMovieItem* self, qint64 frame );
};
#endif // GRAPHICSMOVIEITEM_H
......@@ -189,6 +189,8 @@ void TracksView::addMediaItem( Clip* clip, unsigned int track, qint64 start )
item->setHeight( tracksHeight() );
item->setParentItem( getTrack( track ) );
item->oldTrackNumber = track;
connect( item, SIGNAL( split(GraphicsMovieItem*,qint64) ),
this, SLOT( split(GraphicsMovieItem*,qint64) ) );
moveMediaItem( item, track, start );
updateDuration();
......@@ -203,13 +205,12 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
Clip* clip = Library::getInstance()->getClip( uuid );
if ( !clip ) return;
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
if ( m_dragItem ) delete m_dragItem;
m_dragItem = new GraphicsMovieItem( clip );
m_dragItem->setHeight( tracksHeight() );
m_dragItem->setPos( mappedXPos, 0 );
m_dragItem->setParentItem( m_layout->itemAt( 0 )->graphicsItem() );
connect( m_dragItem, SIGNAL( split(GraphicsMovieItem*,qint64) ),
this, SLOT( split(GraphicsMovieItem*,qint64) ) );
moveMediaItem( m_dragItem, event->pos() );
}
......@@ -439,6 +440,8 @@ void TracksView::setDuration( int duration )
void TracksView::setTool( ToolButtons button )
{
m_tool = button;
if ( m_tool == TOOL_CUT )
scene()->clearSelection();
}
void TracksView::resizeEvent( QResizeEvent* event )
......@@ -500,9 +503,11 @@ void TracksView::mousePressEvent( QMouseEvent* event )
if ( event->modifiers() == Qt::ControlModifier && mediaCollisionList.count() == 0 )
{
setDragMode( QGraphicsView::ScrollHandDrag );
event->accept();
}
else if ( event->modifiers() == Qt::NoModifier &&
event->button() == Qt::LeftButton &&
tool() == TOOL_DEFAULT &&
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem* item = mediaCollisionList.at( 0 );
......@@ -514,19 +519,23 @@ void TracksView::mousePressEvent( QMouseEvent* event )
}
scene()->clearSelection();
item->setSelected( true );
event->accept();
}
else if ( event->modifiers() == Qt::ControlModifier &&
event->button() == Qt::LeftButton &&
tool() == TOOL_DEFAULT &&
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem* item = mediaCollisionList.at( 0 );
item->setSelected( !item->isSelected() );
event->accept();
}
else if ( event->modifiers() & Qt::ShiftModifier && mediaCollisionList.count() == 0 )
{
setDragMode( QGraphicsView::RubberBandDrag );
if ( !event->modifiers() & Qt::ControlModifier )
scene()->clearSelection();
event->accept();
}
QGraphicsView::mousePressEvent( event );
......@@ -671,3 +680,16 @@ GraphicsTrack* TracksView::getTrack( unsigned int number )
}
return NULL;
}
void TracksView::split( GraphicsMovieItem* item, qint64 frame )
{
Q_ASSERT( item );
Clip* newclip = item->clip()->split( frame );
Q_ASSERT( newclip );
addMediaItem( newclip, item->trackNumber(), item->pos().x() + frame );
Commands::trigger( new Commands::MainWorkflow::AddClip( m_mainWorkflow,
newclip,
item->trackNumber(),
item->pos().x() + frame ) );
}
......@@ -82,6 +82,7 @@ protected:
private slots:
void ensureCursorVisible();
void updateDuration();
void split( GraphicsMovieItem* item, qint64 frame );
private:
void createLayout();
......
......@@ -179,9 +179,18 @@ void Clip::setEnd( float end )
Clip* Clip::split( float newEnd )
{
Q_ASSERT( newEnd != m_end );
Clip* newClip = new Clip( this, newEnd, m_end );
m_end = newEnd;
computeLength();
emit lengthUpdated();
return newClip;
}
Clip* Clip::split( qint64 endFrame )
{
//FIXME the conversion *breaks* clip spliting
//But we don't have any other choice for now, VLC only support float positions!
float newEnd = (float) endFrame / m_length;
return split( newEnd );
}
......@@ -104,10 +104,17 @@ class Clip : public QObject
* \brief Split this clip in two parts.
* \param newEnd The new end for this Clip. This will be the beginning of the
* newly created Clip.
* \returns The remaining part as a new Clip.
* \returns A new Clip starting at newEnd.
*/
Clip* split( float newEnd );
/**
* \brief Split this clip in two parts (provided for compatibility)
* \param newEnd The new end for this clip (provided for compatibility)
* \returns A new Clip starting at endFrame.
*/
Clip* split( qint64 endFrame );
private:
void computeLength();
......
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