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 <KPixmapCache>
26 #include <QGraphicsView>
27 #include <QGraphicsItemAnimation>
32 #include "kdenlivedoc.h"
33 #include "docclipbase.h"
35 #include "effectslist.h"
36 #include "customtrackscene.h"
39 class AbstractClipItem;
40 class AbstractGroupItem;
43 class CustomTrackView : public QGraphicsView
48 CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent = 0);
49 virtual ~ CustomTrackView();
50 virtual void mousePressEvent(QMouseEvent * event);
51 virtual void mouseReleaseEvent(QMouseEvent * event);
52 virtual void mouseMoveEvent(QMouseEvent * event);
53 virtual void mouseDoubleClickEvent(QMouseEvent *event);
54 void addTrack(TrackInfo type, int ix = -1);
55 void removeTrack(int ix);
56 /** @brief Makes the document use new track infos (name, type, ...). */
57 void configTracks(QList <TrackInfo> trackInfos);
59 void checkAutoScroll();
60 void moveClip(const ItemInfo start, const ItemInfo end, bool refresh);
61 void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove = false);
62 /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
63 void moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh);
64 void resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry = false);
65 void addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList list = EffectsList(), bool overwrite = false, bool push = false, bool refresh = true);
66 void deleteClip(ItemInfo info, bool refresh = true);
67 void slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position);
68 void slotDeleteAllClipMarkers(const QString &id);
69 void addMarker(const QString &id, const GenTime &pos, const QString comment);
70 void setScale(double scaleFactor, double verticalScale);
71 void deleteClip(const QString &clipId);
72 void slotAddEffect(QDomElement effect, GenTime pos, int track);
73 void slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group);
74 void addEffect(int track, GenTime pos, QDomElement effect);
75 void deleteEffect(int track, GenTime pos, QDomElement effect);
76 void updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser = true);
77 void moveEffect(int track, GenTime pos, int oldPos, int newPos);
78 void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
79 void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
80 void updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget);
81 void moveTransition(GenTime oldpos, GenTime newpos);
82 void activateMonitor();
84 void deleteSelectedClips();
85 /** @brief Cuts all clips that are selected at the timeline cursor position. */
86 void cutSelectedClips();
87 void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
88 void checkTrackHeight();
89 //QList <TrackInfo> tracksList() const;
90 void setTool(PROJECTTOOL tool);
91 ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
92 void slotSeekToPreviousSnap();
93 void slotSeekToNextSnap();
94 double getSnapPointForPos(double pos);
95 void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
96 bool findString(const QString &text);
97 void selectFound(QString track, QString pos);
98 bool findNextString(const QString &text);
99 void initSearchStrings();
100 void clearSearchStrings();
101 QList<ItemInfo> findId(const QString &clipId);
104 void changeClipSpeed();
105 void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
106 /** @brief Sets the document as modified. */
107 void setDocumentModified();
111 /** @brief Prepares inserting space.
113 * Shows a dialog to configure length and track. */
114 void slotInsertSpace();
115 /** @brief Prepares removing space. */
116 void slotRemoveSpace();
117 void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset);
118 ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
119 void deleteTimelineTrack(int ix, TrackInfo trackinfo);
120 void saveThumbnails();
121 void autoTransition();
122 QStringList getLadspaParams(QDomElement effect) const;
123 void initCursorPos(int pos);
125 /** @brief Locks or unlocks a track.
126 * @param ix number of track
127 * @param lock whether to lock or unlock
129 * Makes sure no clip on track to lock is selected. */
130 void lockTrack(int ix, bool lock);
131 void groupClips(bool group = true);
132 void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
133 void loadGroups(const QDomNodeList groups);
135 /** @brief Creates SplitAudioCommands for selected clips. */
138 /** @brief Seperates the audio of a clip to a audio track.
139 * @param pos Position of the clip to split
140 * @param track Track of the clip
141 * @param split Split or unsplit */
142 void doSplitAudio(const GenTime &pos, int track, bool split);
145 void setAudioAndVideo();
146 void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
147 int hasGuide(int pos, int offset);
148 void reloadTransitionLumas();
149 void updateProjectFps();
151 int selectedTrack() const;
152 QStringList selectedClips() const;
153 QList<ClipItem *> selectedClipItems() const;
155 /** @brief Selects a clip.
156 * @param add Whether to select or deselect
157 * @param group (optional) Whether to add the clip to a group
158 * @param track (optional) The track of the clip (has to be combined with @param pos)
159 * @param pos (optional) The position of the clip (has to be combined with @param track) */
160 void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
161 void selectTransition(bool add, bool group = false);
162 QStringList extractTransitionsLumas();
163 void setEditMode(EDITMODE mode);
165 /** @brief Inserts @param clip.
166 * @param clip The clip to insert
167 * @param in The inpoint of the clip (crop from start)
168 * @param out The outpoint of the clip (crop from end)
170 * Inserts at the position of timeline cursor and selected track. */
171 void insertClipCut(DocClipBase *clip, int in, int out);
172 void clearSelection();
173 void editItemDuration();
174 void buildGuidesMenu(QMenu *goMenu) const;
175 KPixmapCache* pixmapCache;
176 /** update the timeline objects when palette changes */
177 void updatePalette();
180 void setCursorPos(int pos, bool seek = true);
181 void moveCursorPos(int delta);
182 void updateCursorPos();
183 void slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup = true);
184 void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
185 void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
186 void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
187 void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
188 void slotRefreshEffects(ClipItem *clip);
189 void setDuration(int duration);
190 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
191 void slotAddTransitionToSelectedClips(QDomElement transition);
192 void slotTransitionUpdated(Transition *, QDomElement);
193 void slotSwitchTrackAudio(int ix);
194 void slotSwitchTrackVideo(int ix);
195 void slotSwitchTrackLock(int ix);
196 void slotUpdateClip(const QString &clipId, bool reload = true);
197 void slotAddClipMarker(const QString &id, GenTime t, QString c);
198 bool addGuide(const GenTime pos, const QString &comment);
200 void slotEditGuide(CommentedTime guide);
201 void slotEditGuide(int guidePos = -1);
202 void slotDeleteGuide(int guidePos = -1);
203 void slotDeleteAllGuides();
204 void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
207 void pasteClipEffects();
208 void slotUpdateAllThumbs();
209 void slotCheckPositionScrolling();
210 void slotInsertTrack(int ix);
212 /** @brief Shows a dialog for selecting a track to delete.
213 * @param ix Number of the track, which should be pre-selected in the dialog */
214 void slotDeleteTrack(int ix);
215 /** @brief Shows the configure tracks dialog. */
216 void slotConfigTracks(int ix);
217 void clipNameChanged(const QString id, const QString name);
219 void slotTrackDown();
220 void slotSelectTrack(int ix);
221 void insertZoneOverwrite(QStringList data, int in);
223 /** @brief Rebuilds a group to fit again after children changed.
224 * @param childTrack the track of one of the groups children
225 * @param childPos The position of the same child */
226 void rebuildGroup(int childTrack, GenTime childPos);
227 /** @brief Rebuilds a group to fit again after children changed.
228 * @param group The group to rebuild */
229 void rebuildGroup(AbstractGroupItem *group);
231 /** @brief Cuts a group into two parts.
232 * @param clips1 Clips before the cut
233 * @param transitions1 Transitions before the cut
234 * @param clipsCut Clips that need to be cut
235 * @param transitionsCut Transitions that need to be cut
236 * @param clips2 Clips behind the cut
237 * @param transitions2 Transitions behind the cut
238 * @param cutPos Absolute position of the cut
239 * @param cut true = cut, false = "uncut" */
240 void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
243 virtual void drawBackground(QPainter * painter, const QRectF & rect);
244 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
245 virtual void dragEnterEvent(QDragEnterEvent * event);
246 virtual void dragMoveEvent(QDragMoveEvent * event);
247 virtual void dragLeaveEvent(QDragLeaveEvent * event);
248 /** @brief Something has been dropped onto the timeline */
249 virtual void dropEvent(QDropEvent * event);
250 virtual void wheelEvent(QWheelEvent * e);
251 virtual void keyPressEvent(QKeyEvent * event);
252 virtual QStringList mimeTypes() const;
253 virtual Qt::DropActions supportedDropActions() const;
257 int m_projectDuration;
259 KdenliveDoc *m_document;
260 CustomTrackScene *m_scene;
261 QGraphicsLineItem *m_cursorLine;
262 ItemInfo m_dragItemInfo;
263 ItemInfo m_selectionGroupInfo;
264 OPERATIONTYPE m_operationMode;
265 OPERATIONTYPE m_moveOpMode;
266 AbstractClipItem *m_dragItem;
268 QUndoStack *m_commandStack;
269 QGraphicsItem *m_visualTip;
270 QGraphicsItemAnimation *m_animation;
271 QTimeLine *m_animationTimer;
276 QList <CommentedTime> m_searchPoints;
277 QList <Guide *> m_guides;
278 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
279 ClipItem *getClipItemAt(int pos, int track);
280 ClipItem *getClipItemAt(GenTime pos, int track);
281 ClipItem *getClipItemAtEnd(GenTime pos, int track);
282 ClipItem *getClipItemAtStart(GenTime pos, int track);
283 Transition *getTransitionItemAt(int pos, int track);
284 Transition *getTransitionItemAt(GenTime pos, int track);
285 Transition *getTransitionItemAtEnd(GenTime pos, int track);
286 Transition *getTransitionItemAtStart(GenTime pos, int track);
287 void checkScrolling();
288 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
290 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
291 QMenu *m_timelineContextMenu;
292 QMenu *m_timelineContextClipMenu;
293 QMenu *m_timelineContextTransitionMenu;
295 QAction *m_autoTransition;
296 QAction *m_pasteEffectsAction;
297 QAction *m_ungroupAction;
298 QAction *m_editGuide;
299 QAction *m_deleteGuide;
300 QActionGroup *m_clipTypeGroup;
301 QTimer m_scrollTimer;
302 QTimer m_thumbsTimer;
308 QCursor m_razorCursor;
309 QCursor m_spacerCursor;
310 /** list containing items currently copied in the timeline */
311 QList<AbstractClipItem *> m_copiedItems;
312 /** Used to get the point in timeline where a context menu was opened */
313 QPoint m_menuPosition;
315 AbstractGroupItem *m_selectionGroup;
316 QList <ClipItem *> m_waitingThumbs;
320 /** Get the index of the video track that is just below current track */
321 int getPreviousVideoTrack(int track);
322 void updatePositionEffects(ClipItem * item, ItemInfo info);
323 bool insertDropClips(const QMimeData *data, const QPoint pos);
324 bool canBePastedTo(ItemInfo info, int type) const;
325 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
326 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
327 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
328 ClipItem *getClipUnderCursor() const;
329 AbstractClipItem *getMainActiveClip() const;
330 void resetSelectionGroup(bool selectItems = true);
331 void groupSelectedItems(bool force = false, bool createNewGroup = false);
332 /** Get available space for clip move (min and max free positions) */
333 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
334 /** Get available space for transition move (min and max free positions) */
335 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
336 void updateClipTypeActions(ClipItem *clip);
337 /** Whether an item can be moved to a new position without colliding with similar items */
338 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
339 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
340 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
341 /** Adjust clips under another one when working in overwrite mode */
342 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
343 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
344 /** Adjust keyframes when pasted to another clip */
345 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
347 /** @brief Removes the tip and stops the animation timer. */
348 void removeTipAnimation();
349 /** @brief Creates a new tip animation.
350 * @param clip clip to display the tip on
351 * @param mode operation mode for which the tip should be displayed
352 * @param size size of the tip */
353 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
355 /** @brief Takes care of updating effects and attached transitions during a resize from start.
356 * @param item Item to resize
357 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
358 * @param pos New startPos
359 * @param check (optional, default = false) Whether to check for collisions
360 * @param command (optional) Will be used as parent command (for undo history) */
361 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
363 /** @brief Takes care of updating effects and attached transitions during a resize from end.
364 * @param item Item to resize
365 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
366 * @param pos New endPos
367 * @param check (optional, default = false) Whether to check for collisions
368 * @param command (optional) Will be used as parent command (for undo history) */
369 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
371 /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
372 * @param group The group to cut
373 * @param cutPos The absolute position of the cut */
374 void razorGroup(AbstractGroupItem *group, GenTime cutPos);
377 void slotRefreshGuides();
378 void slotEnableRefresh();
379 void slotCheckMouseScrolling();
380 void slotEditTimeLineGuide();
381 void slotDeleteTimeLineGuide();
382 void slotFetchNextThumbs();
383 void checkTrackSequence(int track);
384 void slotGoToMarker(QAction *action);
385 void slotResetMenuPosition();
386 void slotDoResetMenuPosition();
389 void cursorMoved(int, int);
392 void mousePosition(int);
393 void clipItemSelected(ClipItem*, int ix = -1);
394 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
395 void activateDocumentMonitor();
396 void trackHeightChanged();
397 void tracksChanged();
398 void displayMessage(const QString, MessageType);
399 void showClipFrame(DocClipBase *, QPoint, const int);
400 void doTrackLock(int, bool);
401 void updateClipMarkers(DocClipBase *);
402 void updateTrackHeaders();