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);
66 /** Give a string list of the clip's effect names */
67 QStringList effectNames();
68 /** Add an effect to the clip and return the parameters that will be passed to Mlt */
69 EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
70 /** Get the effect parameters that will be passed to Mlt */
71 EffectsParameterList getEffectArgs(QDomElement effect);
72 /** Delete effect with id index */
73 void deleteEffect(QString index);
74 /** return the number of effects in that clip */
76 /** return a unique effect id */
78 /** return a copy of the xml of effect at index ix in stack */
79 QDomElement effectAt(int ix) const;
80 /** return the xml of effect at index ix in stack */
81 QDomElement getEffectAt(int ix) const;
82 /** Replace effect at pos ix with given value */
83 void setEffectAt(int ix, QDomElement effect);
85 void addTransition(Transition*);
86 /** regenerate audio and video thumbnails */
87 void resetThumbs(bool clearExistingThumbs);
88 /** update clip properties from base clip */
89 void refreshClip(bool checkDuration);
90 /** Returns a list of times for this clip's markers */
91 QList <GenTime> snapMarkers() const;
92 QList <CommentedTime> commentedSnapMarkers() const;
93 /** Get the position of the fade in effect */
95 /** Get the position of the fade out effect */
97 void setSelectedEffect(const int ix);
98 void updateKeyframeEffect();
99 QDomElement selectedEffect();
100 int selectedEffectIndex() const;
101 void initEffect(QDomElement effect, int diff = 0);
102 QString keyframes(const int index);
103 void setKeyframes(const int ix, const QString keyframes);
104 void setEffectList(const EffectsList effectList);
105 void setSpeed(const double speed, int strobe);
106 double speed() const;
108 GenTime maxDuration() const;
109 GenTime speedIndependantCropStart() const;
110 GenTime speedIndependantCropDuration() const;
111 const ItemInfo speedIndependantInfo() const;
112 int hasEffect(const QString &tag, const QString &id) const;
113 bool checkKeyFrames();
114 QPixmap startThumb() const;
115 QPixmap endThumb() const;
116 void setVideoOnly(bool force);
117 void setAudioOnly(bool force);
118 bool isVideoOnly() const;
119 bool isAudioOnly() const;
120 /** Called when clip start is resized, adjust keyframes values */
121 bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
122 void insertKeyframe(QDomElement effect, int pos, int val);
123 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
124 void updateKeyframes(QDomElement effect);
127 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
128 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
129 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
130 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
131 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
132 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
133 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
137 ItemInfo m_speedIndependantInfo;
141 QString m_effectNames;
152 QTimer m_startThumbTimer;
153 QTimer m_endThumbTimer;
155 int m_selectedEffect;
156 QTimeLine *m_timeLine;
157 bool m_startThumbRequested;
158 bool m_endThumbRequested;
163 EffectsList m_effectList;
164 QList <Transition*> m_transitionsList;
165 QMap<int, QPixmap> m_audioThumbCachePic;
166 bool m_audioThumbReady;
167 double m_framePixelWidth;
171 void doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end);
174 void slotGetStartThumb();
175 void slotGetEndThumb();
176 void slotGotAudioData();
177 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
178 void animate(qreal value);
179 void slotSetStartThumb(QImage img);
180 void slotSetEndThumb(QImage img);
181 void slotThumbReady(int frame, QImage img);
184 void slotFetchThumbs();
185 void slotSetStartThumb(const QPixmap pix);
186 void slotSetEndThumb(const QPixmap pix);
189 void getThumb(int, int);
190 void prepareAudioThumb(double, int, int, int);