Commit af2dbf44 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Timeline design (inspired from kdenlive)

parent 2159dd79
......@@ -50,6 +50,7 @@ void MainWindow::changeEvent( QEvent *e )
void MainWindow::m_initializeDockWidgets( void )
{
Timeline* timeline = new Timeline( this );
timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
timeline->show();
setCentralWidget( timeline );
......
......@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QHBoxLayout>
#include "Timeline.h"
#include "TracksView.h"
#include "TracksScene.h"
......@@ -28,8 +29,18 @@ Timeline::Timeline( QWidget *parent ) :
QWidget( parent )
{
m_ui.setupUi( this );
m_tracksScene = new TracksScene( this );
m_tracksView = new TracksView( m_tracksScene, m_ui.tracksFrame );
m_tracksView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_tracksView->scale(1, 1);
m_tracksView->setAlignment( Qt::AlignLeft | Qt::AlignTop );
QHBoxLayout* tracksLayout = new QHBoxLayout();
tracksLayout->setContentsMargins( 0, 0, 0, 0 );
m_ui.tracksFrame->setLayout( tracksLayout );
tracksLayout->addWidget( m_tracksView );
}
void Timeline::changeEvent( QEvent *e )
......
......@@ -33,6 +33,8 @@ class Timeline : public QWidget
Q_DISABLE_COPY( Timeline )
public:
explicit Timeline( QWidget *parent = 0 );
TracksView* tracksView() { return m_tracksView; }
TracksScene* tracksScene() { return m_tracksScene; }
protected:
virtual void changeEvent( QEvent *e );
......
......@@ -27,6 +27,8 @@
class TracksScene : public QGraphicsScene
{
Q_OBJECT
public:
TracksScene( QObject* parent = 0 );
};
......
......@@ -20,9 +20,59 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QScrollBar>
#include "TracksView.h"
TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
: QGraphicsView( scene, parent )
: QGraphicsView( scene, parent ), m_scene( scene )
{
//TODO should be defined by the settings
m_tracksHeight = 50;
//TODO should be dynamic
m_tracksCount = 5;
setDuration( 800 );
setMouseTracking( true );
setAcceptDrops( true );
setContentsMargins( 0, 0, 0, 0 );
const int maxHeight = m_tracksHeight * m_tracksCount;
setSceneRect( 0, 0, sceneRect().width(), maxHeight );
}
void TracksView::setDuration( int duration )
{
int diff = qAbs( duration - sceneRect().width() );
if ( diff * matrix().m11() > -50 )
{
if ( matrix().m11() < 0.4 )
setSceneRect( 0, 0, ( duration + 100 / matrix().m11() ), sceneRect().height() );
else
setSceneRect( 0, 0, ( duration + 300 ), sceneRect().height() );
}
m_projectDuration = duration;
}
void TracksView::resizeEvent( QResizeEvent* event )
{
QGraphicsView::resizeEvent( event );
}
void TracksView::drawBackground( QPainter* painter, const QRectF& rect )
{
QColor base = palette().button().color();
QRectF r = rect;
r.setWidth( r.width() + 1 );
painter->setClipRect( r );
painter->drawLine( r.left(), 0, r.right(), 0 );
uint tracks = m_tracksCount;
for ( uint i = 0; i < tracks; ++i )
painter->drawLine( r.left(), m_tracksHeight * ( i + 1 ), r.right(), m_tracksHeight * ( i + 1 ) );
int lowerLimit = m_tracksHeight * m_tracksCount + 1;
if ( height() > lowerLimit )
painter->fillRect( QRectF ( r.left(), lowerLimit, r.width(), height() - lowerLimit ), QBrush( base ) );
}
......@@ -27,8 +27,22 @@
class TracksView : public QGraphicsView
{
Q_OBJECT
public:
TracksView( QGraphicsScene* scene, QWidget* parent = 0 );
void setDuration( int duration );
int duration() { return m_projectDuration; }
protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect );
private:
QGraphicsScene* m_scene;
int m_tracksHeight;
int m_tracksCount;
int m_projectDuration;
};
#endif // TRACKSVIEW_H
......@@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>429</width>
<height>167</height>
<width>400</width>
<height>150</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>150</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
......
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