]> git.sesse.net Git - kdenlive/blob - src/clipitem.h
Fix lots of issues with slowmotioned clips (bugs in move, resize, copy, load & save)
[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     Q_OBJECT
41
42 public:
43     ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs = true);
44     virtual ~ ClipItem();
45     virtual void paint(QPainter *painter,
46                        const QStyleOptionGraphicsItem *option,
47                        QWidget *);
48     virtual int type() const;
49     void resizeStart(int posx, double speed = 1.0);
50     void resizeEnd(int posx, double speed = 1.0, bool updateKeyFrames = true);
51     OPERATIONTYPE operationMode(QPointF pos);
52     const QString &clipProducer() const;
53     int clipType() 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     EffectsParameterList addEffect(QDomElement effect, bool animate = true);
65     /** Get the effect parameters that will be passed to Mlt */
66     EffectsParameterList getEffectArgs(QDomElement effect);
67     /** Delete effect with id index */
68     void deleteEffect(QString index);
69     /** return the number of effects in that clip */
70     int effectsCount();
71     /** return a unique effect id */
72     int effectsCounter();
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);
77     void flashClip();
78     void addTransition(Transition*);
79     /** regenerate audio and video thumbnails */
80     void resetThumbs();
81     /** update clip properties from base clip */
82     void refreshClip();
83     /** Returns a list of times for this clip's markers */
84     QList <GenTime> snapMarkers() const;
85     QList <CommentedTime> commentedSnapMarkers() const;
86     uint fadeIn() const;
87     uint fadeOut() 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);
97     double speed() const;
98     GenTime maxDuration() const;
99     GenTime cropStart() const;
100     GenTime endPos() const;
101     GenTime cropDuration() const;
102     int hasEffect(const QString &tag, const QString &id) const;
103     bool checkKeyFrames();
104     QPixmap startThumb() const;
105     QPixmap endThumb() const;
106
107 protected:
108     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
109     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
110     virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
111     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
112     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
113     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
114     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
115     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
116     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
117
118 private:
119     DocClipBase *m_clip;
120     OPERATIONTYPE m_resizeMode;
121     int m_grabPoint;
122     QString m_producer;
123     CLIPTYPE m_clipType;
124     QString m_clipName;
125     QString m_effectNames;
126     uint m_startFade;
127     uint m_endFade;
128     int m_maxTrack;
129
130     QPixmap m_startPix;
131     QPixmap m_endPix;
132     bool m_hasThumbs;
133     QTimer *startThumbTimer;
134     QTimer *endThumbTimer;
135
136     int m_selectedEffect;
137     double m_opacity;
138     QTimeLine *m_timeLine;
139     bool m_startThumbRequested;
140     bool m_endThumbRequested;
141     bool m_hover;
142     double m_speed;
143
144     EffectsList m_effectList;
145     QList <Transition*> m_transitionsList;
146     QMap<int, QPixmap> audioThumbCachePic;
147     bool audioThumbWasDrawn, audioThumbReady;
148     double framePixelWidth;
149     QMap<int, QPainterPath > channelPaths;
150     /** Called when clip start is resized, adjust keyframes values */
151     void checkEffectsKeyframesPos(const int previous, const int current, bool fromStart);
152
153 private slots:
154     void slotFetchThumbs();
155     void slotGetStartThumb();
156     void slotGetEndThumb();
157     void slotGotAudioData();
158     void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
159     void animate(qreal value);
160     void slotSetStartThumb(QImage img);
161     void slotSetEndThumb(QImage img);
162     void slotThumbReady(int frame, QPixmap pix);
163
164 public slots:
165     void slotSetStartThumb(const QPixmap pix);
166     void slotSetEndThumb(const QPixmap pix);
167
168 signals:
169     void getThumb(int, int);
170     void prepareAudioThumb(double, int, int, int);
171 };
172
173 #endif