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