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 <kdeversion.h>
25 #include <KColorScheme>
27 #include <QGraphicsView>
28 #include <QGraphicsItemAnimation>
33 #include <QWaitCondition>
35 #include "kdenlivedoc.h"
36 #include "docclipbase.h"
38 #include "effectslist.h"
39 #include "customtrackscene.h"
42 class AbstractClipItem;
43 class AbstractGroupItem;
46 class CustomTrackView : public QGraphicsView
51 CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent = 0);
52 virtual ~ CustomTrackView();
53 virtual void mousePressEvent(QMouseEvent * event);
54 virtual void mouseReleaseEvent(QMouseEvent * event);
55 virtual void mouseMoveEvent(QMouseEvent * event);
56 virtual void mouseDoubleClickEvent(QMouseEvent *event);
57 void addTrack(TrackInfo type, int ix = -1);
58 void removeTrack(int ix);
59 /** @brief Makes the document use new track infos (name, type, ...). */
60 void configTracks(QList <TrackInfo> trackInfos);
62 void checkAutoScroll();
63 void moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh);
64 void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime &offset, const int trackOffset, bool reverseMove = false);
65 /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
66 void moveTransition(const ItemInfo &start, const ItemInfo &end, bool refresh);
67 void resizeClip(const ItemInfo &start, const ItemInfo &end, bool dontWorry = false);
68 void addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList list = EffectsList(), bool overwrite = false, bool push = false, bool refresh = true);
69 void deleteClip(ItemInfo info, bool refresh = true);
70 void slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position);
71 void slotDeleteAllClipMarkers(const QString &id);
72 void addMarker(const QString &id, const GenTime &pos, const QString &comment);
73 void setScale(double scaleFactor, double verticalScale);
74 void deleteClip(const QString &clipId);
75 void slotAddEffect(QDomElement effect, GenTime pos, int track);
76 void slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group);
77 void addEffect(int track, GenTime pos, QDomElement effect);
78 void deleteEffect(int track, GenTime pos, QDomElement effect);
79 void updateEffect(int track, GenTime pos, QDomElement insertedEffect, bool refreshEffectStack = false);
80 /** @brief Enable / disable a list of effects */
81 void updateEffectState(int track, GenTime pos, QList <int> effectIndexes, bool disable, bool updateEffectStack);
82 void moveEffect(int track, GenTime pos, QList <int> oldPos, QList <int> newPos);
83 void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
84 void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
85 void updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget);
86 void moveTransition(GenTime oldpos, GenTime newpos);
87 void activateMonitor();
89 void deleteSelectedClips();
90 /** @brief Cuts all clips that are selected at the timeline cursor position. */
91 void cutSelectedClips();
92 void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
93 bool checkTrackHeight();
94 void updateSceneFrameWidth();
95 //QList <TrackInfo> tracksList() const;
96 void setTool(PROJECTTOOL tool);
97 ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
98 void slotSeekToPreviousSnap();
99 void slotSeekToNextSnap();
100 double getSnapPointForPos(double pos);
101 void editKeyFrame(const GenTime &pos, const int track, const int index, const QString &keyframes);
102 bool findString(const QString &text);
103 void selectFound(QString track, QString pos);
104 bool findNextString(const QString &text);
105 void initSearchStrings();
106 void clearSearchStrings();
107 QList<ItemInfo> findId(const QString &clipId);
110 void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
111 /** @brief Sets the document as modified. */
112 void setDocumentModified();
116 /** @brief Prepares inserting space.
118 * Shows a dialog to configure length and track. */
119 void slotInsertSpace();
120 /** @brief Prepares removing space. */
121 void slotRemoveSpace();
122 void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime &duration, const GenTime &offset);
123 ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
124 void deleteTimelineTrack(int ix, TrackInfo trackinfo);
125 void saveThumbnails();
126 void autoTransition();
127 void initCursorPos(int pos);
129 /** @brief Locks or unlocks a track.
130 * @param ix number of track
131 * @param lock whether to lock or unlock
132 * @param requestUpdate (default = true) Whether to request an update of the icon in the track header
134 * Makes sure no clip on track to lock is selected. */
135 void lockTrack(int ix, bool lock, bool requestUpdate = true);
136 void groupClips(bool group = true);
137 void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
138 void loadGroups(const QDomNodeList &groups);
140 /** @brief Creates SplitAudioCommands for selected clips. */
143 /** @brief Seperates the audio of a clip to a audio track.
144 * @param pos Position of the clip to split
145 * @param track Track of the clip
146 * @param split Split or unsplit */
147 void doSplitAudio(const GenTime &pos, int track, EffectsList effects, bool split);
150 void setAudioAndVideo();
151 void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
152 int hasGuide(int pos, int offset);
153 void reloadTransitionLumas();
154 void updateProjectFps();
156 int selectedTrack() const;
157 QStringList selectedClips() const;
158 QList<ClipItem *> selectedClipItems() const;
159 /** @brief Checks wheter an item can be inserted (make sure it does not overlap another item) */
160 bool canBePastedTo(ItemInfo info, int type) const;
162 /** @brief Selects a clip.
163 * @param add Whether to select or deselect
164 * @param group (optional) Whether to add the clip to a group
165 * @param track (optional) The track of the clip (has to be combined with @param pos)
166 * @param pos (optional) The position of the clip (has to be combined with @param track) */
167 void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
168 void selectTransition(bool add, bool group = false);
169 QStringList extractTransitionsLumas();
170 void setEditMode(EDITMODE mode);
172 /** @brief Inserts @param clip.
173 * @param clip The clip to insert
174 * @param in The inpoint of the clip (crop from start)
175 * @param out The outpoint of the clip (crop from end)
177 * Inserts at the position of timeline cursor and selected track. */
178 void insertClipCut(DocClipBase *clip, int in, int out);
179 void clearSelection(bool emitInfo = true);
180 void editItemDuration();
181 void buildGuidesMenu(QMenu *goMenu) const;
182 /** update the timeline objects when palette changes */
183 void updatePalette();
184 /** @brief Returns true if a track has audio data on it.
185 * @param track The track number
187 * Check whether given track has a clip with audio in it. */
188 bool hasAudio(int track) const;
193 void setCursorPos(int pos, bool seek = true);
194 void moveCursorPos(int delta);
195 void updateCursorPos();
196 void slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup = true);
197 void slotChangeEffectState(ClipItem *clip, int track, QList <int> effectIndexes, bool disable);
198 void slotChangeEffectPosition(ClipItem *clip, int track, QList <int> currentPos, int newPos);
199 void slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix, bool refreshEffectStack = true);
200 void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
201 void slotRefreshEffects(ClipItem *clip);
202 void setDuration(int duration);
203 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
204 void slotAddTransitionToSelectedClips(QDomElement transition);
205 void slotTransitionUpdated(Transition *, QDomElement);
206 void slotSwitchTrackAudio(int ix);
207 void slotSwitchTrackVideo(int ix);
208 void slotSwitchTrackLock(int ix);
209 void slotUpdateClip(const QString &clipId, bool reload = true);
211 /** @brief Creates a AddClipCommand to add, edit or delete a marker.
212 * @param id Id of the marker's clip
213 * @param t Position of the marker
214 * @param c Comment of the marker */
215 void slotAddClipMarker(const QString &id, GenTime t, QString c);
216 bool addGuide(const GenTime &pos, const QString &comment);
218 /** @brief Shows a dialog for adding a guide.
219 * @param dialog (default = true) false = do not show the dialog but use current position as position and comment */
220 void slotAddGuide(bool dialog = true);
221 void slotEditGuide(CommentedTime guide);
222 void slotEditGuide(int guidePos = -1);
223 void slotDeleteGuide(int guidePos = -1);
224 void slotDeleteAllGuides();
225 void editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment);
228 void pasteClipEffects();
229 void slotUpdateAllThumbs();
230 void slotCheckPositionScrolling();
231 void slotInsertTrack(int ix);
233 /** @brief Shows a dialog for selecting a track to delete.
234 * @param ix Number of the track, which should be pre-selected in the dialog */
235 void slotDeleteTrack(int ix);
236 /** @brief Shows the configure tracks dialog. */
237 void slotConfigTracks(int ix);
238 void clipNameChanged(const QString &id, const QString &name);
240 void slotTrackDown();
241 void slotSelectTrack(int ix);
242 void insertZoneOverwrite(QStringList data, int in);
244 /** @brief Rebuilds a group to fit again after children changed.
245 * @param childTrack the track of one of the groups children
246 * @param childPos The position of the same child */
247 void rebuildGroup(int childTrack, GenTime childPos);
248 /** @brief Rebuilds a group to fit again after children changed.
249 * @param group The group to rebuild */
250 void rebuildGroup(AbstractGroupItem *group);
252 /** @brief Cuts a group into two parts.
253 * @param clips1 Clips before the cut
254 * @param transitions1 Transitions before the cut
255 * @param clipsCut Clips that need to be cut
256 * @param transitionsCut Transitions that need to be cut
257 * @param clips2 Clips behind the cut
258 * @param transitions2 Transitions behind the cut
259 * @param cutPos Absolute position of the cut
260 * @param cut true = cut, false = "uncut" */
261 void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
263 /** @brief Add en effect to a track.
264 * @param effect The new effect xml
265 * @param ix The track index */
266 void slotAddTrackEffect(const QDomElement &effect, int ix);
267 /** @brief Select all clips in selected track. */
268 void slotSelectClipsInTrack();
269 /** @brief Select all clips in timeline. */
270 void slotSelectAllClips();
272 /** @brief Update the list of snap points (sticky timeline hotspots).
273 * @param selected The currently selected clip if any
274 * @param offsetList The list of points that should also snap (for example when movin a clip, start and end points should snap
275 * @param skipSelectedItems if true, the selected item start and end points will not be added to snap list */
276 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
278 void slotAddEffect(ClipItem *clip, QDomElement effect);
281 virtual void drawBackground(QPainter * painter, const QRectF & rect);
282 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
283 virtual void dragEnterEvent(QDragEnterEvent * event);
284 virtual void dragMoveEvent(QDragMoveEvent * event);
285 virtual void dragLeaveEvent(QDragLeaveEvent * event);
286 /** @brief Something has been dropped onto the timeline */
287 virtual void dropEvent(QDropEvent * event);
288 virtual void wheelEvent(QWheelEvent * e);
289 virtual void keyPressEvent(QKeyEvent * event);
290 virtual QStringList mimeTypes() const;
291 virtual Qt::DropActions supportedDropActions() const;
296 int m_projectDuration;
298 KdenliveDoc *m_document;
299 CustomTrackScene *m_scene;
300 QGraphicsLineItem *m_cursorLine;
301 ItemInfo m_dragItemInfo;
302 ItemInfo m_selectionGroupInfo;
303 OPERATIONTYPE m_operationMode;
304 OPERATIONTYPE m_moveOpMode;
305 AbstractClipItem *m_dragItem;
307 QUndoStack *m_commandStack;
308 QGraphicsItem *m_visualTip;
309 QGraphicsItemAnimation *m_animation;
310 QTimeLine *m_animationTimer;
315 QList <CommentedTime> m_searchPoints;
316 QList <Guide *> m_guides;
318 ClipItem *getClipItemAt(int pos, int track);
319 ClipItem *getClipItemAt(GenTime pos, int track);
320 ClipItem *getClipItemAtEnd(GenTime pos, int track);
321 ClipItem *getClipItemAtStart(GenTime pos, int track);
322 Transition *getTransitionItem(TransitionInfo info);
323 Transition *getTransitionItemAt(int pos, int track);
324 Transition *getTransitionItemAt(GenTime pos, int track);
325 Transition *getTransitionItemAtEnd(GenTime pos, int track);
326 Transition *getTransitionItemAtStart(GenTime pos, int track);
327 void checkScrolling();
328 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
330 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
331 QMenu *m_timelineContextMenu;
332 QMenu *m_timelineContextClipMenu;
333 QMenu *m_timelineContextTransitionMenu;
335 QAction *m_autoTransition;
336 QAction *m_pasteEffectsAction;
337 QAction *m_ungroupAction;
338 QAction *m_editGuide;
339 QAction *m_deleteGuide;
340 QActionGroup *m_clipTypeGroup;
341 QTimer m_scrollTimer;
342 QTimer m_thumbsTimer;
348 QCursor m_razorCursor;
349 QCursor m_spacerCursor;
350 /** list containing items currently copied in the timeline */
351 QList<AbstractClipItem *> m_copiedItems;
352 /** Used to get the point in timeline where a context menu was opened */
353 QPoint m_menuPosition;
355 AbstractGroupItem *m_selectionGroup;
356 QList <ClipItem *> m_waitingThumbs;
361 QWaitCondition m_producerNotReady;
362 KStatefulBrush m_activeTrackBrush;
364 /** stores the state of the control modifier during mouse press.
365 * Will then be used to identify whether we resize a group or only one item of it. */
366 bool m_controlModifier;
368 /** Get the index of the video track that is just below current track */
369 int getPreviousVideoTrack(int track);
370 void updatePositionEffects(ClipItem * item, ItemInfo info, bool standalone = true);
371 bool insertDropClips(const QMimeData *data, const QPoint &pos);
372 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
373 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
374 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
375 ClipItem *getClipUnderCursor() const;
376 AbstractClipItem *getMainActiveClip() const;
377 void resetSelectionGroup(bool selectItems = true);
378 void groupSelectedItems(bool force = false, bool createNewGroup = false);
379 /** Get available space for clip move (min and max free positions) */
380 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
381 /** Get available space for transition move (min and max free positions) */
382 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
383 void updateClipTypeActions(ClipItem *clip);
384 /** Whether an item can be moved to a new position without colliding with similar items */
385 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
386 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
387 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
388 /** Adjust clips under another one when working in overwrite mode */
389 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
390 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
391 /** Adjust keyframes when pasted to another clip */
392 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
394 /** @brief Removes the tip and stops the animation timer. */
395 void removeTipAnimation();
396 /** @brief Creates a new tip animation.
397 * @param clip clip to display the tip on
398 * @param mode operation mode for which the tip should be displayed
399 * @param size size of the tip */
400 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
402 /** @brief Takes care of updating effects and attached transitions during a resize from start.
403 * @param item Item to resize
404 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
405 * @param pos New startPos
406 * @param check (optional, default = false) Whether to check for collisions
407 * @param command (optional) Will be used as parent command (for undo history) */
408 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
410 /** @brief Takes care of updating effects and attached transitions during a resize from end.
411 * @param item Item to resize
412 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
413 * @param pos New endPos
414 * @param check (optional, default = false) Whether to check for collisions
415 * @param command (optional) Will be used as parent command (for undo history) */
416 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
418 /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
419 * @param group The group to cut
420 * @param cutPos The absolute position of the cut */
421 void razorGroup(AbstractGroupItem *group, GenTime cutPos);
423 /** @brief Gets the effect parameters that will be passed to Mlt. */
424 EffectsParameterList getEffectArgs(const QDomElement &effect);
426 /** @brief Update Tracknames to fit again after track was added/deleted.
427 * @param track Number of track which was added/deleted
428 * @param added true = track added, false = track deleted
430 * The default track name consists of type + number. If we add/delete a track the number has to be adjusted
431 * if the name is still the default one. */
432 void updateTrackNames(int track, bool added);
434 /** @brief Updates the duration stored in a track's TrackInfo.
435 * @param track Number of track as used in ItemInfo (not the numbering used in KdenliveDoc) (negative for all tracks)
436 * @param command If effects need to be updated the commands to do this will be attached to this undo command
438 * In addition to update the duration in TrackInfo it updates effects with keyframes on the track. */
439 void updateTrackDuration(int track, QUndoCommand *command);
441 /** @brief Adjusts effects after a clip resize.
442 * @param item The item that was resized
443 * @param oldInfo pre resize info
444 * @param fromStart false = resize from end
445 * @param command Used as a parent for EditEffectCommand */
446 void adjustEffects(ClipItem *item, ItemInfo oldInfo, QUndoCommand *command);
448 /** @brief Prepare an add clip command for an effect */
449 void processEffect(ClipItem *item, QDomElement effect, QUndoCommand *effectCommand);
451 /** @brief Get effect parameters ready for MLT*/
452 void adjustEffectParameters(EffectsParameterList ¶meters, QDomNodeList params, const QString &prefix = QString());
455 void slotRefreshGuides();
456 void slotEnableRefresh();
457 void slotCheckMouseScrolling();
458 void slotEditTimeLineGuide();
459 void slotDeleteTimeLineGuide();
460 void slotFetchNextThumbs();
461 void checkTrackSequence(int track);
462 void slotGoToMarker(QAction *action);
463 void slotResetMenuPosition();
464 void slotDoResetMenuPosition();
465 /** @brief Re-create the clip thumbnails.
466 * @param id The clip's Id string.
467 * @param resetThumbs Should we recreate the timeline thumbnails. */
468 void slotRefreshThumbs(const QString &id, bool resetThumbs);
469 /** @brief A Filter job producer results. */
470 void slotGotFilterJobResults(const QString &id, int startPos, int track, const QString &filter, stringMap filterParams);
474 void cursorMoved(int, int);
477 void mousePosition(int);
478 /** @brief A clip was selected in timeline, update the effect stack
479 * @param clip The clip
480 * @param raise If true, the effect stack widget will be raised (come to front). */
481 void clipItemSelected(ClipItem *clip, bool raise = true);
482 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
483 void activateDocumentMonitor();
484 void trackHeightChanged();
485 void tracksChanged();
486 void displayMessage(const QString &, MessageType);
487 void showClipFrame(DocClipBase *, QPoint, bool, const int);
488 void doTrackLock(int, bool);
489 void updateClipMarkers(DocClipBase *);
490 void updateTrackHeaders();
492 /** @brief Monitor document changes (for example the presence of audio data in timeline for export widget.*/
493 void documentModified();
494 void forceClipProcessing(const QString &);
495 void showTrackEffects(int, TrackInfo);
496 /** @brief Update the track effect button that shows if a track has effects or not.*/
497 void updateTrackEffectState(int);