1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #ifndef CUSTOMTRACKVIEW_H
22 #define CUSTOMTRACKVIEW_H
24 #include <QGraphicsView>
25 #include <QGraphicsItemAnimation>
30 #include "kdenlivedoc.h"
31 #include "docclipbase.h"
33 #include "effectslist.h"
34 #include "customtrackscene.h"
37 class AbstractClipItem;
38 class AbstractGroupItem;
41 class CustomTrackView : public QGraphicsView
46 CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent = 0);
47 virtual ~ CustomTrackView();
48 virtual void mousePressEvent(QMouseEvent * event);
49 virtual void mouseReleaseEvent(QMouseEvent * event);
50 virtual void mouseMoveEvent(QMouseEvent * event);
51 virtual void mouseDoubleClickEvent(QMouseEvent *event);
52 void addTrack(TrackInfo type, int ix = -1);
53 void removeTrack(int ix);
54 void changeTrack(int ix, TrackInfo type);
56 void checkAutoScroll();
57 void moveClip(const ItemInfo start, const ItemInfo end, bool refresh);
58 void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove = false);
59 /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
60 void moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh);
61 void resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry = false);
62 void addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList list = EffectsList(), bool refresh = true);
63 void deleteClip(ItemInfo info, bool refresh = true);
64 void slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position);
65 void slotDeleteAllClipMarkers(const QString &id);
66 void addMarker(const QString &id, const GenTime &pos, const QString comment);
67 void setScale(double scaleFactor, double verticalScale);
68 void deleteClip(const QString &clipId);
69 void slotAddEffect(QDomElement effect, GenTime pos, int track);
70 void slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group);
71 void addEffect(int track, GenTime pos, QDomElement effect);
72 void deleteEffect(int track, GenTime pos, QDomElement effect);
73 void updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser = true);
74 void moveEffect(int track, GenTime pos, int oldPos, int newPos);
75 void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
76 void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
77 void updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget);
78 void moveTransition(GenTime oldpos, GenTime newpos);
79 void activateMonitor();
81 void deleteSelectedClips();
82 void cutSelectedClips();
83 void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup);
84 void checkTrackHeight();
85 //QList <TrackInfo> tracksList() const;
86 void setTool(PROJECTTOOL tool);
87 ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
88 void slotSeekToPreviousSnap();
89 void slotSeekToNextSnap();
90 double getSnapPointForPos(double pos);
91 void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
92 bool findString(const QString &text);
93 bool findNextString(const QString &text);
94 void initSearchStrings();
95 void clearSearchStrings();
98 void changeClipSpeed();
99 void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
100 void setDocumentModified();
103 void slotInsertSpace();
104 void slotRemoveSpace();
105 void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset);
106 ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
107 void deleteTimelineTrack(int ix, TrackInfo trackinfo);
108 void changeTimelineTrack(int ix, TrackInfo trackinfo);
109 void saveThumbnails();
110 void autoTransition();
111 QStringList getLadspaParams(QDomElement effect) const;
112 void initCursorPos(int pos);
113 void lockTrack(int ix, bool lock);
114 void groupClips(bool group = true);
115 void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
116 void loadGroups(const QDomNodeList groups);
118 void doSplitAudio(const GenTime &pos, int track, bool split);
121 void setAudioAndVideo();
122 void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
123 int hasGuide(int pos, int offset);
124 void reloadTransitionLumas();
125 void updateProjectFps();
127 int selectedTrack() const;
128 void selectClip(bool add, bool group = false);
129 void selectTransition(bool add, bool group = false);
130 void setEditMode(EDITMODE mode);
133 void setCursorPos(int pos, bool seek = true);
134 void moveCursorPos(int delta);
135 void updateCursorPos();
136 void slotDeleteEffect(ClipItem *clip, QDomElement effect);
137 void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
138 void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
139 void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
140 void slotRefreshEffects(ClipItem *clip);
141 void setDuration(int duration);
142 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
143 void slotAddTransitionToSelectedClips(QDomElement transition);
144 void slotTransitionUpdated(Transition *, QDomElement);
145 void slotSwitchTrackAudio(int ix);
146 void slotSwitchTrackVideo(int ix);
147 void slotSwitchTrackLock(int ix);
148 void slotUpdateClip(const QString &clipId, bool reload = true);
149 void slotAddClipMarker(const QString &id, GenTime t, QString c);
150 bool addGuide(const GenTime pos, const QString &comment);
152 void slotEditGuide(CommentedTime guide);
153 void slotEditGuide(int guidePos = -1);
154 void slotDeleteGuide(int guidePos = -1);
155 void slotDeleteAllGuides();
156 void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
159 void pasteClipEffects();
160 void slotUpdateAllThumbs();
161 void slotCheckPositionScrolling();
162 void slotInsertTrack(int ix);
163 void slotDeleteTrack(int ix);
164 void slotChangeTrack(int ix);
165 void clipNameChanged(const QString id, const QString name);
167 void slotTrackDown();
168 void slotSelectTrack(int ix);
171 virtual void drawBackground(QPainter * painter, const QRectF & rect);
172 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
173 virtual void dragEnterEvent(QDragEnterEvent * event);
174 virtual void dragMoveEvent(QDragMoveEvent * event);
175 virtual void dragLeaveEvent(QDragLeaveEvent * event);
176 virtual void dropEvent(QDropEvent * event);
177 virtual void wheelEvent(QWheelEvent * e);
178 virtual void keyPressEvent(QKeyEvent * event);
179 virtual QStringList mimeTypes() const;
180 virtual Qt::DropActions supportedDropActions() const;
184 int m_projectDuration;
186 KdenliveDoc *m_document;
187 CustomTrackScene *m_scene;
188 QGraphicsLineItem *m_cursorLine;
189 ItemInfo m_dragItemInfo;
190 ItemInfo m_selectionGroupInfo;
191 OPERATIONTYPE m_operationMode;
192 OPERATIONTYPE m_moveOpMode;
193 AbstractClipItem *m_dragItem;
195 QUndoStack *m_commandStack;
196 QGraphicsItem *m_visualTip;
197 QGraphicsItemAnimation *m_animation;
198 QTimeLine *m_animationTimer;
203 QList <CommentedTime> m_searchPoints;
204 QList <Guide *> m_guides;
205 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
206 ClipItem *getClipItemAt(int pos, int track);
207 ClipItem *getClipItemAt(GenTime pos, int track);
208 ClipItem *getClipItemAtEnd(GenTime pos, int track);
209 ClipItem *getClipItemAtStart(GenTime pos, int track);
210 Transition *getTransitionItemAt(int pos, int track);
211 Transition *getTransitionItemAt(GenTime pos, int track);
212 Transition *getTransitionItemAtEnd(GenTime pos, int track);
213 Transition *getTransitionItemAtStart(GenTime pos, int track);
214 void checkScrolling();
215 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
217 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
218 QMenu *m_timelineContextMenu;
219 QMenu *m_timelineContextClipMenu;
220 QMenu *m_timelineContextTransitionMenu;
221 QAction *m_autoTransition;
222 QAction *m_pasteEffectsAction;
223 QAction *m_ungroupAction;
224 QAction *m_editGuide;
225 QAction *m_deleteGuide;
226 QActionGroup *m_clipTypeGroup;
227 QTimer m_scrollTimer;
228 QTimer m_thumbsTimer;
234 QCursor m_razorCursor;
235 QCursor m_spacerCursor;
236 /** list containing items currently copied in the timeline */
237 QList<AbstractClipItem *> m_copiedItems;
238 /** Used to get the point in timeline where a context menu was opened */
239 QPoint m_menuPosition;
241 AbstractGroupItem *m_selectionGroup;
242 QList <ClipItem *> m_waitingThumbs;
245 /** Get the index of the video track that is just below current track */
246 int getPreviousVideoTrack(int track);
247 void updatePositionEffects(ClipItem * item, ItemInfo info);
248 bool insertDropClips(const QMimeData *data, const QPoint pos);
249 bool canBePastedTo(ItemInfo info, int type) const;
250 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
251 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
252 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
253 ClipItem *getClipUnderCursor() const;
254 AbstractClipItem *getMainActiveClip() const;
255 void resetSelectionGroup(bool selectItems = true);
256 void groupSelectedItems(bool force = false, bool createNewGroup = false);
257 /** Get available space for clip move (min and max free positions) */
258 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
259 /** Get available space for transition move (min and max free positions) */
260 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
261 void updateClipTypeActions(ClipItem *clip);
262 /** Whether an item can be moved to a new position without colliding with similar items */
263 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
264 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
265 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
268 void slotRefreshGuides();
269 void slotEnableRefresh();
270 void slotCheckMouseScrolling();
271 void slotEditTimeLineGuide();
272 void slotDeleteTimeLineGuide();
273 void slotFetchNextThumbs();
276 void cursorMoved(int, int);
279 void mousePosition(int);
280 void clipItemSelected(ClipItem*, int ix = -1);
281 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
282 void activateDocumentMonitor();
283 void trackHeightChanged();
284 void tracksChanged();
285 void displayMessage(const QString, MessageType);
286 void showClipFrame(DocClipBase *, const int);
287 void doTrackLock(int, bool);
288 void updateClipMarkers(DocClipBase *);
289 void updateTrackHeaders();