AbstractGraphicsItem.h 6.53 KB
Newer Older
1 2 3 4 5
/*****************************************************************************
 * AbstractGraphiscItem.cpp: Represent an abstract item on the timeline
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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 ABSTRACTGRAPHICSITEM_H
#define ABSTRACTGRAPHICSITEM_H

#include <QGraphicsItem>
27
#include <QUuid>
28 29 30 31 32

class   GraphicsTrack;
class   TrackWorkflow;
class   TracksScene;
class   TracksView;
33
class   EffectUser;
34

35 36 37 38 39
namespace Workflow
{
    class   Helper;
}

40 41
#include "Types.h"

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
class AbstractGraphicsItem : public QObject, public QGraphicsItem
{
    Q_OBJECT

#if QT_VERSION >= 0x40600
    Q_INTERFACES( QGraphicsItem )
#endif

    public:
        enum From
        {
            BEGINNING,
            END
        };
        AbstractGraphicsItem();
        virtual ~AbstractGraphicsItem();

59 60 61 62 63
        virtual const QUuid& uuid() const = 0;

        /// Return the type of the media
        virtual Workflow::TrackType trackType() const = 0;

64 65 66 67 68 69 70 71 72 73 74
        /// Return the Type of the MediaItem (see http://doc.trolltech.com/4.5/qgraphicsitem.html#type)
        virtual int type() const = 0;
        /// Defines the outer bounds of the item as a rectangle
        virtual QRectF boundingRect() const;

        /// The item length can be expanded or shrinked by the user.
        virtual bool expandable() const = 0;

        /// The item can be moved by the user.
        virtual bool moveable() const = 0;

75 76
        virtual qint64      itemHeight() const = 0;

77 78 79 80 81 82 83 84 85 86
        /// Return a pointer to the TracksScene
        TracksScene* scene();

        /// Return the current track of the item
        qint32 trackNumber();

        /// Return the item's parent track
        GraphicsTrack* track();

        /// Set the position of the item (in frames) for the x-axis.
87
        virtual void setStartPos( qint64 position );
88 89

        /// Return the position of the item (in frames) for the x-axis.
90
        qint64 startPos() const;
91 92 93 94 95 96 97

        void    setColor( const QColor& color );
        QColor  itemColor();

        /**
         * \brief    Resize an item from its beginning or from its end.
         */
98 99
        void        resize( qint64 newSize, qint64 newMovingBoundary,
                            qint64 currentStillBoundary, From from = BEGINNING );
100

101 102 103 104 105 106 107 108 109 110 111 112
        /**
         * \brief Return a pointer to the linked item.
         * \details This method will return NULL if there is no linked item.
         */
        AbstractGraphicsItem*   groupItem();

        /// Group two items together
        void                group( AbstractGraphicsItem* item );

        /// Ungroup two items
        void                ungroup();

113 114
        virtual qint64      begin() const = 0;
        virtual qint64      end() const = 0;
115 116
        qint64              width() const;

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
117
        virtual void        triggerMove( EffectUser *target, qint64 startPos ) = 0;
118
        virtual void        triggerResize( EffectUser *tw, Workflow::Helper *helper,
119
                                           qint64 newBegin, qint64 newEnd, qint64 pos ) = 0;
120
        virtual Workflow::Helper    *helper() = 0;
121 122 123
        virtual qint32      zSelected() const = 0;
        virtual qint32      zNotSelected() const = 0;

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    protected:
        virtual void        hoverEnterEvent( QGraphicsSceneHoverEvent* event );
        virtual void        hoverMoveEvent( QGraphicsSceneHoverEvent* event );
        virtual void        mousePressEvent( QGraphicsSceneMouseEvent* event );
        virtual void        mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
        /**
         * \brief Set the width of the item.
         * \param width Width in frames.
         */
        void setWidth( qint64 width );
        /**
         * \brief Set the height of the item.
         * \param height Height in pixels.
         */
        void setHeight( qint64 height );
        /**
         * \details Returns a pointer to the tracksView which contains the item,
         * or NULL if the item is not stored in a tracksView.
         */
        TracksView*         tracksView();
        /**
         *  \returns        True if the item has resize boundaries, false otherwise.
         */
        virtual bool        hasResizeBoundaries() const = 0;
        /**
         *  \brief          Return the begin boundaries for the item.
         */
151
        virtual qint64      maxBegin() const = 0;
152 153 154
        /**
         *  \brief          Return the end boundaries for the item.
         */
155
        virtual qint64      maxEnd() const = 0;
156 157

    protected:
158 159
        static const quint32    RounderRectRadius = 5;

160
        /// This pointer will be set when inserted in the tracksView.
161 162
        TracksView*                 m_tracksView;
        QColor                      m_itemColor;
163
        TrackWorkflow               *m_oldTrack;
164 165

    private:
166 167 168 169
        qint64                      m_width;
        qint64                      m_height;
        /// Pointer used to save the address of a linked item.
        AbstractGraphicsItem*       m_group;
170 171 172 173 174 175 176

    protected slots:
        /**
         * \brief Check if the position given as parameter could be taken as a resize request.
         * \return Returns True if the point is in a resize zone.
         */
        bool                resizeZone( const QPointF& position );
177 178 179 180 181
        /**
         * \brief Adjust the length of the item according to the associated Clip.
         * \details This method should be called when the clip size change
         */
        void adjustLength();
182

183 184 185 186
        /// Set the item's parent track
        void setTrack( GraphicsTrack* track );


187 188
    signals:
        void                moved( qint64 pos );
189
        void                trackChanged( GraphicsTrack *tracks );
190

191 192 193 194 195
        friend class        TracksView;

};

#endif // ABSTRACTGRAPHICSITEM_H