]> git.sesse.net Git - kdenlive/blob - src/customtrackview.h
copy / paste clips and transitions, move several clips
[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     QDomElement xmlInfo();
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
96 public slots:
97     void setCursorPos(int pos, bool seek = true);
98     void moveCursorPos(int delta);
99     void updateCursorPos();
100     void slotDeleteEffect(ClipItem *clip, QDomElement effect);
101     void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
102     void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
103     void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
104     void slotRefreshEffects(ClipItem *clip);
105     void setDuration(int duration);
106     void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
107     void slotAddTransitionToSelectedClips(QDomElement transition);
108     void slotTransitionUpdated(Transition *, QDomElement);
109     void slotSwitchTrackAudio(int ix);
110     void slotSwitchTrackVideo(int ix);
111     void slotUpdateClip(int clipId);
112     void slotAddClipMarker(int id, GenTime t, QString c);
113     bool addGuide(const GenTime pos, const QString &comment);
114     void slotAddGuide();
115     void slotEditGuide(CommentedTime guide);
116     void slotEditGuide();
117     void slotDeleteGuide();
118     void slotDeleteAllGuides();
119     void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
120     void copyClip();
121     void pasteClip();
122
123 protected:
124     virtual void drawBackground(QPainter * painter, const QRectF & rect);
125     //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
126     virtual void dragEnterEvent(QDragEnterEvent * event);
127     virtual void dragMoveEvent(QDragMoveEvent * event);
128     virtual void dragLeaveEvent(QDragLeaveEvent * event);
129     virtual void dropEvent(QDropEvent * event);
130     virtual void wheelEvent(QWheelEvent * e);
131     virtual QStringList mimeTypes() const;
132     virtual Qt::DropActions supportedDropActions() const;
133     virtual void resizeEvent(QResizeEvent * event);
134
135 private:
136     uint m_tracksHeight;
137     int m_projectDuration;
138     int m_cursorPos;
139     ClipItem *m_dropItem;
140     KdenliveDoc *m_document;
141     void addItem(DocClipBase *clip, QPoint pos);
142     QGraphicsLineItem *m_cursorLine;
143     ItemInfo m_dragItemInfo;
144     OPERATIONTYPE m_operationMode;
145     OPERATIONTYPE m_moveOpMode;
146     AbstractClipItem *m_dragItem;
147     Guide *m_dragGuide;
148     KUndoStack *m_commandStack;
149     QGraphicsItem *m_visualTip;
150     QGraphicsItemAnimation *m_animation;
151     QTimeLine *m_animationTimer;
152     QColor m_tipColor;
153     QPen m_tipPen;
154     double m_scale;
155     QPoint m_clickPoint;
156     QPoint m_clickEvent;
157     QList <GenTime> m_snapPoints;
158     QList <CommentedTime> m_searchPoints;
159     QList <Guide *> m_guides;
160     void updateSnapPoints(AbstractClipItem *selected);
161     ClipItem *getClipItemAt(int pos, int track);
162     ClipItem *getClipItemAt(GenTime pos, int track);
163     Transition *getTransitionItemAt(int pos, int track);
164     Transition *getTransitionItemAt(GenTime pos, int track);
165     void checkScrolling();
166     /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
167     bool m_autoScroll;
168     void displayContextMenu(QPoint pos, AbstractClipItem *clip = NULL);
169     QMenu *m_timelineContextMenu;
170     QMenu *m_timelineContextClipMenu;
171     QMenu *m_timelineContextTransitionMenu;
172     QList <TrackInfo> m_tracksList;
173     QList <CommentedTime> m_searchStrings;
174     int m_findIndex;
175     PROJECTTOOL m_tool;
176     QCursor m_razorCursor;
177     /** list containing items currently copied in the timeline */
178     QList<AbstractClipItem *> m_copiedItems;
179     QList<AbstractClipItem *> m_selectedClipList;
180     /** Used to get the point in timeline where a context menu was opened */
181     QPoint m_menuPosition;
182
183     /** Get the index of the video track that is just below current track */
184     int getPreviousVideoTrack(int track);
185     void updateClipFade(ClipItem * item, bool updateFadeOut = false);
186     bool canBePastedTo(ItemInfo info, int type) const;
187     bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
188     bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
189
190 private slots:
191     void slotRefreshGuides();
192
193 signals:
194     void cursorMoved(int, int);
195     void zoomIn();
196     void zoomOut();
197     void mousePosition(int);
198     void clipItemSelected(ClipItem*);
199     void transitionItemSelected(Transition*);
200     void activateDocumentMonitor();
201     void trackHeightChanged();
202     void displayMessage(const QString, MessageType);
203     void showClipFrame(DocClipBase *, const int);
204 };
205
206 #endif
207