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