]> git.sesse.net Git - kdenlive/blob - src/customtrackview.h
Change clip speed (slowmotion) - not finished yet, saving does not work
[kdenlive] / src / customtrackview.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 CUSTOMTRACKVIEW_H
22 #define CUSTOMTRACKVIEW_H
23
24 #include <QGraphicsView>
25 #include <QGraphicsItemAnimation>
26 #include <QTimeLine>
27 #include <QMenu>
28
29 #include <KUndoStack>
30
31 #include "kdenlivedoc.h"
32 #include "docclipbase.h"
33 #include "guide.h"
34 #include "effectslist.h"
35
36 class ClipItem;
37 class AbstractClipItem;
38 class Transition;
39
40 class CustomTrackView : public QGraphicsView {
41     Q_OBJECT
42
43 public:
44     CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent = 0);
45     virtual ~ CustomTrackView();
46     virtual void mousePressEvent(QMouseEvent * event);
47     virtual void mouseReleaseEvent(QMouseEvent * event);
48     virtual void mouseMoveEvent(QMouseEvent * event);
49     virtual void mouseDoubleClickEvent(QMouseEvent *event);
50     void addTrack(TrackInfo type);
51     void removeTrack();
52     int cursorPos();
53     void checkAutoScroll();
54     void moveClip(const ItemInfo start, const ItemInfo end);
55     /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
56     void moveTransition(const ItemInfo start, const ItemInfo end);
57     void resizeClip(const ItemInfo start, const ItemInfo end);
58     void addClip(QDomElement xml, int clipId, ItemInfo info, EffectsList list = EffectsList());
59     void deleteClip(ItemInfo info);
60     void slotAddClipMarker();
61     void slotEditClipMarker();
62     void slotDeleteClipMarker();
63     void slotDeleteAllClipMarkers();
64     void addMarker(const int id, const GenTime &pos, const QString comment);
65     void setScale(double scaleFactor);
66     void deleteClip(int clipId);
67     void slotAddEffect(QDomElement effect, GenTime pos, int track);
68     void addEffect(int track, GenTime pos, QDomElement effect);
69     void deleteEffect(int track, GenTime pos, QDomElement effect);
70     void updateEffect(int track, GenTime pos, QDomElement effect, int ix);
71     void moveEffect(int track, GenTime pos, int oldPos, int newPos);
72     void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params);
73     void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params);
74     void updateTransition(int track, GenTime pos,  QDomElement oldTransition, QDomElement transition);
75     void moveTransition(GenTime oldpos, GenTime newpos);
76     void activateMonitor();
77     int duration() const;
78     void deleteSelectedClips();
79     void cutSelectedClips();
80     void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition);
81     void checkTrackHeight();
82     QList <TrackInfo> tracksList() const;
83     void setTool(PROJECTTOOL tool);
84     void cutClip(ItemInfo info, GenTime cutTime, bool cut);
85     void slotSeekToPreviousSnap();
86     void slotSeekToNextSnap();
87     double getSnapPointForPos(double pos);
88     void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
89     bool findString(const QString &text);
90     bool findNextString(const QString &text);
91     void initSearchStrings();
92     void clearSearchStrings();
93     void clipStart();
94     void clipEnd();
95     void changeClipSpeed();
96     void doChangeClipSpeed(ItemInfo info, double speed, int id);
97
98 public slots:
99     void setCursorPos(int pos, bool seek = true);
100     void moveCursorPos(int delta);
101     void updateCursorPos();
102     void slotDeleteEffect(ClipItem *clip, QDomElement effect);
103     void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
104     void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
105     void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
106     void slotRefreshEffects(ClipItem *clip);
107     void setDuration(int duration);
108     void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
109     void slotAddTransitionToSelectedClips(QDomElement transition);
110     void slotTransitionUpdated(Transition *, QDomElement);
111     void slotSwitchTrackAudio(int ix);
112     void slotSwitchTrackVideo(int ix);
113     void slotUpdateClip(int clipId);
114     void slotAddClipMarker(int id, GenTime t, QString c);
115     bool addGuide(const GenTime pos, const QString &comment);
116     void slotAddGuide();
117     void slotEditGuide(CommentedTime guide);
118     void slotEditGuide();
119     void slotDeleteGuide();
120     void slotDeleteAllGuides();
121     void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
122     void copyClip();
123     void pasteClip();
124     void pasteClipEffects();
125
126 protected:
127     virtual void drawBackground(QPainter * painter, const QRectF & rect);
128     //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
129     virtual void dragEnterEvent(QDragEnterEvent * event);
130     virtual void dragMoveEvent(QDragMoveEvent * event);
131     virtual void dragLeaveEvent(QDragLeaveEvent * event);
132     virtual void dropEvent(QDropEvent * event);
133     virtual void wheelEvent(QWheelEvent * e);
134     virtual QStringList mimeTypes() const;
135     virtual Qt::DropActions supportedDropActions() const;
136     virtual void resizeEvent(QResizeEvent * event);
137
138 private:
139     uint m_tracksHeight;
140     int m_projectDuration;
141     int m_cursorPos;
142     ClipItem *m_dropItem;
143     KdenliveDoc *m_document;
144     void addItem(DocClipBase *clip, QPoint pos);
145     QGraphicsLineItem *m_cursorLine;
146     ItemInfo m_dragItemInfo;
147     OPERATIONTYPE m_operationMode;
148     OPERATIONTYPE m_moveOpMode;
149     AbstractClipItem *m_dragItem;
150     Guide *m_dragGuide;
151     KUndoStack *m_commandStack;
152     QGraphicsItem *m_visualTip;
153     QGraphicsItemAnimation *m_animation;
154     QTimeLine *m_animationTimer;
155     QColor m_tipColor;
156     QPen m_tipPen;
157     double m_scale;
158     QPoint m_clickPoint;
159     QPoint m_clickEvent;
160     QList <GenTime> m_snapPoints;
161     QList <CommentedTime> m_searchPoints;
162     QList <Guide *> m_guides;
163     void updateSnapPoints(AbstractClipItem *selected);
164     ClipItem *getClipItemAt(int pos, int track);
165     ClipItem *getClipItemAt(GenTime pos, int track);
166     Transition *getTransitionItemAt(int pos, int track);
167     Transition *getTransitionItemAt(GenTime pos, int track);
168     void checkScrolling();
169     /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
170     bool m_autoScroll;
171     void displayContextMenu(QPoint pos, AbstractClipItem *clip = NULL);
172     QMenu *m_timelineContextMenu;
173     QMenu *m_timelineContextClipMenu;
174     QMenu *m_timelineContextTransitionMenu;
175     QList <TrackInfo> m_tracksList;
176     QList <CommentedTime> m_searchStrings;
177     int m_findIndex;
178     PROJECTTOOL m_tool;
179     QCursor m_razorCursor;
180     /** list containing items currently copied in the timeline */
181     QList<AbstractClipItem *> m_copiedItems;
182     QList<AbstractClipItem *> m_selectedClipList;
183     /** Used to get the point in timeline where a context menu was opened */
184     QPoint m_menuPosition;
185
186     /** Get the index of the video track that is just below current track */
187     int getPreviousVideoTrack(int track);
188     void updateClipFade(ClipItem * item, bool updateFadeOut = false);
189     bool canBePastedTo(ItemInfo info, int type) const;
190     bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
191     bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
192
193 private slots:
194     void slotRefreshGuides();
195
196 signals:
197     void cursorMoved(int, int);
198     void zoomIn();
199     void zoomOut();
200     void mousePosition(int);
201     void clipItemSelected(ClipItem*);
202     void transitionItemSelected(Transition*);
203     void activateDocumentMonitor();
204     void trackHeightChanged();
205     void displayMessage(const QString, MessageType);
206     void showClipFrame(DocClipBase *, const int);
207 };
208
209 #endif
210