AbstractGraphicsItem.h 5.75 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
/*****************************************************************************
 * AbstractGraphiscItem.cpp: Represent an abstract item on the timeline
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
 * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.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.
 *****************************************************************************/

#ifndef ABSTRACTGRAPHICSITEM_H
#define ABSTRACTGRAPHICSITEM_H

#include <QGraphicsItem>

class   GraphicsTrack;
class   TrackWorkflow;
class   TracksScene;
class   TracksView;

33 34 35 36
class   QUuid;

#include "Types.h"

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
class AbstractGraphicsItem : public QObject, public QGraphicsItem
{
    Q_OBJECT

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

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

54 55 56 57 58
        virtual const QUuid& uuid() const = 0;

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

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        /// 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;

        /// Return a pointer to the TracksScene
        TracksScene* scene();

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

        /// Set the item's parent track
        void setTrack( GraphicsTrack* track );

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

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

        /// Return the position of the item (in frames) for the x-axis.
        qint64 startPos();

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

        /**
         * \brief    Resize an item from its beginning or from its end.
         *
         *  \returns    A contextual info (depending on "from") to compute
         *              the new length. (Either the new beginning of the new length)
         */
        qint64      resize( qint64 size, qint64 newBegin, qint64 clipPos, From from = BEGINNING );

99 100 101 102 103 104 105 106 107 108 109 110
        /**
         * \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();

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    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.
         */
        virtual qint64      maxBegin() const { return 0; }
        /**
         *  \brief          Return the end boundaries for the item.
         */
        virtual qint64      maxEnd() const { return -1; }

    protected:
145 146 147 148
        static const quint32    ZSelected = 4;
        static const quint32    ZNotSelected = 3;
        static const quint32    RounderRectRadius = 5;

149
        /// This pointer will be set when inserted in the tracksView.
150 151
        TracksView*                 m_tracksView;
        QColor                      m_itemColor;
152 153

    private:
154 155 156 157 158
        TrackWorkflow               *m_oldTrack;
        qint64                      m_width;
        qint64                      m_height;
        /// Pointer used to save the address of a linked item.
        AbstractGraphicsItem*       m_group;
159 160 161 162 163 164 165 166 167 168 169 170 171

    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 );

        friend class        TracksView;

};

#endif // ABSTRACTGRAPHICSITEM_H