AbstractGraphicsItem.h 6.21 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
class   QUuid;

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 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.
         */
99 100
        void        resize( qint64 newSize, qint64 newMovingBoundary,
                            qint64 currentStillBoundary, From from = BEGINNING );
101

102 103 104 105 106 107 108 109 110 111 112 113
        /**
         * \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();

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

118 119
        virtual void        triggerMove( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
                                         Workflow::Helper *helper, qint64 pos ) = 0;
120 121
        virtual void        triggerResize( TrackWorkflow *tw, Workflow::Helper *helper,
                                           qint64 newBegin, qint64 newEnd, qint64 pos ) = 0;
122 123
        virtual Workflow::Helper    *helper() = 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 151 152 153 154 155 156 157
    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:
158 159 160 161
        static const quint32    ZSelected = 4;
        static const quint32    ZNotSelected = 3;
        static const quint32    RounderRectRadius = 5;

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

    private:
167 168 169 170 171
        TrackWorkflow               *m_oldTrack;
        qint64                      m_width;
        qint64                      m_height;
        /// Pointer used to save the address of a linked item.
        AbstractGraphicsItem*       m_group;
172 173 174 175 176 177 178 179 180 181 182 183 184

    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