StackedAction.hpp 4.98 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
/*****************************************************************************
 * 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"

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

58 59 60 61 62 63 64
    class   Workflow : public Generic
    {
        public:
            Workflow( MainWorkflow* mainWorkflow, Type type ) : Generic( type ), m_mainWorkflow( mainWorkflow ) {}
        protected:
            MainWorkflow*   m_mainWorkflow;
    };
65

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

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    class   AddClip : public Track
    {
        public:
            AddClip( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
                           Clip* clip, qint64 startingPos ) : Track( mainWorkflow, trackId, trackType, Add ),
                                                            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;
    };
94

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

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

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

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    class   Unpause : public Workflow
    {
        public:
            Unpause( MainWorkflow* mainWorkflow ) : Workflow( mainWorkflow, Generic::Unpause )
            {
            }
            void    execute()
            {
                m_mainWorkflow->unpause();
            }
            bool    isOpposite( const Generic* act ) const
            {
                return ( act->getType() == Generic::Pause );
            }
    };
}
160
#endif // STACKEDACTION_H