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, bool generateThumbs = true);
45 virtual void paint(QPainter *painter,
46 const QStyleOptionGraphicsItem *option,
48 virtual int type() const;
49 void resizeStart(int posx);
50 void resizeEnd(int posx);
51 OPERATIONTYPE operationMode(QPointF pos);
52 const QString &clipProducer() const;
54 DocClipBase *baseClip() const;
55 QString clipName() const;
56 QDomElement xml() const;
57 ClipItem *clone(ItemInfo info) const;
58 const EffectsList effectList();
59 void setFadeOut(int pos);
60 void setFadeIn(int pos);
61 /** Give a string list of the clip's effect names */
62 QStringList effectNames();
63 /** Add an effect to the clip and return the parameters that will be passed to Mlt */
64 QHash <QString, QString> addEffect(QDomElement effect, bool animate = true);
65 /** Get the effect parameters that will be passed to Mlt */
66 QHash <QString, QString> getEffectArgs(QDomElement effect);
67 /** Delete effect with id index */
68 void deleteEffect(QString index);
69 /** return the number of effects in that clip */
71 /** return a unique effect id */
73 /** return the xml of effect at index ix in stack */
74 QDomElement effectAt(int ix);
75 /** Replace effect at pos ix with given value */
76 void setEffectAt(int ix, QDomElement effect);
78 void addTransition(Transition*);
79 /** regenerate audio and video thumbnails */
81 /** update clip properties from base clip */
83 /** Returns a list of times for this clip's markers */
84 QList <GenTime> snapMarkers() const;
85 QList <CommentedTime> commentedSnapMarkers() const;
88 void setSelectedEffect(const int ix);
89 void updateKeyframeEffect();
90 QDomElement selectedEffect();
91 int selectedEffectIndex() const;
92 void initEffect(QDomElement effect);
93 QString keyframes(const int index);
94 void setKeyframes(const int ix, const QString keyframes);
95 void setEffectList(const EffectsList effectList);
96 void setSpeed(const double speed);
98 GenTime maxDuration() const;
99 int hasEffect(const QString &tag, const QString &id) const;
102 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
103 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
104 virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
105 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
106 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
107 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
108 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
109 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
110 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
114 OPERATIONTYPE m_resizeMode;
119 QString m_effectNames;
127 QTimer *startThumbTimer;
128 QTimer *endThumbTimer;
130 /** counter used to provide a unique id to each effect */
131 int m_effectsCounter;
132 int m_selectedEffect;
134 QTimeLine *m_timeLine;
135 bool m_startThumbRequested;
136 bool m_endThumbRequested;
140 EffectsList m_effectList;
141 QList <Transition*> m_transitionsList;
142 QMap<int, QPixmap> audioThumbCachePic;
143 bool audioThumbWasDrawn, audioThumbReady;
144 double framePixelWidth;
145 QMap<int, QPainterPath > channelPaths;
146 /** Called when clip start is resized, adjust keyframes values */
147 void checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
150 void slotFetchThumbs();
151 void slotGetStartThumb();
152 void slotGetEndThumb();
153 void slotGotAudioData();
154 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
155 void animate(qreal value);
156 void slotSetStartThumb(QImage img);
157 void slotSetEndThumb(QImage img);
158 void slotSetStartThumb(QPixmap pix);
159 void slotSetEndThumb(QPixmap pix);
160 void slotThumbReady(int frame, QPixmap pix);
163 void getThumb(int, int);
164 void prepareAudioThumb(double, int, int, int);