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 {
43 ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs = true);
45 virtual void paint(QPainter *painter,
46 const QStyleOptionGraphicsItem *option,
48 virtual int type() const;
49 void resizeStart(int posx, double speed = 1.0);
50 void resizeEnd(int posx, double speed = 1.0, bool updateKeyFrames = true);
51 OPERATIONTYPE operationMode(QPointF pos);
52 const QString &clipProducer() const;
54 DocClipBase *baseClip() const;
55 QString clipName() const;
56 void setClipName(const QString &name);
57 QDomElement xml() const;
58 ClipItem *clone(ItemInfo info) const;
59 const EffectsList effectList();
60 void setFadeOut(int pos);
61 void setFadeIn(int pos);
62 /** Give a string list of the clip's effect names */
63 QStringList effectNames();
64 /** Add an effect to the clip and return the parameters that will be passed to Mlt */
65 EffectsParameterList addEffect(QDomElement effect, bool animate = true);
66 /** Get the effect parameters that will be passed to Mlt */
67 EffectsParameterList getEffectArgs(QDomElement effect);
68 /** Delete effect with id index */
69 void deleteEffect(QString index);
70 /** return the number of effects in that clip */
72 /** return a unique effect id */
74 /** return the xml of effect at index ix in stack */
75 QDomElement effectAt(int ix);
76 /** Replace effect at pos ix with given value */
77 void setEffectAt(int ix, QDomElement effect);
79 void addTransition(Transition*);
80 /** regenerate audio and video thumbnails */
82 /** update clip properties from base clip */
84 /** Returns a list of times for this clip's markers */
85 QList <GenTime> snapMarkers() const;
86 QList <CommentedTime> commentedSnapMarkers() const;
89 void setSelectedEffect(const int ix);
90 void updateKeyframeEffect();
91 QDomElement selectedEffect();
92 int selectedEffectIndex() const;
93 void initEffect(QDomElement effect);
94 QString keyframes(const int index);
95 void setKeyframes(const int ix, const QString keyframes);
96 void setEffectList(const EffectsList effectList);
97 void setSpeed(const double speed);
99 GenTime maxDuration() const;
100 GenTime cropStart() const;
101 GenTime endPos() const;
102 GenTime cropDuration() const;
103 int hasEffect(const QString &tag, const QString &id) const;
104 bool checkKeyFrames();
105 QPixmap startThumb() const;
106 QPixmap endThumb() const;
109 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
110 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
111 virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
112 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
113 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
114 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
115 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
116 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
117 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
121 OPERATIONTYPE m_resizeMode;
126 QString m_effectNames;
134 QTimer *startThumbTimer;
135 QTimer *endThumbTimer;
137 int m_selectedEffect;
139 QTimeLine *m_timeLine;
140 bool m_startThumbRequested;
141 bool m_endThumbRequested;
145 EffectsList m_effectList;
146 QList <Transition*> m_transitionsList;
147 QMap<int, QPixmap> audioThumbCachePic;
148 bool audioThumbWasDrawn, audioThumbReady;
149 double framePixelWidth;
150 QMap<int, QPainterPath > channelPaths;
151 /** Called when clip start is resized, adjust keyframes values */
152 void checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
155 void slotFetchThumbs();
156 void slotGetStartThumb();
157 void slotGetEndThumb();
158 void slotGotAudioData();
159 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
160 void animate(qreal value);
161 void slotSetStartThumb(QImage img);
162 void slotSetEndThumb(QImage img);
163 void slotThumbReady(int frame, QPixmap pix);
166 void slotSetStartThumb(const QPixmap pix);
167 void slotSetEndThumb(const QPixmap pix);
170 void getThumb(int, int);
171 void prepareAudioThumb(double, int, int, int);