]> git.sesse.net Git - kdenlive/blob - src/clipitem.h
- Properly handle pan and zoom effect during cut
[kdenlive] / src / clipitem.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef CLIPITEM_H
22 #define CLIPITEM_H
23
24 #include <QTimeLine>
25 #include <QGraphicsRectItem>
26 #include <QDomElement>
27 #include <QGraphicsSceneMouseEvent>
28 #include <QTimer>
29 #include <QFuture>
30
31 #include "definitions.h"
32 #include "gentime.h"
33 #include "effectslist.h"
34 #include "abstractclipitem.h"
35
36 class DocClipBase;
37 class Transition;
38
39
40 class ClipItem : public AbstractClipItem
41 {
42     Q_OBJECT
43
44 public:
45     ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs = true);
46     virtual ~ ClipItem();
47     virtual void paint(QPainter *painter,
48                        const QStyleOptionGraphicsItem *option,
49                        QWidget *);
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;
55     int clipType() 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
67     /** @brief Gets the clip's effect names.
68     * @return The names of the effects in a string list */
69     QStringList effectNames();
70
71     /** @brief Adds an effect to the clip.
72     * @return The parameters that will be passed to Mlt */
73     EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
74
75     /** @brief Deletes the effect with id @param index. */
76     void deleteEffect(QString index);
77
78     /** @brief Gets the number of effects in this clip. */
79     int effectsCount();
80
81     /** @brief Gets a unique (?) effect id. */
82     int effectsCounter();
83
84     /** @brief Gets a copy of the xml of an effect.
85     * @param ix The effect's index in effectlist
86     * @return A copy of the effect's xml */
87     QDomElement effectAt(int ix) const;
88
89     /** @brief Gets the xml of an effect.
90     * @param ix The effect's index in effectlist
91     * @return The effect's xml */
92     QDomElement getEffectAt(int ix) const;
93
94     /** @brief Replaces an effect.
95     * @param ix The effect's index in effectlist
96     * @param effect The new effect */
97     void setEffectAt(int ix, QDomElement effect);
98     void flashClip();
99     void addTransition(Transition*);
100
101     /** @brief Regenerates audio and video thumbnails.
102     * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
103     void resetThumbs(bool clearExistingThumbs);
104
105     /** @brief Updates clip properties from base clip.
106     * @param checkDuration whether or not to check for a valid duration. */
107     void refreshClip(bool checkDuration);
108
109     /** @brief Gets clip's marker times.
110     * @return A list of the times. */
111     QList <GenTime> snapMarkers() const;
112     QList <CommentedTime> commentedSnapMarkers() const;
113
114     /** @brief Gets the position of the fade in effect. */
115     int fadeIn() const;
116
117     /** @brief Gets the position of the fade out effect. */
118     int fadeOut() const;
119     void setSelectedEffect(const int ix);
120     void updateKeyframeEffect();
121     QDomElement selectedEffect();
122     int selectedEffectIndex() const;
123     void initEffect(QDomElement effect, int diff = 0);
124
125     /** @brief Gets all keyframes.
126     * @param index Number of the effect
127     * @return a list of strings of keyframes (one string per param) */
128     QStringList keyframes(const int index);
129
130     /** @brief Sets params with keyframes and updates the visible keyframes.
131     * @param ix Number of the effect
132     * @param keyframes a list of strings of keyframes (one string per param), which should be used */
133     void setKeyframes(const int ix, const QStringList keyframes);
134     void setEffectList(const EffectsList effectList);
135     void setSpeed(const double speed, int strobe);
136     double speed() const;
137     int strobe() const;
138     GenTime maxDuration() const;
139     GenTime speedIndependantCropStart() const;
140     GenTime speedIndependantCropDuration() const;
141     const ItemInfo speedIndependantInfo() const;
142     int hasEffect(const QString &tag, const QString &id) const;
143
144     /** @brief Makes sure all keyframes are in the clip's cropped duration.
145     * @return Whether or not changes were made */
146     bool checkKeyFrames();
147     QPixmap startThumb() const;
148     QPixmap endThumb() const;
149     void setVideoOnly(bool force);
150     void setAudioOnly(bool force);
151     bool isVideoOnly() const;
152     bool isAudioOnly() const;
153
154     /** @brief Adjusts the keyframe values to fit a clip resizement.
155     * @param previous Old crop value
156     * @param current New crop value
157     * @param fromStart true = crop from start, false = crop from end
158     * @return true if anything was modified */
159     bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
160     void insertKeyframe(QDomElement effect, int pos, int val);
161     void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
162     void updateKeyframes(QDomElement effect);
163     /** @brief Updates the keyframes in the pan and zoom effect to fit the clips cropDuration.
164      * @param width Render width
165      * @param height Render height
166      * @param cut (optional) if clip was cut, cut position relative to the original's clip position
167      * @return List of the pan and zoom effects indexes
168      * 
169      * Can be used for all effects using mlt_geometry with keyframes, but at the moment Pan & Zoom is the only one. */
170     QList <int> updatePanZoom(int width, int height, int cut = 0);
171
172 protected:
173     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
174     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
175     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
176     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
177     //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
178     //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
179     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
180
181 private:
182     DocClipBase *m_clip;
183     ItemInfo m_speedIndependantInfo;
184     QString m_producer;
185     CLIPTYPE m_clipType;
186     QString m_clipName;
187     QString m_effectNames;
188     int m_startFade;
189     int m_endFade;
190     bool m_audioOnly;
191     bool m_videoOnly;
192     QColor m_baseColor;
193
194     QPixmap m_startPix;
195     QPixmap m_endPix;
196
197     bool m_hasThumbs;
198     QTimer m_startThumbTimer;
199     QTimer m_endThumbTimer;
200
201     int m_selectedEffect;
202     QTimeLine *m_timeLine;
203     bool m_startThumbRequested;
204     bool m_endThumbRequested;
205     //bool m_hover;
206     double m_speed;
207     int m_strobe;
208
209     EffectsList m_effectList;
210     QList <Transition*> m_transitionsList;
211     QMap<int, QPixmap> m_audioThumbCachePic;
212     bool m_audioThumbReady;
213     double m_framePixelWidth;
214
215     QPixmap m_videoPix;
216     QPixmap m_audioPix;
217     void doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end);
218
219 private slots:
220     void slotGetStartThumb();
221     void slotGetEndThumb();
222     void slotGotAudioData();
223     void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
224     void animate(qreal value);
225     void slotSetStartThumb(QImage img);
226     void slotSetEndThumb(QImage img);
227     void slotThumbReady(int frame, QImage img);
228
229 public slots:
230     void slotFetchThumbs();
231     void slotSetStartThumb(const QPixmap pix);
232     void slotSetEndThumb(const QPixmap pix);
233
234 signals:
235     void getThumb(int, int);
236     void prepareAudioThumb(double, int, int, int);
237 };
238
239 #endif