Commit be57b1f6 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Extend resizing capabilities to the GraphicsMedia items

parent 57f680e8
......@@ -23,7 +23,8 @@
#include "AbstractGraphicsMediaItem.h"
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem() :
oldTrackNumber( -1 ), oldPosition( -1 ), m_tracksView( NULL ), m_group( NULL )
oldTrackNumber( -1 ), oldPosition( -1 ), m_tracksView( NULL ),
m_group( NULL ), m_width( 0 ), m_height( 0 )
{
}
......@@ -33,6 +34,23 @@ TracksView* AbstractGraphicsMediaItem::tracksView()
return m_tracksView;
}
QRectF AbstractGraphicsMediaItem::boundingRect() const
{
return QRectF( 0, 0, (qreal)m_width, (qreal)m_height );
}
void AbstractGraphicsMediaItem::setWidth( qint64 width )
{
prepareGeometryChange();
m_width = width;
}
void AbstractGraphicsMediaItem::setHeight( qint64 height )
{
prepareGeometryChange();
m_height = height;
}
quint32 AbstractGraphicsMediaItem::trackNumber()
{
if ( parentItem() )
......@@ -74,3 +92,31 @@ qint64 AbstractGraphicsMediaItem::startPos()
{
return qRound64( QGraphicsItem::pos().x() );
}
void AbstractGraphicsMediaItem::resize( qint64 size, From from )
{
Q_ASSERT( clip() );
if ( size > clip()->getLength() )
{
qWarning( "AbstractGraphicsMediaItem: Can't expand a clip beyond its original size" );
size = clip()->getLength();
}
if ( from == BEGINNING )
clip()->setEnd( clip()->getBegin() + size );
else
{
qint64 oldBegin = clip()->getBegin();
clip()->setBegin( clip()->getEnd() - size );
setStartPos( clip()->getBegin() - oldBegin );
}
setWidth( clip()->getLength() );
}
void AbstractGraphicsMediaItem::adjustLength()
{
Q_ASSERT( clip() );
resize( clip()->getLength() );
}
......@@ -27,6 +27,7 @@
#include <QUuid>
#include <QCursor>
#include "GraphicsTrack.hpp"
#include "Clip.h"
class TracksView;
......@@ -35,9 +36,18 @@ class AbstractGraphicsMediaItem : public QObject, public QGraphicsItem
Q_OBJECT
friend class TracksView;
public:
enum From
{
BEGINNING,
END
};
AbstractGraphicsMediaItem();
virtual ~AbstractGraphicsMediaItem() { }
/// Defines the outer bounds of the item as a rectangle
virtual QRectF boundingRect() const;
/// Return the Type of the MediaItem (see http://doc.trolltech.com/4.5/qgraphicsitem.html#type)
virtual int type() const = 0;
......@@ -71,6 +81,9 @@ public:
/// Return the position of the item (in frames) for the x-axis.
qint64 startPos();
/// Resize an item from its beginning or from its end.
void resize( qint64 size, From from = BEGINNING );
protected:
/**
* Returns the current tracksView for the item,
......@@ -93,6 +106,12 @@ protected:
*/
AbstractGraphicsMediaItem* groupItem();
void setWidth( qint64 width );
void setHeight( qint64 height );
protected slots:
void adjustLength();
private:
/// This pointer will be set when inserted in the tracksView.
TracksView* m_tracksView;
......@@ -100,6 +119,8 @@ private:
/// Pointer used to save the address of a linked item.
AbstractGraphicsMediaItem* m_group;
qint64 m_width;
qint64 m_height;
};
#endif // ABSTRACTGRAPHICSMEDIAITEM_H
......@@ -28,7 +28,7 @@
#include "TracksView.h"
#include "Timeline.h"
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip ), m_width( 0 ), m_height( 0 )
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip )
{
setFlags( QGraphicsItem::ItemIsSelectable );
......@@ -42,7 +42,7 @@ GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip ), m_width( 0
// Adjust the width
setWidth( clip->getLength() );
// Automatically adjust future changes
// Automatically adjust for future changes
connect( clip, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
}
......@@ -55,11 +55,6 @@ MainWorkflow::TrackType GraphicsMovieItem::mediaType() const
return MainWorkflow::VideoTrack;
}
QRectF GraphicsMovieItem::boundingRect() const
{
return QRectF( 0, 0, m_width, m_height );
}
void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* )
{
painter->save();
......@@ -71,30 +66,6 @@ void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->restore();
}
void GraphicsMovieItem::setWidth( int width )
{
prepareGeometryChange();
m_width = width;
}
void GraphicsMovieItem::setHeight( int height )
{
prepareGeometryChange();
m_height = height;
}
void GraphicsMovieItem::adjustLength()
{
//FIXME implement clip expanding.
if ( m_clip->getLength() > m_width )
{
qWarning( "adjustLength: Clip expanding not supported!" );
return ;
}
prepareGeometryChange();
setWidth( m_clip->getLength() );
}
Clip* GraphicsMovieItem::clip() const
{
return m_clip;
......
......@@ -46,11 +46,8 @@ public:
virtual bool moveable() const { return true; }
virtual const QUuid& uuid() const { return m_clip->getUuid(); }
virtual MainWorkflow::TrackType mediaType() const;
virtual QRectF boundingRect() const;
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
void setWidth( int width );
void setHeight( int height );
virtual Clip* clip() const;
protected:
......@@ -61,13 +58,8 @@ protected:
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
private slots:
void adjustLength();
private:
Clip* m_clip;
int m_width;
int m_height;
signals:
void split( GraphicsMovieItem* self, qint64 frame );
......
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