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, const 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, bool emitChange = true);
56 void resizeEnd(int posx, bool emitChange = true);
57 OPERATIONTYPE operationMode(const 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(const 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(QDomElement effect, bool animate = true);
80 /** @brief Deletes the effect with id @param index. */
81 void deleteEffect(const 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 list index (starting from 0)
91 * @return A copy of the effect's xml */
92 QDomElement effect(int ix) const;
94 /** @brief Gets a copy of the xml of an effect.
95 * @param ix The effect's index in effectlist (starting from 1)
96 * @return A copy of the effect's xml */
97 QDomElement effectAtIndex(int ix) const;
99 /** @brief Gets the xml of an effect.
100 * @param ix The effect's index in effectlist (starting from 1)
101 * @return The effect's xml */
102 QDomElement getEffectAtIndex(int ix) const;
104 /** @brief Replaces an effect.
105 * @param ix The effect's index in effectlist
106 * @param effect The new effect */
107 void updateEffect(QDomElement effect);
108 /** @brief Enable / disable a list of effect from their indexes. */
109 void enableEffects(QList <int> indexes, bool disable);
110 bool moveEffect(QDomElement effect, int ix);
112 void addTransition(Transition*);
114 /** @brief Regenerates audio and video thumbnails.
115 * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
116 void resetThumbs(bool clearExistingThumbs);
118 /** @brief Updates clip properties from base clip.
119 * @param checkDuration whether or not to check for a valid duration.
120 * @param resetThumbs whether or not to recreate the image thumbnails. */
121 void refreshClip(bool checkDuration, bool resetThumbs);
123 /** @brief Gets clip's marker times.
124 * @return A list of the times. */
125 QList <GenTime> snapMarkers() const;
126 QList <CommentedTime> commentedSnapMarkers() const;
128 /** @brief Gets the position of the fade in effect. */
131 /** @brief Gets the position of the fade out effect. */
133 void setSelectedEffect(const int ix);
134 void updateKeyframeEffect();
135 QDomElement selectedEffect();
136 int selectedEffectIndex() const;
138 void initEffect(QDomElement effect, int diff = 0, int offset = 0);
140 /** @brief Gets all keyframes.
141 * @param index Index of the effect
142 * @return a list of strings of keyframes (one string per param) */
143 QStringList keyframes(const int index);
145 /** @brief Adjust all geometry keyframes.
146 * @param index Index of the effect */
147 void resizeGeometries(const int index, int width, int height, int previousDuration, int start, int duration);
149 /** @brief Sets params with keyframes and updates the visible keyframes.
150 * @param ix Number of the effect
151 * @param keyframes a list of strings of keyframes (one string per param), which should be used */
152 void setKeyframes(const int ix, const QStringList &keyframes);
153 void setEffectList(const EffectsList &effectList);
154 void setSpeed(const double speed, int strobe);
155 double speed() const;
157 GenTime maxDuration() const;
158 GenTime speedIndependantCropStart() const;
159 GenTime speedIndependantCropDuration() const;
160 const ItemInfo speedIndependantInfo() const;
161 int hasEffect(const QString &tag, const QString &id) const;
163 /** @brief Adjust keyframes to the new clip. */
164 const QString adjustKeyframes(const QString &keyframes, int offset);
165 /** @brief Makes sure all keyframes are in the clip's cropped duration.
166 * @param cutPos the frame number where the new clip starts
167 * @return Whether or not changes were made */
168 bool checkKeyFrames(int width, int height, int previousDuration, int cutPos = -1);
169 QPixmap startThumb() const;
170 QPixmap endThumb() const;
171 void setVideoOnly(bool force);
172 void setAudioOnly(bool force);
173 bool isVideoOnly() const;
174 bool isAudioOnly() const;
176 void insertKeyframe(QDomElement effect, int pos, int val);
177 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
178 void updateKeyframes(QDomElement effect);
179 void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo);
180 bool updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo);
182 /** @brief Adjusts effects after a clip duration change. */
183 QMap<int, QDomElement> adjustEffectsToDuration(int width, int height, const ItemInfo &oldInfo);
185 /** Returns the necessary (audio, video, general) producer.
186 * @param track Track of the requested producer
187 * @param trackSpecific (default = true) Whether to return general producer for a specific track.
188 * @return Fitting producer
189 * Which producer is returned depends on the type of this clip (audioonly, videoonly, normal) */
190 Mlt::Producer *getProducer(int track, bool trackSpecific = true);
191 void resetFrameWidth(int width);
192 /** @brief Clip is about to be deleted, block thumbs. */
195 /** @brief Get a free index value for effect group. */
196 int nextFreeEffectGroupIndex() const;
199 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
200 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
201 void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
202 void dropEvent(QGraphicsSceneDragDropEvent *event);
203 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
204 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
205 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
209 ItemInfo m_speedIndependantInfo;
213 QString m_effectNames;
225 QTimer m_startThumbTimer;
226 QTimer m_endThumbTimer;
228 int m_selectedEffect;
229 QTimeLine *m_timeLine;
230 bool m_startThumbRequested;
231 bool m_endThumbRequested;
236 EffectsList m_effectList;
237 QList <Transition*> m_transitionsList;
238 QMap<int, QPixmap> m_audioThumbCachePic;
239 bool m_audioThumbReady;
240 double m_framePixelWidth;
244 /** @brief Keyframes type can be "keyframe" or "simplekeyframe" which have to be painted differently.
245 * True if keyframe type is "keyframe" */
246 bool m_limitedKeyFrames;
249 void slotGetStartThumb();
250 void slotGetEndThumb();
251 void slotGotAudioData();
252 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels, int pixelHeight);
253 void animate(qreal value);
254 void slotSetStartThumb(const QImage &img);
255 void slotSetEndThumb(const QImage &img);
256 void slotThumbReady(int frame, const QImage &img);
257 /** @brief The thumbnailer has finished to cache all required thumbs. */
258 void slotGotThumbsCache();
261 void slotFetchThumbs();
262 void slotSetStartThumb(const QPixmap &pix);
263 void slotSetEndThumb(const QPixmap &pix);
264 void slotUpdateRange();
267 void prepareAudioThumb(double, int, int, int, int);