Timeline.cpp 6.38 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*****************************************************************************
 * Timeline.cpp: Widget that handle the tracks
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23
#include <QHBoxLayout>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
24
#include <QScrollBar>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
25
#include <QtDebug>
26
#include "Timeline.h"
27
28
#include "TracksView.h"
#include "TracksScene.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
29
30
31
#include "TracksControls.h"
#include "TracksRuler.h"
#include "WorkflowRenderer.h"
32

33
34
Timeline*   Timeline::m_instance = NULL;

35
36
Timeline::Timeline( WorkflowRenderer* renderer, QWidget *parent ) :
    QWidget( parent ), m_scale( 1.0 ), m_renderer( renderer )
37
{
38
39
    Q_ASSERT( m_instance == NULL );
    m_instance = this;
40
    m_ui.setupUi( this );
41

42
    m_mainWorkflow = MainWorkflow::getInstance();
43

44
    m_tracksScene = new TracksScene( this );
45
    m_tracksView = new TracksView( m_tracksScene, m_mainWorkflow, m_renderer, m_ui.tracksFrame );
46
47
48
    m_tracksView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_tracksView->scale(1, 1);

Ludovic Fauvet's avatar
Ludovic Fauvet committed
49
50
51
52
    QHBoxLayout* tracksViewLayout = new QHBoxLayout();
    tracksViewLayout->setContentsMargins( 0, 0, 0, 0 );
    m_ui.tracksFrame->setLayout( tracksViewLayout );
    tracksViewLayout->addWidget( m_tracksView );
53

Ludovic Fauvet's avatar
Ludovic Fauvet committed
54
    m_tracksRuler = new TracksRuler( tracksView(), this );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
55
56
57
58
59
    QHBoxLayout* tracksRulerLayout = new QHBoxLayout();
    tracksRulerLayout->setContentsMargins( 0, 0, 0, 0 );
    m_ui.rulerFrame->setLayout( tracksRulerLayout );
    tracksRulerLayout->addWidget( m_tracksRuler );

60
61
62
63
64
65
66
    m_tracksControls = new TracksControls( this );
    QHBoxLayout* tracksControlsLayout = new QHBoxLayout();
    tracksControlsLayout->setContentsMargins( 0, 0, 0, 0 );
    m_ui.controlsFrame->setLayout( tracksControlsLayout );
    tracksControlsLayout->addWidget( m_tracksControls );


67
    changeZoom( 10 );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
68
    setDuration( 0 );
69
70

    // Scroll
71
72
73
74
    connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
             m_tracksRuler, SLOT( moveRuler(int) ) );
    connect( m_tracksView->verticalScrollBar(), SIGNAL( valueChanged(int) ),
             m_tracksControls->verticalScrollBar(), SLOT( setValue(int) ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
75
76
    connect( m_tracksControls->verticalScrollBar(), SIGNAL( valueChanged(int) ),
             m_tracksView->verticalScrollBar(), SLOT( setValue(int) ) );
77
78

    // Project duration change
79
    connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
80
81
82
83
84
85
86
87
88
89

    // Clip actions
    connect( m_mainWorkflow, SIGNAL( clipAdded(Clip*,uint,qint64,MainWorkflow::TrackType ) ),
             this, SLOT( actionAddClip(Clip*,uint,qint64,MainWorkflow::TrackType ) ) );
    connect( m_mainWorkflow, SIGNAL( clipMoved(QUuid, uint, qint64,MainWorkflow::TrackType ) ),
             this, SLOT( actionMoveClip(QUuid,uint,qint64,MainWorkflow::TrackType ) ) );
    connect( m_mainWorkflow, SIGNAL( clipRemoved(Clip*,uint,MainWorkflow::TrackType ) ),
             this, SLOT( actionRemoveClip(Clip*,uint,MainWorkflow::TrackType )) );

    // Clear / reset
90
    connect( m_mainWorkflow, SIGNAL( cleared() ), m_tracksControls, SLOT( clear() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
91
    connect( m_mainWorkflow, SIGNAL( cleared() ), tracksView(), SLOT( clear() ) );
92

93
    // Tracks controls
94
95
96
97
98
    connect( m_tracksView, SIGNAL( videoTrackAdded(GraphicsTrack*) ),
             m_tracksControls, SLOT( addVideoTrack(GraphicsTrack*) ) );
    connect( m_tracksView, SIGNAL( audioTrackAdded(GraphicsTrack*) ),
             m_tracksControls, SLOT( addAudioTrack(GraphicsTrack*) ) );

99
    // Frames updates
100
    connect( m_renderer, SIGNAL( frameChanged(qint64, MainWorkflow::FrameChangedReason) ),
101
102
103
104
             m_tracksView->tracksCursor(), SLOT( frameChanged( qint64, MainWorkflow::FrameChangedReason ) ),
             Qt::QueuedConnection );
    connect( m_renderer, SIGNAL( frameChanged(qint64,MainWorkflow::FrameChangedReason) ),
             m_tracksRuler, SLOT( update() ) );
105
    connect( m_tracksRuler, SIGNAL( frameChanged(qint64,MainWorkflow::FrameChangedReason) ),
106
             m_renderer, SLOT( rulerCursorChanged(qint64)) );
107

108
109
110
111
    // Cursor position updates
    connect( m_tracksView->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
             m_renderer, SLOT( timelineCursorChanged(qint64) ) );

112
    m_tracksView->createLayout();
113
114
}

115
116
Timeline::~Timeline()
{
117
    MainWorkflow::destroyInstance();
118
119
}

120
void Timeline::changeEvent( QEvent *e )
121
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
122
123
    switch ( e->type() )
    {
124
    case QEvent::LanguageChange:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
125
        m_ui.retranslateUi( this );
126
127
128
129
        break;
    default:
        break;
    }
130
}
131

132
133
134
135
136
137
void Timeline::clear()
{
    // The main workflow will ask the GUI to clear itself.
    m_mainWorkflow->clear();
}

138
139
140
141
142
143
void Timeline::changeZoom( int factor )
{
    m_tracksRuler->setPixelPerMark( factor );
    m_scale = (double) FRAME_SIZE / m_tracksRuler->comboScale[factor];
    m_tracksView->setScale( m_scale );
}
144
145
146
147
148
149

void Timeline::setDuration( int duration )
{
    m_tracksView->setDuration( duration );
    m_tracksRuler->setDuration( duration );
}
150

151
152
153
154
155
void Timeline::setTool( ToolButtons button )
{
    tracksView()->setTool( button );
}

156
void Timeline::actionAddClip( Clip* clip, unsigned int track, qint64 start, MainWorkflow::TrackType )
157
158
159
160
{
    tracksView()->addMediaItem( clip, track, start );
}

161
void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, MainWorkflow::TrackType )
162
163
{
    tracksView()->moveMediaItem( uuid, track, time );
164
    Q_ASSERT( tracksView()->setItemOldTrack( uuid, track ) == true );
165
166
167
    tracksView()->updateDuration();
    tracksRuler()->update();
}
168

169
void Timeline::actionRemoveClip( Clip* clip, unsigned int track, MainWorkflow::TrackType )
170
{
171
    tracksView()->removeMediaItem( clip->getUuid(), track );
172
}