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"
40 class ClipItem : public AbstractClipItem
45 ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs = true);
47 virtual void paint(QPainter *painter,
48 const QStyleOptionGraphicsItem *option,
50 virtual int type() const;
51 void resizeStart(int posx, bool size = true);
52 void resizeEnd(int posx);
53 OPERATIONTYPE operationMode(QPointF pos);
54 const QString clipProducer() const;
56 DocClipBase *baseClip() const;
57 QString clipName() const;
58 void setClipName(const QString &name);
59 QDomElement xml() const;
60 QDomElement itemXml() const;
61 ClipItem *clone(ItemInfo info) const;
62 const EffectsList effectList() const;
63 void setFadeOut(int pos);
64 void setFadeIn(int pos);
65 void setFades(int in, int out);
67 /** @brief Gets the clip's effect names.
68 * @return The names of the effects in a string list */
69 QStringList effectNames();
71 /** @brief Adds an effect to the clip.
72 * @return The parameters that will be passed to Mlt */
73 EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
75 /** @brief Gets the effect parameters that will be passed to Mlt. */
76 EffectsParameterList getEffectArgs(QDomElement effect);
78 /** @brief Deletes the effect with id @param index. */
79 void deleteEffect(QString index);
81 /** @brief Gets the number of effects in this clip. */
84 /** @brief Gets a unique (?) effect id. */
87 /** @brief Gets a copy of the xml of an effect.
88 * @param ix The effect's index in effectlist
89 * @return A copy of the effect's xml */
90 QDomElement effectAt(int ix) const;
92 /** @brief Gets the xml of an effect.
93 * @param ix The effect's index in effectlist
94 * @return The effect's xml */
95 QDomElement getEffectAt(int ix) const;
97 /** @brief Replaces an effect.
98 * @param ix The effect's index in effectlist
99 * @param effect The new effect */
100 void setEffectAt(int ix, QDomElement effect);
102 void addTransition(Transition*);
104 /** @brief Regenerates audio and video thumbnails.
105 * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
106 void resetThumbs(bool clearExistingThumbs);
108 /** @brief Updates clip properties from base clip.
109 * @param checkDuration whether or not to check for a valid duration. */
110 void refreshClip(bool checkDuration);
112 /** @brief Gets clip's marker times.
113 * @return A list of the times. */
114 QList <GenTime> snapMarkers() const;
115 QList <CommentedTime> commentedSnapMarkers() const;
117 /** @brief Gets the position of the fade in effect. */
120 /** @brief Gets the position of the fade out effect. */
122 void setSelectedEffect(const int ix);
123 void updateKeyframeEffect();
124 QDomElement selectedEffect();
125 int selectedEffectIndex() const;
126 void initEffect(QDomElement effect, int diff = 0);
128 /** @brief Gets all keyframes.
129 * @param index Number of the effect
130 * @return a list of strings of keyframes (one string per param) */
131 QStringList keyframes(const int index);
133 /** @brief Sets params with keyframes and updates the visible keyframes.
134 * @param ix Number of the effect
135 * @param keyframes a list of strings of keyframes (one string per param), which should be used */
136 void setKeyframes(const int ix, const QStringList keyframes);
137 void setEffectList(const EffectsList effectList);
138 void setSpeed(const double speed, int strobe);
139 double speed() const;
141 GenTime maxDuration() const;
142 GenTime speedIndependantCropStart() const;
143 GenTime speedIndependantCropDuration() const;
144 const ItemInfo speedIndependantInfo() const;
145 int hasEffect(const QString &tag, const QString &id) const;
147 /** @brief Makes sure all keyframes are in the clip's cropped duration.
148 * @return Whether or not changes were made */
149 bool checkKeyFrames();
150 QPixmap startThumb() const;
151 QPixmap endThumb() const;
152 void setVideoOnly(bool force);
153 void setAudioOnly(bool force);
154 bool isVideoOnly() const;
155 bool isAudioOnly() const;
157 /** @brief Adjusts the keyframe values to fit a clip resizement.
158 * @param previous Old crop value
159 * @param current New crop value
160 * @param fromStart true = crop from start, false = crop from end
161 * @return true if anything was modified */
162 bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
163 void insertKeyframe(QDomElement effect, int pos, int val);
164 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
165 void updateKeyframes(QDomElement effect);
168 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
169 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
170 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
171 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
172 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
173 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
174 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
178 ItemInfo m_speedIndependantInfo;
182 QString m_effectNames;
193 QTimer m_startThumbTimer;
194 QTimer m_endThumbTimer;
196 int m_selectedEffect;
197 QTimeLine *m_timeLine;
198 bool m_startThumbRequested;
199 bool m_endThumbRequested;
204 EffectsList m_effectList;
205 QList <Transition*> m_transitionsList;
206 QMap<int, QPixmap> m_audioThumbCachePic;
207 bool m_audioThumbReady;
208 double m_framePixelWidth;
212 void doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end);
215 void slotGetStartThumb();
216 void slotGetEndThumb();
217 void slotGotAudioData();
218 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
219 void animate(qreal value);
220 void slotSetStartThumb(QImage img);
221 void slotSetEndThumb(QImage img);
222 void slotThumbReady(int frame, QImage img);
225 void slotFetchThumbs();
226 void slotSetStartThumb(const QPixmap pix);
227 void slotSetEndThumb(const QPixmap pix);
230 void getThumb(int, int);
231 void prepareAudioThumb(double, int, int, int);