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 ) ...@@ -50,6 +50,7 @@ void MainWindow::changeEvent( QEvent *e )
void MainWindow::m_initializeDockWidgets( void ) void MainWindow::m_initializeDockWidgets( void )
{ {
Timeline* timeline = new Timeline( this ); Timeline* timeline = new Timeline( this );
timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
timeline->show(); timeline->show();
setCentralWidget( timeline ); setCentralWidget( timeline );
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <QHBoxLayout>
#include "Timeline.h" #include "Timeline.h"
#include "TracksView.h" #include "TracksView.h"
#include "TracksScene.h" #include "TracksScene.h"
...@@ -28,8 +29,18 @@ Timeline::Timeline( QWidget *parent ) : ...@@ -28,8 +29,18 @@ Timeline::Timeline( QWidget *parent ) :
QWidget( parent ) QWidget( parent )
{ {
m_ui.setupUi( this ); m_ui.setupUi( this );
m_tracksScene = new TracksScene( this ); m_tracksScene = new TracksScene( this );
m_tracksView = new TracksView( m_tracksScene, m_ui.tracksFrame ); 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 ) void Timeline::changeEvent( QEvent *e )
......
...@@ -33,6 +33,8 @@ class Timeline : public QWidget ...@@ -33,6 +33,8 @@ class Timeline : public QWidget
Q_DISABLE_COPY( Timeline ) Q_DISABLE_COPY( Timeline )
public: public:
explicit Timeline( QWidget *parent = 0 ); explicit Timeline( QWidget *parent = 0 );
TracksView* tracksView() { return m_tracksView; }
TracksScene* tracksScene() { return m_tracksScene; }
protected: protected:
virtual void changeEvent( QEvent *e ); virtual void changeEvent( QEvent *e );
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
class TracksScene : public QGraphicsScene class TracksScene : public QGraphicsScene
{ {
Q_OBJECT
public: public:
TracksScene( QObject* parent = 0 ); TracksScene( QObject* parent = 0 );
}; };
......
...@@ -20,9 +20,59 @@ ...@@ -20,9 +20,59 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <QScrollBar>
#include "TracksView.h" #include "TracksView.h"
TracksView::TracksView( QGraphicsScene* scene, QWidget* parent ) 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 @@ ...@@ -27,8 +27,22 @@
class TracksView : public QGraphicsView class TracksView : public QGraphicsView
{ {
Q_OBJECT
public: public:
TracksView( QGraphicsScene* scene, QWidget* parent = 0 ); 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 #endif // TRACKSVIEW_H
...@@ -6,10 +6,16 @@ ...@@ -6,10 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>429</width> <width>400</width>
<height>167</height> <height>150</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>400</width>
<height>150</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </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