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