1 /***************************************************************************
2 * Copyright (C) 2008 by Marco Gittler (g.marco@freenet.de) *
3 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #ifndef ABSTRACTCLIPITEM
22 #define ABSTRACTCLIPITEM
24 #include <QGraphicsRectItem>
25 #include <QGraphicsWidget>
27 #if QT_VERSION >= 0x040600
28 #include <QPropertyAnimation>
31 #include "definitions.h"
34 class CustomTrackScene;
35 class QGraphicsSceneMouseEvent;
37 class AbstractClipItem : public QObject, public QGraphicsRectItem
40 Q_PROPERTY(QRectF rect READ rect WRITE setRect)
41 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
44 AbstractClipItem(const ItemInfo &info, const QRectF& rect, double fps);
45 virtual ~ AbstractClipItem();
46 void updateSelectedKeyFrame();
48 /** @brief Move the selected keyframe (does not influence the effect, only the display in timeline).
49 * @param pos new Position
50 * @param value new Value */
51 void updateKeyFramePos(const GenTime &pos, const double value);
52 int addKeyFrame(const GenTime &pos, const double value);
53 bool hasKeyFrames() const;
54 int editedKeyFramePos() const;
55 int selectedKeyFramePos() const;
56 double selectedKeyFrameValue() const;
57 double editedKeyFrameValue() const;
58 double keyFrameFactor() const;
59 /** @brief Returns the number of keyframes the selected effect has. */
60 int keyFrameNumber() const;
61 ItemInfo info() const;
62 CustomTrackScene* projectScene();
63 void updateRectGeometry();
65 void setItemLocked(bool locked);
66 bool isItemLocked() const;
67 void closeAnimation();
69 virtual OPERATIONTYPE operationMode(QPointF pos) = 0;
70 virtual GenTime startPos() const ;
71 virtual void setTrack(int track);
72 virtual GenTime endPos() const ;
73 virtual int defaultZValue() const ;
74 virtual int track() const ;
75 virtual GenTime cropStart() const ;
76 virtual GenTime cropDuration() const ;
77 /** @brief Return the current item's height */
78 static int itemHeight();
79 /** @brief Return the current item's vertical offset
80 * For example transitions are drawn at 1/3 of track height */
81 static int itemOffset();
83 /** @brief Resizes the clip from the start.
84 * @param posx Absolute position of new in point
85 * @param hasSizeLimit (optional) Whether the clip has a maximum size */
86 virtual void resizeStart(int posx, bool hasSizeLimit = true, bool emitChange = true);
88 /** @brief Resizes the clip from the end.
89 * @param posx Absolute position of new out point */
90 virtual void resizeEnd(int posx, bool emitChange = true);
91 virtual double fps() const;
92 virtual void updateFps(double fps);
93 virtual GenTime maxDuration() const;
94 virtual void setCropStart(GenTime pos);
96 /** @brief Set this clip as the main selected clip (or not). */
97 void setMainSelectedClip(bool selected);
98 /** @brief Is this clip selected as the main clip. */
99 bool isMainSelectedClip();
103 /** The position of the current keyframe when it has moved */
104 int m_editedKeyframe;
105 /** The position of the current keyframe before it was moved */
106 int m_selectedKeyframe;
107 /* GenTime m_cropStart;
108 GenTime m_cropDuration;
109 GenTime m_startPos;*/
110 GenTime m_maxDuration;
111 QMap <int, int> m_keyframes;
112 /** @brief Strech factor so that keyframes display on the full clip height. */
113 double m_keyframeFactor;
114 /** @brief Offset factor so that keyframes minimum value are displaed at the bottom of the clip. */
115 double m_keyframeOffset;
116 /** @brief Default reset value for keyframe. */
117 double m_keyframeDefault;
118 /** The (keyframe) parameter that is visible and editable in timeline (on the clip) */
121 /** @brief True if this is the last clip the user selected */
122 bool m_isMainSelectedClip;
123 /** @brief Draw the keyframes of a clip
124 * @param painter The painter device for the clip
125 * @param limitedKeyFrames The keyframes can be of type "keyframe" or "simplekeyframe". In the
126 * "simplekeyframe" type, the effect always starts on clip start and ends on clip end. With the
127 * "keyframe" type, the effect starts on the first keyframe and ends on the last keyframe
129 void drawKeyFrames(QPainter *painter, bool limitedKeyFrames);
130 int mouseOverKeyFrames(QPointF pos, double maxOffset);
131 virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);