StackedAction.hpp 4.67 KB
Newer Older
1 2 3 4 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
/*****************************************************************************
 * StackedAction.hpp: Stores an action to be executed later
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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.
 *****************************************************************************/

#ifndef STACKEDACTION_H
#define STACKEDACTION_H

#include <QUuid>

#include "MainWorkflow.h"

class   StackedAction
{
    public:
33 34 35 36 37 38 39 40 41
        enum    Type
        {
            Pause,
            Unpause,
            Resize,
            Remove,
            Add,
        };
        StackedAction( Type type ) : m_type( type ) {}
42 43
        virtual ~StackedAction(){}
        virtual void    execute() = 0;
44 45 46 47
        virtual bool    isOpposite( const StackedAction* ) const
        {
            return false;
        }
48 49 50 51 52 53
        Type    getType() const
        {
            return m_type;
        }
    private:
        Type    m_type;
54 55 56 57 58
};

class   WorkflowAction : public StackedAction
{
    public:
59
        WorkflowAction( MainWorkflow* mainWorkflow, Type type ) : StackedAction( type ), m_mainWorkflow( mainWorkflow ) {}
60 61 62 63 64 65 66
    protected:
        MainWorkflow*   m_mainWorkflow;
};

class   TrackAction : public WorkflowAction
{
    public:
67 68
        TrackAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType, Type type ) :
            WorkflowAction( mainWorkflow, type ), m_trackId( trackId ), m_trackType( trackType )
69 70 71 72 73 74 75 76 77 78 79
        {
        }
    protected:
        uint32_t                    m_trackId;
        MainWorkflow::TrackType     m_trackType;
};

class   AddClipAction : public TrackAction
{
    public:
        AddClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
80
                       Clip* clip, qint64 startingPos ) : TrackAction( mainWorkflow, trackId, trackType, Add ),
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
                                                        m_clip( clip ), m_startingPos( startingPos )
        {
        }
        void        execute()
        {
            m_mainWorkflow->addClip( m_clip, m_trackId, m_startingPos, m_trackType );
        }
    protected:
        Clip*       m_clip;
        qint64      m_startingPos;
};

class   RemoveClipAction : public TrackAction
{
    public:
        RemoveClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
97
                       const QUuid& uuid ) : TrackAction( mainWorkflow, trackId, trackType, Remove ),
98 99 100 101 102 103 104 105 106 107 108 109 110 111
                                            m_uuid( uuid )
        {
        }
        void        execute()
        {
            m_mainWorkflow->removeClip( m_uuid, m_trackId, m_trackType );
        }
    protected:
        QUuid       m_uuid;
};

class   ResizeClipAction : public StackedAction
{
    public:
112 113
        ResizeClipAction( Clip* clip, qint64 newBegin, qint64 newEnd ) : StackedAction( Resize ),
                m_clip( clip ), m_newBegin( newBegin ), m_newEnd( newEnd )
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        {
        }
        void    execute()
        {
            m_clip->setBoundaries( m_newBegin, m_newEnd );
        }
    protected:
        Clip*   m_clip;
        qint64  m_newBegin;
        qint64  m_newEnd;
};

class   PauseAction : public WorkflowAction
{
    public:
129
        PauseAction( MainWorkflow* mainWorkflow ) : WorkflowAction( mainWorkflow, Pause )
130 131 132 133 134 135
        {
        }
        void    execute()
        {
            m_mainWorkflow->pause();
        }
136 137 138 139
        bool    isOpposite( const StackedAction* act ) const
        {
            return ( act->getType() == Unpause );
        }
140 141
};

142 143 144
class   UnpauseAction : public WorkflowAction
{
    public:
145
        UnpauseAction( MainWorkflow* mainWorkflow ) : WorkflowAction( mainWorkflow, Unpause )
146 147 148 149 150 151
        {
        }
        void    execute()
        {
            m_mainWorkflow->unpause();
        }
152 153 154 155
        bool    isOpposite( const StackedAction* act ) const
        {
            return ( act->getType() == Pause );
        }
156 157
};

158
#endif // STACKEDACTION_H