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