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