]> git.sesse.net Git - kdenlive/blob - src/clipitem.h
067ea231b55ce75703fb9ae87c3a4d80015efab9
[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
30 #include "definitions.h"
31 #include "gentime.h"
32 #include "effectslist.h"
33 #include "abstractclipitem.h"
34
35 class DocClipBase;
36 class Transition;
37
38
39 class ClipItem : public AbstractClipItem
40 {
41     Q_OBJECT
42
43 public:
44     ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs = true);
45     virtual ~ ClipItem();
46     virtual void paint(QPainter *painter,
47                        const QStyleOptionGraphicsItem *option,
48                        QWidget *);
49     virtual int type() const;
50     void resizeStart(int posx, bool size = true);
51     void resizeEnd(int posx);
52     OPERATIONTYPE operationMode(QPointF pos);
53     const QString clipProducer() const;
54     int clipType() const;
55     DocClipBase *baseClip() const;
56     QString clipName() const;
57     void setClipName(const QString &name);
58     QDomElement xml() const;
59     QDomElement itemXml() const;
60     ClipItem *clone(ItemInfo info) const;
61     const EffectsList effectList() const;
62     void setFadeOut(int pos);
63     void setFadeIn(int pos);
64     void setFades(int in, int out);
65     /** Give a string list of the clip's effect names */
66     QStringList effectNames();
67     /** Add an effect to the clip and return the parameters that will be passed to Mlt */
68     EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
69     /** Get the effect parameters that will be passed to Mlt */
70     EffectsParameterList getEffectArgs(QDomElement effect);
71     /** Delete effect with id index */
72     void deleteEffect(QString index);
73     /** return the number of effects in that clip */
74     int effectsCount();
75     /** return a unique effect id */
76     int effectsCounter();
77     /** return a copy of the xml of effect at index ix in stack */
78     QDomElement effectAt(int ix) const;
79     /** return the xml of effect at index ix in stack */
80     QDomElement getEffectAt(int ix) const;
81     /** Replace effect at pos ix with given value */
82     void setEffectAt(int ix, QDomElement effect);
83     void flashClip();
84     void addTransition(Transition*);
85     /** regenerate audio and video thumbnails */
86     void resetThumbs(bool clearExistingThumbs);
87     /** update clip properties from base clip */
88     void refreshClip(bool checkDuration);
89     /** Returns a list of times for this clip's markers */
90     QList <GenTime> snapMarkers() const;
91     QList <CommentedTime> commentedSnapMarkers() const;
92     /** Get the position of the fade in effect */
93     int fadeIn() const;
94     /** Get the position of the fade out effect */
95     int fadeOut() const;
96     void setSelectedEffect(const int ix);
97     void updateKeyframeEffect();
98     QDomElement selectedEffect();
99     int selectedEffectIndex() const;
100     void initEffect(QDomElement effect, int diff = 0);
101     QString keyframes(const int index);
102     void setKeyframes(const int ix, const QString keyframes);
103     void setEffectList(const EffectsList effectList);
104     void setSpeed(const double speed, int strobe);
105     double speed() const;
106     int strobe() const;
107     GenTime maxDuration() const;
108     GenTime speedIndependantCropStart() const;
109     GenTime speedIndependantCropDuration() const;
110     const ItemInfo speedIndependantInfo() const;
111     int hasEffect(const QString &tag, const QString &id) const;
112     bool checkKeyFrames();
113     QPixmap startThumb() const;
114     QPixmap endThumb() const;
115     void setVideoOnly(bool force);
116     void setAudioOnly(bool force);
117     bool isVideoOnly() const;
118     bool isAudioOnly() const;
119     /** Called when clip start is resized, adjust keyframes values */
120     bool checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
121     void insertKeyframe(QDomElement effect, int pos, int val);
122     void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
123     void updateKeyframes(QDomElement effect);
124
125 protected:
126     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
127     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
128     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
129     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
130     //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
131     //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
132     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
133
134 private:
135     DocClipBase *m_clip;
136     ItemInfo m_speedIndependantInfo;
137     QString m_producer;
138     CLIPTYPE m_clipType;
139     QString m_clipName;
140     QString m_effectNames;
141     int m_startFade;
142     int m_endFade;
143     bool m_audioOnly;
144     bool m_videoOnly;
145     QColor m_baseColor;
146
147     QPixmap m_startPix;
148     QPixmap m_endPix;
149
150     bool m_hasThumbs;
151     QTimer m_startThumbTimer;
152     QTimer m_endThumbTimer;
153
154     int m_selectedEffect;
155     QTimeLine *m_timeLine;
156     bool m_startThumbRequested;
157     bool m_endThumbRequested;
158     //bool m_hover;
159     double m_speed;
160     int m_strobe;
161
162     EffectsList m_effectList;
163     QList <Transition*> m_transitionsList;
164     QMap<int, QPixmap> m_audioThumbCachePic;
165     bool m_audioThumbReady;
166     double m_framePixelWidth;
167
168     QPixmap m_videoPix;
169     QPixmap m_audioPix;
170
171 private slots:
172     void slotGetStartThumb();
173     void slotGetEndThumb();
174     void slotGotAudioData();
175     void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
176     void animate(qreal value);
177     void slotSetStartThumb(QImage img);
178     void slotSetEndThumb(QImage img);
179     void slotThumbReady(int frame, QImage img);
180
181 public slots:
182     void slotFetchThumbs();
183     void slotSetStartThumb(const QPixmap pix);
184     void slotSetEndThumb(const QPixmap pix);
185
186 signals:
187     void getThumb(int, int);
188     void prepareAudioThumb(double, int, int, int);
189 };
190
191 #endif