Commit bbf4d62f authored by Ludovic Fauvet's avatar Ludovic Fauvet

Representation of an object dropped in the timeline.

parent c5c8a717
......@@ -23,7 +23,7 @@
#include "GraphicsMovieItem.h"
#include "TracksView.h"
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip )
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) : m_clip( clip ), m_width( 0 ), m_height( 0 )
{
}
......@@ -32,3 +32,24 @@ GraphicsMovieItem::~GraphicsMovieItem()
{
}
QRectF GraphicsMovieItem::boundingRect() const
{
return QRectF( 0, 0, m_width, m_height );
}
void GraphicsMovieItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
painter->setBrush( Qt::red );
painter->drawRoundedRect( boundingRect(), 5, 5 );
}
void GraphicsMovieItem::setWidth( int width )
{
m_width = width;
}
void GraphicsMovieItem::setHeight( int height )
{
m_height = height;
}
......@@ -37,9 +37,16 @@ public:
virtual bool expandable() const { return false; }
virtual bool moveable() const { return true; }
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 );
private:
Clip* m_clip;
int m_width;
int m_height;
};
#endif // GRAPHICSMOVIEITEM_H
......@@ -27,7 +27,7 @@
#include "TracksScene.h"
Timeline::Timeline( QWidget *parent ) :
QWidget( parent )
QWidget( parent ), m_scale( 1.0 )
{
m_ui.setupUi( this );
......@@ -48,6 +48,10 @@ Timeline::Timeline( QWidget *parent ) :
m_ui.rulerFrame->setLayout( tracksRulerLayout );
tracksRulerLayout->addWidget( m_tracksRuler );
changeZoom( 5 );
m_tracksView->setDuration( 800 );
m_tracksRuler->setDuration( 800 );
connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged( int ) ), m_tracksRuler, SLOT( moveRuler( int ) ) );
}
......@@ -62,3 +66,10 @@ void Timeline::changeEvent( QEvent *e )
break;
}
}
void Timeline::changeZoom( int factor )
{
m_tracksRuler->setPixelPerMark( factor );
m_scale = (double) FRAME_SIZE / m_tracksRuler->comboScale[factor];
m_tracksView->setScale( m_scale );
}
......@@ -37,6 +37,9 @@ public:
TracksView* tracksView() { return m_tracksView; }
TracksScene* tracksScene() { return m_tracksScene; }
public slots:
void changeZoom( int factor );
protected:
virtual void changeEvent( QEvent *e );
......@@ -45,7 +48,7 @@ private:
TracksView* m_tracksView;
TracksScene* m_tracksScene;
TracksRuler* m_tracksRuler;
double m_scale;
};
#endif // TIMELINE_H
......@@ -114,7 +114,7 @@ void TracksRuler::paintEvent( QPaintEvent* e )
offsetMin = offsetMin * m_textSpacing;
for ( f = offsetMin; f < offsetMax; f += m_textSpacing )
{
QString time = QString("00:00:00");
QString time = getTimeCode( (int)( f / m_factor + 0.5 ) );
painter.drawText( ( int )f - m_offset + 2, LABEL_SIZE, time );
}
......@@ -149,3 +149,25 @@ void TracksRuler::moveRuler( int pos )
m_offset = pos;
update();
}
QString TracksRuler::getTimeCode( int frames ) const
{
int seconds = frames / m_fps;
frames = frames % m_fps;
int minutes = seconds / 60;
seconds = seconds % 60;
int hours = minutes / 60;
minutes = minutes % 60;
QString text;
text.append( QString::number( hours ).rightJustified( 2, '0', false ) );
text.append( ':' );
text.append( QString::number( minutes ).rightJustified( 2, '0', false ) );
text.append( ':' );
text.append( QString::number( seconds ).rightJustified( 2, '0', false ) );
text.append( ':' );
text.append( QString::number( frames ).rightJustified( 2, '0', false ) );
return text;
}
......@@ -25,6 +25,7 @@
#include <QWidget>
#include <QPaintEvent>
#include <QString>
const int FRAME_SIZE = 90;
static const int FIX_WIDTH = 24; /* widget width in pixel */
......@@ -59,6 +60,7 @@ protected:
virtual void paintEvent( QPaintEvent* e );
private:
QString getTimeCode( int frames ) const;
int m_duration;
int m_fps;
int m_offset;
......
......@@ -22,7 +22,12 @@
#include <QScrollBar>
#include <QMouseEvent>
#include <QtDebug>
#include <cmath>
#include "TracksView.h"
#include "Clip.h"
#include "Library.h"
#include "GraphicsMovieItem.h"
TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
: QGraphicsView( scene, parent ), m_scene( scene )
......@@ -32,7 +37,7 @@ TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
//TODO should be dynamic
m_tracksCount = 5;
setDuration( 800 );
m_fps = 30;
setMouseTracking( true );
setAcceptDrops( true );
......@@ -56,6 +61,11 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
void TracksView::dropEvent( QDropEvent* event )
{
QUuid uuid = QUuid( (const QString& )event->mimeData()->data( "vlmc/uuid" ) );
Clip* clip = Library::getInstance()->getClip( uuid );
if ( !clip ) return;
addClip( clip, event->pos() );
event->acceptProposedAction();
}
......@@ -130,3 +140,36 @@ void TracksView::setCursorPos(int pos)
m_cursorPos = pos;
m_cursorLine->setPos(m_cursorPos, 0);
}
void TracksView::addClip( Clip* clip, const QPoint& point )
{
int track = (int)( mapToScene( point ).y() / m_tracksHeight );
if ( track + 1 > m_tracksCount ) return;
//mappedXPos: 1 pixel = 1 frame
int mappedXPos = ( int )( mapToScene( point ).x() + 0.5 );
GraphicsMovieItem* item = new GraphicsMovieItem( clip );
item->setPos( mappedXPos, track * tracksHeight() );
item->setWidth( clip->getLength() / m_fps );
item->setHeight( tracksHeight() );
m_scene->addItem( item );
item->show();
}
void TracksView::setScale( double scaleFactor )
{
QMatrix matrix;
matrix.scale( scaleFactor, 1 );
//TODO update the scene scale ?
setMatrix( matrix );
int diff = sceneRect().width() - m_projectDuration;
if ( diff * matrix.m11() < 50 )
{
if ( matrix.m11() < 0.4 )
setSceneRect( 0, 0, ( m_projectDuration + 100 / matrix.m11() ), sceneRect().height() );
else
setSceneRect( 0, 0, ( m_projectDuration + 300 ), sceneRect().height() );
}
}
......@@ -29,6 +29,7 @@
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDragMoveEvent>
#include "Clip.h"
class TracksView : public QGraphicsView
{
......@@ -37,10 +38,12 @@ class TracksView : public QGraphicsView
public:
TracksView( QGraphicsScene* scene, QWidget* parent = 0 );
void setDuration( int duration );
int duration() { return m_projectDuration; }
int tracksHeight() { return m_tracksHeight; }
int tracksCount() { return m_tracksCount; }
int duration() const { return m_projectDuration; }
int tracksHeight() const { return m_tracksHeight; }
int tracksCount() const { return m_tracksCount; }
void setCursorPos( int pos );
void addClip( Clip* clip, const QPoint& point );
void setScale( double scaleFactor );
protected:
virtual void resizeEvent( QResizeEvent* event );
......@@ -57,6 +60,7 @@ private:
int m_tracksCount;
int m_projectDuration;
int m_cursorPos;
int m_fps;
QGraphicsLineItem* m_cursorLine;
};
......
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