Commit f56a60f4 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Support for clip resizing.

This is a very simple implementation, it does not provide a good
feedback to the user but is usable.
parent 226f85af
......@@ -97,19 +97,26 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
{
Q_ASSERT( clip() );
if ( size > clip()->getLength() )
if ( size > clip()->getParent()->getNbFrames() )
{
qWarning( "AbstractGraphicsMediaItem: Can't expand a clip beyond its original size" );
size = clip()->getLength();
return;
}
if ( size < 0 ) return;
if ( from == BEGINNING )
clip()->setEnd( clip()->getBegin() + size );
else
{
qint64 oldBegin = clip()->getBegin();
clip()->setBegin( clip()->getEnd() - size );
setStartPos( clip()->getBegin() - oldBegin );
qint64 oldLength = clip()->getLength();
if ( ( clip()->getEnd() - size ) < 0 )
{
qWarning( "Warning: resizing a region with a size below 0" );
size += clip()->getEnd() - size;
}
clip()->setBegin( qMax( clip()->getEnd() - size, (qint64)0 ) );
setStartPos( startPos() + ( oldLength - size ) );
}
setWidth( clip()->getLength() );
......
......@@ -29,6 +29,8 @@
#include "GraphicsTrack.hpp"
#include "Clip.h"
#define RESIZE_ZONE 7
class TracksView;
class AbstractGraphicsMediaItem : public QObject, public QGraphicsItem
......
......@@ -186,19 +186,38 @@ void GraphicsMovieItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
AbstractGraphicsMediaItem::hoverLeaveEvent( event );
}
void GraphicsMovieItem::hoverMoveEvent( QGraphicsSceneHoverEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
QPoint mouseMapped = tracksView()->mapFromScene( event->pos() );
QPoint sizeMapped = tracksView()->mapFromScene( boundingRect().width(), boundingRect().height() );
if ( mouseMapped.x() < RESIZE_ZONE ||
mouseMapped.x() > ( sizeMapped.x() - RESIZE_ZONE ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::OpenHandCursor );
}
}
void GraphicsMovieItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv->tool() == TOOL_DEFAULT )
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::ClosedHandCursor );
else if ( tv->tool() == TOOL_CUT )
else if ( tracksView()->tool() == TOOL_CUT )
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 )
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
......@@ -55,6 +55,7 @@ protected:
void paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
......
......@@ -47,6 +47,7 @@ TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, Workf
m_numVideoTrack = 0;
m_dragItem = NULL;
m_actionMove = false;
m_actionResize = false;
m_actionRelativeX = -1;
m_actionItem = NULL;
m_tool = TOOL_DEFAULT;
......@@ -167,6 +168,7 @@ void TracksView::addMediaItem( Clip* clip, unsigned int track, qint64 start )
}
GraphicsMovieItem* item = new GraphicsMovieItem( clip );
item->m_tracksView = this;
item->setHeight( tracksHeight() );
item->setParentItem( getTrack( MainWorkflow::VideoTrack, track ) );
item->setStartPos( start );
......@@ -193,6 +195,7 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
if ( m_dragItem ) delete m_dragItem;
m_dragItem = new GraphicsMovieItem( clip );
m_dragItem->m_tracksView = this;
m_dragItem->setHeight( tracksHeight() );
m_dragItem->setParentItem( m_layout->itemAt( 0 )->graphicsItem() );
connect( m_dragItem, SIGNAL( split(GraphicsMovieItem*,qint64) ),
......@@ -490,6 +493,24 @@ void TracksView::mouseMoveEvent( QMouseEvent* event )
m_actionRelativeX = event->pos().x() - mapFromScene( m_actionItem->pos() ).x();
moveMediaItem( m_actionItem, QPoint( event->pos().x() - m_actionRelativeX, event->pos().y() ) );
}
else if ( event->modifiers() == Qt::NoModifier &&
event->buttons() == Qt::LeftButton &&
m_actionResize == true )
{
QPointF itemPos = m_actionItem->mapToScene( 0, 0 );
QPointF itemNewSize = mapToScene( event->pos() ) - itemPos;
if ( m_actionResizeType == AbstractGraphicsMediaItem::END )
{
qint64 distance = mapToScene( event->pos() ).x() - m_actionResizeStart;
qint64 newsize = qMax( m_actionResizeBase - distance, (qint64)0 );
m_actionItem->resize( newsize , AbstractGraphicsMediaItem::END );
}
else
{
m_actionItem->resize( itemNewSize.x(), AbstractGraphicsMediaItem::BEGINNING );
}
}
QGraphicsView::mouseMoveEvent( event );
}
......@@ -509,11 +530,28 @@ void TracksView::mousePressEvent( QMouseEvent* event )
mediaCollisionList.count() == 1 )
{
AbstractGraphicsMediaItem* item = mediaCollisionList.at( 0 );
if ( item->moveable() )
QPoint itemEndPos = mapFromScene( item->mapToScene( item->boundingRect().bottomRight() ) );
QPoint itemPos = mapFromScene( item->mapToScene( 0, 0 ) );
QPoint clickPos = event->pos() - itemPos;
QPoint itemSize = itemEndPos - itemPos;
if ( clickPos.x() < RESIZE_ZONE || clickPos.x() > ( itemSize.x() - RESIZE_ZONE ) )
{
if ( clickPos.x() < RESIZE_ZONE )
m_actionResizeType = AbstractGraphicsMediaItem::END;
else
m_actionResizeType = AbstractGraphicsMediaItem::BEGINNING;
m_actionResize = true;
m_actionResizeStart = mapToScene( event->pos() ).x();
m_actionResizeBase = item->clip()->getLength();
m_actionItem = item;
}
else if ( item->moveable() )
{
m_actionMove = true;
m_actionMoveExecuted = false;
m_actionItem = mediaCollisionList.at( 0 );
m_actionItem = item;
}
scene()->clearSelection();
item->setSelected( true );
......@@ -564,8 +602,13 @@ void TracksView::mouseReleaseEvent( QMouseEvent* event )
m_actionItem = NULL;
}
}
else if ( m_actionResize )
{
updateDuration();
}
m_actionMove = false;
m_actionResize = false;
setDragMode( QGraphicsView::NoDrag );
QGraphicsView::mouseReleaseEvent( event );
......
......@@ -109,6 +109,10 @@ private:
// Mouse actions on Medias
bool m_actionMove;
bool m_actionMoveExecuted;
bool m_actionResize;
qint64 m_actionResizeStart;
qint64 m_actionResizeBase;
AbstractGraphicsMediaItem::From m_actionResizeType;
int m_actionRelativeX;
AbstractGraphicsMediaItem* m_actionItem;
......
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