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, double speed = 1.0);
51 void resizeEnd(int posx, double speed = 1.0, bool updateKeyFrames = true);
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 /** Give a string list of the clip's effect names */
64 QStringList effectNames();
65 /** Add an effect to the clip and return the parameters that will be passed to Mlt */
66 EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
67 /** Get the effect parameters that will be passed to Mlt */
68 EffectsParameterList getEffectArgs(QDomElement effect);
69 /** Delete effect with id index */
70 void deleteEffect(QString index);
71 /** return the number of effects in that clip */
73 /** return a unique effect id */
75 /** return a copy of the xml of effect at index ix in stack */
76 QDomElement effectAt(int ix) const;
77 /** return the xml of effect at index ix in stack */
78 QDomElement getEffectAt(int ix) const;
79 /** Replace effect at pos ix with given value */
80 void setEffectAt(int ix, QDomElement effect);
82 void addTransition(Transition*);
83 /** regenerate audio and video thumbnails */
84 void resetThumbs(bool clearExistingThumbs);
85 /** update clip properties from base clip */
86 void refreshClip(bool checkDuration);
87 /** Returns a list of times for this clip's markers */
88 QList <GenTime> snapMarkers() const;
89 QList <CommentedTime> commentedSnapMarkers() const;
92 void setSelectedEffect(const int ix);
93 void updateKeyframeEffect();
94 QDomElement selectedEffect();
95 int selectedEffectIndex() const;
96 void initEffect(QDomElement effect);
97 QString keyframes(const int index);
98 void setKeyframes(const int ix, const QString keyframes);
99 void setEffectList(const EffectsList effectList);
100 void setSpeed(const double speed, int strobe);
101 double speed() const;
103 GenTime maxDuration() const;
104 GenTime cropStart() const;
105 GenTime endPos() const;
106 GenTime cropDuration() const;
107 int hasEffect(const QString &tag, const QString &id) const;
108 bool checkKeyFrames();
109 QPixmap startThumb() const;
110 QPixmap endThumb() const;
111 void setVideoOnly(bool force);
112 void setAudioOnly(bool force);
113 bool isVideoOnly() const;
114 bool isAudioOnly() const;
117 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
118 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
119 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
120 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
121 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
122 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
123 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
130 QString m_effectNames;
140 QTimer m_startThumbTimer;
141 QTimer m_endThumbTimer;
143 int m_selectedEffect;
144 QTimeLine *m_timeLine;
145 bool m_startThumbRequested;
146 bool m_endThumbRequested;
151 EffectsList m_effectList;
152 QList <Transition*> m_transitionsList;
153 QMap<int, QPixmap> m_audioThumbCachePic;
154 bool m_audioThumbReady;
155 double m_framePixelWidth;
156 /** Called when clip start is resized, adjust keyframes values */
157 void checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
162 void slotGetStartThumb();
163 void slotGetEndThumb();
164 void slotGotAudioData();
165 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
166 void animate(qreal value);
167 void slotSetStartThumb(QImage img);
168 void slotSetEndThumb(QImage img);
169 void slotThumbReady(int frame, QPixmap pix);
172 void slotFetchThumbs();
173 void slotSetStartThumb(const QPixmap pix);
174 void slotSetEndThumb(const QPixmap pix);
177 void getThumb(int, int);
178 void prepareAudioThumb(double, int, int, int);