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>
30 #include "definitions.h"
32 #include "effectslist.h"
33 #include "abstractclipitem.h"
39 class ClipItem : public AbstractClipItem
44 ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs = true);
46 virtual void paint(QPainter *painter,
47 const QStyleOptionGraphicsItem *option,
49 virtual int type() const;
50 void resizeStart(int posx);
51 void resizeEnd(int posx);
52 OPERATIONTYPE operationMode(QPointF pos);
53 const QString clipProducer() const;
55 DocClipBase *baseClip() const;
56 QString clipName() const;
57 void setClipName(const QString &name);
58 QDomElement xml() const;
59 ClipItem *clone(ItemInfo info) const;
60 const EffectsList effectList() const;
61 void setFadeOut(int pos);
62 void setFadeIn(int pos);
63 void setFades(int in, int out);
64 /** Give a string list of the clip's effect names */
65 QStringList effectNames();
66 /** Add an effect to the clip and return the parameters that will be passed to Mlt */
67 EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
68 /** Get the effect parameters that will be passed to Mlt */
69 EffectsParameterList getEffectArgs(QDomElement effect);
70 /** Delete effect with id index */
71 void deleteEffect(QString index);
72 /** return the number of effects in that clip */
74 /** return a unique effect id */
76 /** return a copy of the xml of effect at index ix in stack */
77 QDomElement effectAt(int ix) const;
78 /** return the xml of effect at index ix in stack */
79 QDomElement getEffectAt(int ix) const;
80 /** Replace effect at pos ix with given value */
81 void setEffectAt(int ix, QDomElement effect);
83 void addTransition(Transition*);
84 /** regenerate audio and video thumbnails */
85 void resetThumbs(bool clearExistingThumbs);
86 /** update clip properties from base clip */
87 void refreshClip(bool checkDuration);
88 /** Returns a list of times for this clip's markers */
89 QList <GenTime> snapMarkers() const;
90 QList <CommentedTime> commentedSnapMarkers() const;
91 /** Get the position of the fade in effect */
93 /** Get the position of the fade out effect */
95 void setSelectedEffect(const int ix);
96 void updateKeyframeEffect();
97 QDomElement selectedEffect();
98 int selectedEffectIndex() const;
99 void initEffect(QDomElement effect, int diff = 0);
100 QString keyframes(const int index);
101 void setKeyframes(const int ix, const QString keyframes);
102 void setEffectList(const EffectsList effectList);
103 void setSpeed(const double speed, int strobe);
104 double speed() const;
106 GenTime maxDuration() const;
107 GenTime speedIndependantCropStart() const;
108 GenTime speedIndependantCropDuration() const;
109 const ItemInfo speedIndependantInfo() const;
110 int hasEffect(const QString &tag, const QString &id) const;
111 bool checkKeyFrames();
112 QPixmap startThumb() const;
113 QPixmap endThumb() const;
114 void setVideoOnly(bool force);
115 void setAudioOnly(bool force);
116 bool isVideoOnly() const;
117 bool isAudioOnly() const;
118 /** Called when clip start is resized, adjust keyframes values */
119 bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
120 void insertKeyframe(QDomElement effect, int pos, int val);
121 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
122 void updateKeyframes(QDomElement effect);
125 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
126 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
127 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
128 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
129 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
130 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
131 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
135 ItemInfo m_speedIndependantInfo;
139 QString m_effectNames;
149 QTimer m_startThumbTimer;
150 QTimer m_endThumbTimer;
152 int m_selectedEffect;
153 QTimeLine *m_timeLine;
154 bool m_startThumbRequested;
155 bool m_endThumbRequested;
160 EffectsList m_effectList;
161 QList <Transition*> m_transitionsList;
162 QMap<int, QPixmap> m_audioThumbCachePic;
163 bool m_audioThumbReady;
164 double m_framePixelWidth;
170 void slotGetStartThumb();
171 void slotGetEndThumb();
172 void slotGotAudioData();
173 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
174 void animate(qreal value);
175 void slotSetStartThumb(QImage img);
176 void slotSetEndThumb(QImage img);
177 void slotThumbReady(int frame, QImage img);
180 void slotFetchThumbs();
181 void slotSetStartThumb(const QPixmap pix);
182 void slotSetEndThumb(const QPixmap pix);
185 void getThumb(int, int);
186 void prepareAudioThumb(double, int, int, int);