]> git.sesse.net Git - kdenlive/blob - src/clipitem.h
cleanup
[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 Gets the effect parameters that will be passed to Mlt. */
76     EffectsParameterList getEffectArgs(QDomElement effect);
77
78     /** @brief Deletes the effect with id @param index. */
79     void deleteEffect(QString index);
80
81     /** @brief Gets the number of effects in this clip. */
82     int effectsCount();
83
84     /** @brief Gets a unique (?) effect id. */
85     int effectsCounter();
86
87     /** @brief Gets a copy of the xml of an effect.
88     * @param ix The effect's index in effectlist
89     * @return A copy of the effect's xml */
90     QDomElement effectAt(int ix) const;
91
92     /** @brief Gets the xml of an effect.
93     * @param ix The effect's index in effectlist
94     * @return The effect's xml */
95     QDomElement getEffectAt(int ix) const;
96
97     /** @brief Replaces an effect.
98     * @param ix The effect's index in effectlist
99     * @param effect The new effect */
100     void setEffectAt(int ix, QDomElement effect);
101     void flashClip();
102     void addTransition(Transition*);
103
104     /** @brief Regenerates audio and video thumbnails.
105     * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
106     void resetThumbs(bool clearExistingThumbs);
107
108     /** @brief Updates clip properties from base clip.
109     * @param checkDuration whether or not to check for a valid duration. */
110     void refreshClip(bool checkDuration);
111
112     /** @brief Gets clip's marker times.
113     * @return A list of the times. */
114     QList <GenTime> snapMarkers() const;
115     QList <CommentedTime> commentedSnapMarkers() const;
116
117     /** @brief Gets the position of the fade in effect. */
118     int fadeIn() const;
119
120     /** @brief Gets the position of the fade out effect. */
121     int fadeOut() const;
122     void setSelectedEffect(const int ix);
123     void updateKeyframeEffect();
124     QDomElement selectedEffect();
125     int selectedEffectIndex() const;
126     void initEffect(QDomElement effect, int diff = 0);
127     QString keyframes(const int index);
128     void setKeyframes(const int ix, const QString keyframes);
129     void setEffectList(const EffectsList effectList);
130     void setSpeed(const double speed, int strobe);
131     double speed() const;
132     int strobe() const;
133     GenTime maxDuration() const;
134     GenTime speedIndependantCropStart() const;
135     GenTime speedIndependantCropDuration() const;
136     const ItemInfo speedIndependantInfo() const;
137     int hasEffect(const QString &tag, const QString &id) const;
138     bool checkKeyFrames();
139     QPixmap startThumb() const;
140     QPixmap endThumb() const;
141     void setVideoOnly(bool force);
142     void setAudioOnly(bool force);
143     bool isVideoOnly() const;
144     bool isAudioOnly() const;
145
146     /** @brief Adjusts the keyframe values to fit a clip resizement.
147     * @param previous Old crop value
148     * @param current New crop value
149     * @param fromStart true = crop from start, false = crop from end
150     * @return true if anything was modified */
151     bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
152     void insertKeyframe(QDomElement effect, int pos, int val);
153     void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
154     void updateKeyframes(QDomElement effect);
155
156 protected:
157     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
158     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
159     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
160     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
161     //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
162     //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
163     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
164
165 private:
166     DocClipBase *m_clip;
167     ItemInfo m_speedIndependantInfo;
168     QString m_producer;
169     CLIPTYPE m_clipType;
170     QString m_clipName;
171     QString m_effectNames;
172     int m_startFade;
173     int m_endFade;
174     bool m_audioOnly;
175     bool m_videoOnly;
176     QColor m_baseColor;
177
178     QPixmap m_startPix;
179     QPixmap m_endPix;
180
181     bool m_hasThumbs;
182     QTimer m_startThumbTimer;
183     QTimer m_endThumbTimer;
184
185     int m_selectedEffect;
186     QTimeLine *m_timeLine;
187     bool m_startThumbRequested;
188     bool m_endThumbRequested;
189     //bool m_hover;
190     double m_speed;
191     int m_strobe;
192
193     EffectsList m_effectList;
194     QList <Transition*> m_transitionsList;
195     QMap<int, QPixmap> m_audioThumbCachePic;
196     bool m_audioThumbReady;
197     double m_framePixelWidth;
198
199     QPixmap m_videoPix;
200     QPixmap m_audioPix;
201     void doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end);
202
203 private slots:
204     void slotGetStartThumb();
205     void slotGetEndThumb();
206     void slotGotAudioData();
207     void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
208     void animate(qreal value);
209     void slotSetStartThumb(QImage img);
210     void slotSetEndThumb(QImage img);
211     void slotThumbReady(int frame, QImage img);
212
213 public slots:
214     void slotFetchThumbs();
215     void slotSetStartThumb(const QPixmap pix);
216     void slotSetEndThumb(const QPixmap pix);
217
218 signals:
219     void getThumb(int, int);
220     void prepareAudioThumb(double, int, int, int);
221 };
222
223 #endif