1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
25 #include <QGraphicsRectItem>
26 #include <QDomElement>
27 #include <QGraphicsSceneMouseEvent>
31 #include "definitions.h"
33 #include "effectslist.h"
34 #include "abstractclipitem.h"
44 class ClipItem : public AbstractClipItem
49 ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, int frame_width, bool generateThumbs = true);
51 virtual void paint(QPainter *painter,
52 const QStyleOptionGraphicsItem *option,
54 virtual int type() const;
55 void resizeStart(int posx, bool size = true);
56 void resizeEnd(int posx);
57 OPERATIONTYPE operationMode(QPointF pos);
58 static int itemHeight();
59 const QString clipProducer() const;
61 DocClipBase *baseClip() const;
62 QString clipName() const;
63 void setClipName(const QString &name);
64 QDomElement xml() const;
65 QDomElement itemXml() const;
66 ClipItem *clone(ItemInfo info) const;
67 const EffectsList effectList() const;
68 void setFadeOut(int pos);
69 void setFadeIn(int pos);
70 void setFades(int in, int out);
72 /** @brief Gets the clip's effect names.
73 * @return The names of the effects in a string list */
74 QStringList effectNames();
76 /** @brief Adds an effect to the clip.
77 * @return The parameters that will be passed to Mlt */
78 EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
80 /** @brief Deletes the effect with id @param index. */
81 void deleteEffect(QString index);
83 /** @brief Gets the number of effects in this clip. */
86 /** @brief Gets a unique (?) effect id. */
89 /** @brief Gets a copy of the xml of an effect.
90 * @param ix The effect's index in effectlist
91 * @return A copy of the effect's xml */
92 QDomElement effectAt(int ix) const;
94 /** @brief Gets the xml of an effect.
95 * @param ix The effect's index in effectlist
96 * @return The effect's xml */
97 QDomElement getEffectAt(int ix) const;
99 /** @brief Replaces an effect.
100 * @param ix The effect's index in effectlist
101 * @param effect The new effect */
102 bool updateEffect(QDomElement effect);
103 bool moveEffect(QDomElement effect, int ix);
105 void addTransition(Transition*);
107 /** @brief Regenerates audio and video thumbnails.
108 * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
109 void resetThumbs(bool clearExistingThumbs);
111 /** @brief Updates clip properties from base clip.
112 * @param checkDuration whether or not to check for a valid duration.
113 * @param resetThumbs whether or not to recreate the image thumbnails. */
114 void refreshClip(bool checkDuration, bool resetThumbs);
116 /** @brief Gets clip's marker times.
117 * @return A list of the times. */
118 QList <GenTime> snapMarkers() const;
119 QList <CommentedTime> commentedSnapMarkers() const;
121 /** @brief Gets the position of the fade in effect. */
124 /** @brief Gets the position of the fade out effect. */
126 void setSelectedEffect(const int ix);
127 void updateKeyframeEffect();
128 QDomElement selectedEffect();
129 int selectedEffectIndex() const;
130 void initEffect(QDomElement effect, int diff = 0);
132 /** @brief Gets all keyframes.
133 * @param index Number of the effect
134 * @return a list of strings of keyframes (one string per param) */
135 QStringList keyframes(const int index);
137 /** @brief Sets params with keyframes and updates the visible keyframes.
138 * @param ix Number of the effect
139 * @param keyframes a list of strings of keyframes (one string per param), which should be used */
140 void setKeyframes(const int ix, const QStringList keyframes);
141 void setEffectList(const EffectsList effectList);
142 void setSpeed(const double speed, int strobe);
143 double speed() const;
145 GenTime maxDuration() const;
146 GenTime speedIndependantCropStart() const;
147 GenTime speedIndependantCropDuration() const;
148 const ItemInfo speedIndependantInfo() const;
149 int hasEffect(const QString &tag, const QString &id) const;
151 /** @brief Makes sure all keyframes are in the clip's cropped duration.
152 * @return Whether or not changes were made */
153 bool checkKeyFrames();
154 QPixmap startThumb() const;
155 QPixmap endThumb() const;
156 void setVideoOnly(bool force);
157 void setAudioOnly(bool force);
158 bool isVideoOnly() const;
159 bool isAudioOnly() const;
161 void insertKeyframe(QDomElement effect, int pos, int val);
162 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
163 void updateKeyframes(QDomElement effect);
164 void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo);
165 bool updateNormalKeyframes(QDomElement parameter);
167 /** @brief Adjusts effects after a clip duration change. */
168 QMap<int, QDomElement> adjustEffectsToDuration(int width, int height, ItemInfo oldInfo);
170 /** Returns the necessary (audio, video, general) producer.
171 * @param track Track of the requested producer
172 * @param trackSpecific (default = true) Whether to return general producer for a specific track.
173 * @return Fitting producer
174 * Which producer is returned depends on the type of this clip (audioonly, videoonly, normal) */
175 Mlt::Producer *getProducer(int track, bool trackSpecific = true);
176 void resetFrameWidth(int width);
177 /** @brief Clip is about to be deleted, block thumbs. */
181 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
182 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
183 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
184 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
185 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
186 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
187 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
191 ItemInfo m_speedIndependantInfo;
195 QString m_effectNames;
206 QTimer m_startThumbTimer;
207 QTimer m_endThumbTimer;
209 int m_selectedEffect;
210 QTimeLine *m_timeLine;
211 bool m_startThumbRequested;
212 bool m_endThumbRequested;
217 EffectsList m_effectList;
218 QList <Transition*> m_transitionsList;
219 QMap<int, QPixmap> m_audioThumbCachePic;
220 bool m_audioThumbReady;
221 double m_framePixelWidth;
225 /** @brief Keyframes type can be "keyframe" or "simplekeyframe" which have to be painted differently.
226 * True if keyframe type is "keyframe" */
227 bool m_limitedKeyFrames;
230 void slotGetStartThumb();
231 void slotGetEndThumb();
232 void slotGotAudioData();
233 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
234 void animate(qreal value);
235 void slotSetStartThumb(QImage img);
236 void slotSetEndThumb(QImage img);
237 void slotThumbReady(int frame, QImage img);
238 /** @brief The thumbnailer has finished to cache all required thumbs. */
239 void slotGotThumbsCache();
242 void slotFetchThumbs();
243 void slotSetStartThumb(const QPixmap pix);
244 void slotSetEndThumb(const QPixmap pix);
247 void getThumb(int, int);
248 void prepareAudioThumb(double, int, int, int);