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