Commands.cpp 6.48 KB
Newer Older
1 2 3
/*****************************************************************************
 * Commands.cpp: Contains all the implementation of VLMC commands.
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *          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.
 *****************************************************************************/

#include <QUndoCommand>
#include "Commands.h"
#include "UndoStack.h"
#include "MainWorkflow.h"
#include "Clip.h"

void Commands::trigger( QUndoCommand* command )
{
    UndoStack::getInstance()->push( command );
}

35
Commands::MainWorkflow::AddClip::AddClip( WorkflowRenderer* renderer, Clip* clip,
36
                                          unsigned int trackNumber, qint64 pos,
37
                                          ::MainWorkflow::TrackType trackType ) :
38
        m_renderer( renderer ),
39 40 41 42
        m_clip( clip ),
        m_trackNumber( trackNumber ),
        m_pos( pos ),
        m_trackType( trackType )
43 44 45 46
{
    setText( QObject::tr( "Adding clip to track %1" ).arg( QString::number( trackNumber ) ) );
}

47 48 49 50 51
Commands::MainWorkflow::AddClip::~AddClip()
{
    delete m_clip;
}

52 53
void Commands::MainWorkflow::AddClip::redo()
{
54
    m_renderer->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
55 56 57 58
}

void Commands::MainWorkflow::AddClip::undo()
{
59
    m_renderer->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
60 61 62
}

Commands::MainWorkflow::MoveClip::MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
63
          unsigned int oldTrack, unsigned int newTrack, qint64 newPos,
64
          ::MainWorkflow::TrackType trackType ) :
65
    m_workflow( workflow ), m_uuid( uuid ), m_oldTrack( oldTrack ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
66
    m_newTrack( newTrack ), m_pos( newPos ), m_trackType( trackType )
67
{
68 69 70 71 72
    if ( oldTrack != newTrack )
        setText( QObject::tr( "Moving clip from track %1 to %2" ).arg(
                QString::number( oldTrack ), QString::number( newTrack ) ) );
    else
        setText( QObject::tr( "Moving clip" ) );
73
    m_undoRedoAction = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
74
    m_oldPos = m_workflow->getClipPosition( uuid, oldTrack, trackType );
75 76 77 78
}

void Commands::MainWorkflow::MoveClip::redo()
{
79
//    qDebug() << "Moving clip from track" << m_oldTrack << "to" << m_newTrack << "at position:" << m_pos;
80
    m_workflow->moveClip( m_uuid, m_oldTrack, m_newTrack, m_pos, m_trackType, m_undoRedoAction );
81 82 83 84 85
    m_undoRedoAction = true;
}

void Commands::MainWorkflow::MoveClip::undo()
{
86
//    qDebug() << "Undo moving clip from track" << m_newTrack << "to" << m_oldTrack << "at position:" << m_oldPos;
87
    m_workflow->moveClip( m_uuid, m_newTrack, m_oldTrack, m_oldPos, m_trackType, m_undoRedoAction );
88 89 90
    m_undoRedoAction = true;
}

91 92 93
Commands::MainWorkflow::RemoveClip::RemoveClip( WorkflowRenderer* renderer, Clip* clip, unsigned int trackNumber, qint64 pos, ::MainWorkflow::TrackType trackType ) :
        m_renderer( renderer ), m_clip( clip ), m_trackNumber( trackNumber ),
        m_pos( pos ), m_trackType( trackType )
94 95 96
{
    setText( QObject::tr( "Remove clip" ) );
}
97

98
void Commands::MainWorkflow::RemoveClip::redo()
99
{
100
   m_renderer->removeClip( m_clip->getUuid(), m_trackNumber, m_trackType );
101
}
102
void Commands::MainWorkflow::RemoveClip::undo()
103
{
104
    m_renderer->addClip( m_clip, m_trackNumber, m_pos, m_trackType );
105 106
}

107 108 109 110
Commands::MainWorkflow::ResizeClip::ResizeClip( WorkflowRenderer* renderer, const QUuid& uuid,
                                                qint64 newBegin, qint64 newEnd,
                                                qint64 oldBegin, qint64 oldEnd,
                                                qint64 newPos, qint64 oldPos,
111
                                                quint32 trackId,
112 113 114
                                                ::MainWorkflow::TrackType trackType ) :
    m_renderer( renderer ),
    m_uuid( uuid ),
115
    m_newBegin( newBegin ),
116
    m_newEnd( newEnd ),
117 118 119 120 121 122 123
    m_oldBegin( oldBegin ),
    m_oldEnd( oldEnd ),
    m_newPos( newPos ),
    m_oldPos( oldPos ),
    m_trackId( trackId ),
    m_trackType( trackType ),
    m_undoRedoAction( false )
124
{
125 126
    m_clip = ::MainWorkflow::getInstance()->getClip( uuid, trackId, m_trackType );
    setText( QObject::tr( "Resizing clip" ) );
127 128 129 130
}

void Commands::MainWorkflow::ResizeClip::redo()
{
131 132
    m_renderer->resizeClip( m_clip, m_newBegin, m_newEnd, m_newPos, m_trackId, m_trackType, m_undoRedoAction );
    m_undoRedoAction = true;
133 134 135 136
}

void Commands::MainWorkflow::ResizeClip::undo()
{
137 138 139 140 141 142 143 144 145 146 147 148
    //This code is complete crap.
    // We need to case, because when we redo a "begin-resize", we need to first resize, then move.
    //In the other cases, we need to move, then resize.
    if ( m_oldBegin == m_newBegin )
    {
        m_renderer->resizeClip( m_clip, m_oldBegin, m_oldEnd, m_oldPos, m_trackId, m_trackType, m_undoRedoAction );
    }
    else
    {
        m_clip->setBoundaries( m_oldBegin, m_oldEnd );
        ::MainWorkflow::getInstance()->moveClip( m_clip->getUuid(), m_trackId, m_trackId, m_oldPos, m_trackType, m_undoRedoAction );
    }
149
}
150

151
Commands::MainWorkflow::SplitClip::SplitClip( WorkflowRenderer* renderer, Clip* toSplit, quint32 trackId,
152 153 154 155 156 157 158 159 160 161 162 163
                           qint64 newClipPos, qint64 newClipBegin, ::MainWorkflow::TrackType trackType ) :
    m_renderer( renderer ),
    m_toSplit( toSplit ),
    m_newClip( NULL ),
    m_trackId( trackId ),
    m_newClipPos( newClipPos ),
    m_newClipBegin( newClipBegin ),
    m_trackType( trackType )
{
    setText( QObject::tr("Splitting clip") );
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
164
Commands::MainWorkflow::SplitClip::~SplitClip()
165
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
166 167 168
    if ( m_newClip != NULL )
        delete m_newClip;
}
169

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
170 171 172
void    Commands::MainWorkflow::SplitClip::redo()
{
    m_newClip = m_renderer->split( m_toSplit, m_newClip, m_trackId, m_newClipPos, m_newClipBegin, m_trackType );
173 174 175 176
}

void    Commands::MainWorkflow::SplitClip::undo()
{
177
    m_renderer->unsplit( m_toSplit, m_newClip, m_trackId, m_trackType );
178
}