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