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