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