Commit d02ed257 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Timeline: many improvements

- added an arrow in the ruler sticked to the cursor
- the height of the ruler has been increased
- small fix to avoid a 1 pixel width for the project duration
parent e5fca81b
......@@ -43,16 +43,17 @@ Timeline::Timeline( QWidget *parent ) :
m_ui.tracksFrame->setLayout( tracksViewLayout );
tracksViewLayout->addWidget( m_tracksView );
m_tracksRuler = new TracksRuler( this );
m_tracksRuler = new TracksRuler( tracksView(), this );
QHBoxLayout* tracksRulerLayout = new QHBoxLayout();
tracksRulerLayout->setContentsMargins( 0, 0, 0, 0 );
m_ui.rulerFrame->setLayout( tracksRulerLayout );
tracksRulerLayout->addWidget( m_tracksRuler );
changeZoom( 10 );
setDuration( 1 );
setDuration( 0 );
connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged( int ) ), m_tracksRuler, SLOT( moveRuler( int ) ) );
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
connect( m_tracksView, SIGNAL( cursorPositionChanged(int) ), m_tracksRuler, SLOT( update() ) );
}
void Timeline::changeEvent( QEvent *e )
......
......@@ -24,12 +24,14 @@
#include <QBrush>
#include <QColor>
#include <QPalette>
#include <QPolygon>
#include "TracksRuler.h"
#include "TracksView.h"
const int TracksRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000, 12000};
TracksRuler::TracksRuler( QWidget* parent )
: QWidget( parent ), m_duration ( 0 ), m_offset( 0 )
TracksRuler::TracksRuler( TracksView* tracksView, QWidget* parent )
: QWidget( parent ), m_duration ( 0 ), m_offset( 0 ), m_tracksView( tracksView )
{
m_fps = 30;
m_factor = 1;
......@@ -37,7 +39,7 @@ TracksRuler::TracksRuler( QWidget* parent )
m_littleMarkDistance = FRAME_SIZE;
m_mediumMarkDistance = FRAME_SIZE * m_fps;
m_bigMarkDistance = FRAME_SIZE * m_fps * 60;
setMinimumHeight( 20 );
setMinimumHeight( 30 );
setPixelPerMark( 5 );
}
......@@ -99,7 +101,8 @@ void TracksRuler::paintEvent( QPaintEvent* e )
// Draw the background
const int projectEnd = ( int )( m_duration * m_factor );
painter.fillRect( 0, 0, projectEnd - m_offset, height(), QBrush( QColor( 245, 245, 245 ) ) );
if ( projectEnd - m_offset > 1 )
painter.fillRect( 0, 0, projectEnd - m_offset, height(), QBrush( QColor( 245, 245, 245 ) ) );
double f, step;
......@@ -115,7 +118,7 @@ void TracksRuler::paintEvent( QPaintEvent* e )
for ( f = offsetMin; f < offsetMax; f += m_textSpacing )
{
QString time = getTimeCode( (int)( f / m_factor + 0.5 ) );
painter.drawText( ( int )f - m_offset + 2, LABEL_SIZE, time );
painter.drawText( ( int )f - m_offset + 2, LABEL_SIZE + 1, time );
}
......@@ -141,7 +144,12 @@ void TracksRuler::paintEvent( QPaintEvent* e )
for ( f = offsetMin - m_offset; f < offsetMax - m_offset; f += step )
painter.drawLine( ( int )f, BIG_MARK_X1, ( int )f, BIG_MARK_X2 );
// Draw the pointer
int cursorPos = m_tracksView->cursorPos() * m_factor - offset();
QPolygon cursor( 3 );
cursor.setPoints( 3, cursorPos - 9, 11, cursorPos + 9, 11, cursorPos, 30 );
painter.setBrush( QBrush( QColor( 82, 97, 122, 150 ) ) );
painter.drawPolygon( cursor );
}
void TracksRuler::moveRuler( int pos )
......
......@@ -26,9 +26,10 @@
#include <QWidget>
#include <QPaintEvent>
#include <QString>
#include "TracksView.h"
const int FRAME_SIZE = 90;
static const int FIX_WIDTH = 24; /* widget width in pixel */
static const int FIX_WIDTH = 30; /* widget width in pixel */
static const int LINE_END = (FIX_WIDTH - 3);
static const int END_MARK_LENGTH = (FIX_WIDTH - 8);
static const int BIG_MARK_LENGTH = (END_MARK_LENGTH * 3 / 4);
......@@ -48,10 +49,11 @@ class TracksRuler : public QWidget
Q_OBJECT
public:
TracksRuler( QWidget* parent = 0 );
TracksRuler( TracksView* tracksView, QWidget* parent = 0 );
void setDuration( int duration );
void setPixelPerMark( double rate );
static const int comboScale[];
int offset() const { return m_offset; }
public slots:
void moveRuler( int pos );
......@@ -61,6 +63,7 @@ protected:
private:
QString getTimeCode( int frames ) const;
TracksView* m_tracksView;
int m_duration;
int m_fps;
int m_offset;
......
......@@ -43,13 +43,14 @@ TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
setMouseTracking( true );
setAcceptDrops( true );
setContentsMargins( 0, 0, 0, 0 );
setFrameStyle( QFrame::NoFrame );
// Adjust the height using the number of tracks
const int maxHeight = m_tracksHeight * m_tracksCount;
setSceneRect( 0, 0, sceneRect().width(), maxHeight );
m_cursorPos = 0;
m_cursorLine = m_scene->addLine( 0, 0, 0, maxHeight );
m_cursorLine = m_scene->addLine( 0, 0, 0, maxHeight, QPen( QColor( 220, 30, 30 ) ) );
m_cursorLine->setZValue( 100 );
}
......@@ -177,10 +178,16 @@ void TracksView::wheelEvent( QWheelEvent* event )
}
}
void TracksView::setCursorPos(int pos)
void TracksView::setCursorPos( int pos )
{
m_cursorPos = pos;
m_cursorLine->setPos( m_cursorPos, 0 );
emit cursorPositionChanged( pos );
}
int TracksView::cursorPos()
{
return m_cursorPos;
}
void TracksView::addClip( Media* clip, const QPoint& point )
......
......@@ -43,6 +43,7 @@ public:
int tracksHeight() const { return m_tracksHeight; }
int tracksCount() const { return m_tracksCount; }
void setCursorPos( int pos );
int cursorPos();
void addClip( Media* clip, const QPoint& point );
void setScale( double scaleFactor );
......@@ -70,6 +71,7 @@ signals:
void zoomIn();
void zoomOut();
void durationChanged( int duration );
void cursorPositionChanged( int pos );
};
#endif // TRACKSVIEW_H
......@@ -62,7 +62,7 @@
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
<height>30</height>
</size>
</property>
<property name="frameShape">
......
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