Timeline.cpp 6.02 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"
29

30
31
Timeline*   Timeline::m_instance = NULL;

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

39
    m_mainWorkflow = MainWorkflow::getInstance();
40

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

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

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

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


64
    changeZoom( 10 );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
65
    setDuration( 0 );
66
67
68
69
    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
70
71
    connect( m_tracksControls->verticalScrollBar(), SIGNAL( valueChanged(int) ),
             m_tracksView->verticalScrollBar(), SLOT( setValue(int) ) );
72
    connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
73
74
    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 ) ) );
75
    connect( m_mainWorkflow, SIGNAL( clipRemoved(Clip*,uint,MainWorkflow::TrackType ) ), this, SLOT( actionRemoveClip(Clip*,uint,MainWorkflow::TrackType )) );
76
    connect( m_mainWorkflow, SIGNAL( cleared() ), tracksView(), SLOT( clear() ) );
77
    connect( m_mainWorkflow, SIGNAL( cleared() ), m_tracksControls, SLOT( clear() ) );
78
79
80
81
82
83

    connect( m_tracksView, SIGNAL( videoTrackAdded(GraphicsTrack*) ),
             m_tracksControls, SLOT( addVideoTrack(GraphicsTrack*) ) );
    connect( m_tracksView, SIGNAL( audioTrackAdded(GraphicsTrack*) ),
             m_tracksControls, SLOT( addAudioTrack(GraphicsTrack*) ) );

84
85
    connect( m_renderer, SIGNAL( frameChanged(qint64, MainWorkflow::FrameChangedReason) ),
            m_tracksView->tracksCursor(), SLOT( frameChanged( qint64, MainWorkflow::FrameChangedReason ) ),
86
            Qt::QueuedConnection );
87
88
    connect( m_tracksView->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
             m_renderer, SLOT( timelineCursorChanged(qint64) ) );
89
90
    connect( m_renderer, SIGNAL( frameChanged(qint64,MainWorkflow::FrameChangedReason) ), m_tracksRuler, SLOT( update() ) );
    connect( m_tracksRuler, SIGNAL( frameChanged(qint64,MainWorkflow::FrameChangedReason) ),
91
             m_renderer, SLOT( rulerCursorChanged(qint64)) );
92

93
    m_tracksView->createLayout();
94
95
}

96
97
Timeline::~Timeline()
{
98
    MainWorkflow::destroyInstance();
99
100
}

101
void Timeline::changeEvent( QEvent *e )
102
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
103
104
    switch ( e->type() )
    {
105
    case QEvent::LanguageChange:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
106
        m_ui.retranslateUi( this );
107
108
109
110
        break;
    default:
        break;
    }
111
}
112

113
114
115
116
117
118
void Timeline::clear()
{
    // The main workflow will ask the GUI to clear itself.
    m_mainWorkflow->clear();
}

119
120
121
122
123
124
void Timeline::changeZoom( int factor )
{
    m_tracksRuler->setPixelPerMark( factor );
    m_scale = (double) FRAME_SIZE / m_tracksRuler->comboScale[factor];
    m_tracksView->setScale( m_scale );
}
125
126
127
128
129
130

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

132
133
134
135
136
void Timeline::setTool( ToolButtons button )
{
    tracksView()->setTool( button );
}

137
void Timeline::actionAddClip( Clip* clip, unsigned int track, qint64 start, MainWorkflow::TrackType )
138
139
140
141
{
    tracksView()->addMediaItem( clip, track, start );
}

142
void Timeline::actionMoveClip( const QUuid& uuid, unsigned int track, qint64 time, MainWorkflow::TrackType )
143
144
145
146
147
{
    tracksView()->moveMediaItem( uuid, track, time );
    tracksView()->updateDuration();
    tracksRuler()->update();
}
148

149
void Timeline::actionRemoveClip( Clip* clip, unsigned int track, MainWorkflow::TrackType )
150
{
151
    tracksView()->removeMediaItem( clip->getUuid(), track );
152
}