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