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 <KPixmapCache>
26 #include <QGraphicsView>
27 #include <QGraphicsItemAnimation>
32 #include <QWaitCondition>
34 #include "kdenlivedoc.h"
35 #include "docclipbase.h"
37 #include "effectslist.h"
38 #include "customtrackscene.h"
41 class AbstractClipItem;
42 class AbstractGroupItem;
45 class CustomTrackView : public QGraphicsView
50 CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent = 0);
51 virtual ~ CustomTrackView();
52 virtual void mousePressEvent(QMouseEvent * event);
53 virtual void mouseReleaseEvent(QMouseEvent * event);
54 virtual void mouseMoveEvent(QMouseEvent * event);
55 virtual void mouseDoubleClickEvent(QMouseEvent *event);
56 void addTrack(TrackInfo type, int ix = -1);
57 void removeTrack(int ix);
58 /** @brief Makes the document use new track infos (name, type, ...). */
59 void configTracks(QList <TrackInfo> trackInfos);
61 void checkAutoScroll();
62 void moveClip(const ItemInfo start, const ItemInfo end, bool refresh);
63 void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove = false);
64 /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
65 void moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh);
66 void resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry = false);
67 void addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList list = EffectsList(), bool overwrite = false, bool push = false, bool refresh = true);
68 void deleteClip(ItemInfo info, bool refresh = true);
69 void slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position);
70 void slotDeleteAllClipMarkers(const QString &id);
71 void addMarker(const QString &id, const GenTime &pos, const QString comment);
72 void setScale(double scaleFactor, double verticalScale);
73 void deleteClip(const QString &clipId);
74 void slotAddEffect(QDomElement effect, GenTime pos, int track);
75 void slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group);
76 void addEffect(int track, GenTime pos, QDomElement effect);
77 void deleteEffect(int track, GenTime pos, QDomElement effect);
78 void updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser = true);
79 void moveEffect(int track, GenTime pos, int oldPos, int newPos);
80 void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
81 void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
82 void updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget);
83 void moveTransition(GenTime oldpos, GenTime newpos);
84 void activateMonitor();
86 void deleteSelectedClips();
87 /** @brief Cuts all clips that are selected at the timeline cursor position. */
88 void cutSelectedClips();
89 void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
90 void checkTrackHeight();
91 //QList <TrackInfo> tracksList() const;
92 void setTool(PROJECTTOOL tool);
93 ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
94 void slotSeekToPreviousSnap();
95 void slotSeekToNextSnap();
96 double getSnapPointForPos(double pos);
97 void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
98 bool findString(const QString &text);
99 void selectFound(QString track, QString pos);
100 bool findNextString(const QString &text);
101 void initSearchStrings();
102 void clearSearchStrings();
103 QList<ItemInfo> findId(const QString &clipId);
106 void changeClipSpeed();
107 void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
108 /** @brief Sets the document as modified. */
109 void setDocumentModified();
113 /** @brief Prepares inserting space.
115 * Shows a dialog to configure length and track. */
116 void slotInsertSpace();
117 /** @brief Prepares removing space. */
118 void slotRemoveSpace();
119 void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset);
120 ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
121 void deleteTimelineTrack(int ix, TrackInfo trackinfo);
122 void saveThumbnails();
123 void autoTransition();
124 QStringList getLadspaParams(QDomElement effect) const;
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, 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;
158 /** @brief Selects a clip.
159 * @param add Whether to select or deselect
160 * @param group (optional) Whether to add the clip to a group
161 * @param track (optional) The track of the clip (has to be combined with @param pos)
162 * @param pos (optional) The position of the clip (has to be combined with @param track) */
163 void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
164 void selectTransition(bool add, bool group = false);
165 QStringList extractTransitionsLumas();
166 void setEditMode(EDITMODE mode);
168 /** @brief Inserts @param clip.
169 * @param clip The clip to insert
170 * @param in The inpoint of the clip (crop from start)
171 * @param out The outpoint of the clip (crop from end)
173 * Inserts at the position of timeline cursor and selected track. */
174 void insertClipCut(DocClipBase *clip, int in, int out);
175 void clearSelection();
176 void editItemDuration();
177 void buildGuidesMenu(QMenu *goMenu) const;
178 KPixmapCache* pixmapCache;
179 /** update the timeline objects when palette changes */
180 void updatePalette();
181 /** @brief Returns true if a track has audio data on it.
182 * @param track The track number
184 * Check whether given track has a clip with audio in it. */
185 bool hasAudio(int track) const;
188 void setCursorPos(int pos, bool seek = true);
189 void moveCursorPos(int delta);
190 void updateCursorPos();
191 void slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup = true);
192 void slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable);
193 void slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos);
194 void slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix);
195 void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
196 void slotRefreshEffects(ClipItem *clip);
197 void setDuration(int duration);
198 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
199 void slotAddTransitionToSelectedClips(QDomElement transition);
200 void slotTransitionUpdated(Transition *, QDomElement);
201 void slotSwitchTrackAudio(int ix);
202 void slotSwitchTrackVideo(int ix);
203 void slotSwitchTrackLock(int ix);
204 void slotUpdateClip(const QString &clipId, bool reload = true);
205 void slotAddClipMarker(const QString &id, GenTime t, QString c);
206 bool addGuide(const GenTime pos, const QString &comment);
208 void slotEditGuide(CommentedTime guide);
209 void slotEditGuide(int guidePos = -1);
210 void slotDeleteGuide(int guidePos = -1);
211 void slotDeleteAllGuides();
212 void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
215 void pasteClipEffects();
216 void slotUpdateAllThumbs();
217 void slotCheckPositionScrolling();
218 void slotInsertTrack(int ix);
220 /** @brief Shows a dialog for selecting a track to delete.
221 * @param ix Number of the track, which should be pre-selected in the dialog */
222 void slotDeleteTrack(int ix);
223 /** @brief Shows the configure tracks dialog. */
224 void slotConfigTracks(int ix);
225 void clipNameChanged(const QString id, const QString name);
227 void slotTrackDown();
228 void slotSelectTrack(int ix);
229 void insertZoneOverwrite(QStringList data, int in);
231 /** @brief Rebuilds a group to fit again after children changed.
232 * @param childTrack the track of one of the groups children
233 * @param childPos The position of the same child */
234 void rebuildGroup(int childTrack, GenTime childPos);
235 /** @brief Rebuilds a group to fit again after children changed.
236 * @param group The group to rebuild */
237 void rebuildGroup(AbstractGroupItem *group);
239 /** @brief Cuts a group into two parts.
240 * @param clips1 Clips before the cut
241 * @param transitions1 Transitions before the cut
242 * @param clipsCut Clips that need to be cut
243 * @param transitionsCut Transitions that need to be cut
244 * @param clips2 Clips behind the cut
245 * @param transitions2 Transitions behind the cut
246 * @param cutPos Absolute position of the cut
247 * @param cut true = cut, false = "uncut" */
248 void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
250 /** @brief Add en effect to a track.
251 * @param effect The new effect xml
252 * @param ix The track index */
253 void slotAddTrackEffect(const QDomElement effect, int ix);
256 virtual void drawBackground(QPainter * painter, const QRectF & rect);
257 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
258 virtual void dragEnterEvent(QDragEnterEvent * event);
259 virtual void dragMoveEvent(QDragMoveEvent * event);
260 virtual void dragLeaveEvent(QDragLeaveEvent * event);
261 /** @brief Something has been dropped onto the timeline */
262 virtual void dropEvent(QDropEvent * event);
263 virtual void wheelEvent(QWheelEvent * e);
264 virtual void keyPressEvent(QKeyEvent * event);
265 virtual QStringList mimeTypes() const;
266 virtual Qt::DropActions supportedDropActions() const;
270 int m_projectDuration;
272 KdenliveDoc *m_document;
273 CustomTrackScene *m_scene;
274 QGraphicsLineItem *m_cursorLine;
275 ItemInfo m_dragItemInfo;
276 ItemInfo m_selectionGroupInfo;
277 OPERATIONTYPE m_operationMode;
278 OPERATIONTYPE m_moveOpMode;
279 AbstractClipItem *m_dragItem;
281 QUndoStack *m_commandStack;
282 QGraphicsItem *m_visualTip;
283 QGraphicsItemAnimation *m_animation;
284 QTimeLine *m_animationTimer;
289 QList <CommentedTime> m_searchPoints;
290 QList <Guide *> m_guides;
291 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
292 ClipItem *getClipItemAt(int pos, int track);
293 ClipItem *getClipItemAt(GenTime pos, int track);
294 ClipItem *getClipItemAtEnd(GenTime pos, int track);
295 ClipItem *getClipItemAtStart(GenTime pos, int track);
296 Transition *getTransitionItemAt(int pos, int track);
297 Transition *getTransitionItemAt(GenTime pos, int track);
298 Transition *getTransitionItemAtEnd(GenTime pos, int track);
299 Transition *getTransitionItemAtStart(GenTime pos, int track);
300 void checkScrolling();
301 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
303 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
304 QMenu *m_timelineContextMenu;
305 QMenu *m_timelineContextClipMenu;
306 QMenu *m_timelineContextTransitionMenu;
308 QAction *m_autoTransition;
309 QAction *m_pasteEffectsAction;
310 QAction *m_ungroupAction;
311 QAction *m_editGuide;
312 QAction *m_deleteGuide;
313 QActionGroup *m_clipTypeGroup;
314 QTimer m_scrollTimer;
315 QTimer m_thumbsTimer;
321 QCursor m_razorCursor;
322 QCursor m_spacerCursor;
323 /** list containing items currently copied in the timeline */
324 QList<AbstractClipItem *> m_copiedItems;
325 /** Used to get the point in timeline where a context menu was opened */
326 QPoint m_menuPosition;
328 AbstractGroupItem *m_selectionGroup;
329 QList <ClipItem *> m_waitingThumbs;
334 QWaitCondition m_producerNotReady;
336 /** Get the index of the video track that is just below current track */
337 int getPreviousVideoTrack(int track);
338 void updatePositionEffects(ClipItem * item, ItemInfo info);
339 bool insertDropClips(const QMimeData *data, const QPoint pos);
340 bool canBePastedTo(ItemInfo info, int type) const;
341 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
342 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
343 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
344 ClipItem *getClipUnderCursor() const;
345 AbstractClipItem *getMainActiveClip() const;
346 void resetSelectionGroup(bool selectItems = true);
347 void groupSelectedItems(bool force = false, bool createNewGroup = false);
348 /** Get available space for clip move (min and max free positions) */
349 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
350 /** Get available space for transition move (min and max free positions) */
351 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
352 void updateClipTypeActions(ClipItem *clip);
353 /** Whether an item can be moved to a new position without colliding with similar items */
354 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
355 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
356 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
357 /** Adjust clips under another one when working in overwrite mode */
358 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
359 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
360 /** Adjust keyframes when pasted to another clip */
361 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
363 /** @brief Removes the tip and stops the animation timer. */
364 void removeTipAnimation();
365 /** @brief Creates a new tip animation.
366 * @param clip clip to display the tip on
367 * @param mode operation mode for which the tip should be displayed
368 * @param size size of the tip */
369 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
371 /** @brief Takes care of updating effects and attached transitions during a resize from start.
372 * @param item Item to resize
373 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
374 * @param pos New startPos
375 * @param check (optional, default = false) Whether to check for collisions
376 * @param command (optional) Will be used as parent command (for undo history) */
377 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
379 /** @brief Takes care of updating effects and attached transitions during a resize from end.
380 * @param item Item to resize
381 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
382 * @param pos New endPos
383 * @param check (optional, default = false) Whether to check for collisions
384 * @param command (optional) Will be used as parent command (for undo history) */
385 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
387 /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
388 * @param group The group to cut
389 * @param cutPos The absolute position of the cut */
390 void razorGroup(AbstractGroupItem *group, GenTime cutPos);
392 /** @brief Gets the effect parameters that will be passed to Mlt. */
393 EffectsParameterList getEffectArgs(const QDomElement effect);
396 void slotRefreshGuides();
397 void slotEnableRefresh();
398 void slotCheckMouseScrolling();
399 void slotEditTimeLineGuide();
400 void slotDeleteTimeLineGuide();
401 void slotFetchNextThumbs();
402 void checkTrackSequence(int track);
403 void slotGoToMarker(QAction *action);
404 void slotResetMenuPosition();
405 void slotDoResetMenuPosition();
408 void cursorMoved(int, int);
411 void mousePosition(int);
412 void clipItemSelected(ClipItem*, int ix = -1);
413 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
414 void activateDocumentMonitor();
415 void trackHeightChanged();
416 void tracksChanged();
417 void displayMessage(const QString, MessageType);
418 void showClipFrame(DocClipBase *, QPoint, const int);
419 void doTrackLock(int, bool);
420 void updateClipMarkers(DocClipBase *);
421 void updateTrackHeaders();
423 /** @brief Monitor document changes (for example the presence of audio data in timeline for export widget.*/
424 void documentModified();
425 void forceClipProcessing(const QString &);
426 void showTrackEffects(int, TrackInfo);
427 /** @brief Update the track effect button that shows if a track has effects or not.*/
428 void updateTrackEffectState(int);