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
131 * Makes sure no clip on track to lock is selected. */
132 void lockTrack(int ix, bool lock);
133 void groupClips(bool group = true);
134 void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
135 void loadGroups(const QDomNodeList groups);
137 /** @brief Creates SplitAudioCommands for selected clips. */
140 /** @brief Seperates the audio of a clip to a audio track.
141 * @param pos Position of the clip to split
142 * @param track Track of the clip
143 * @param split Split or unsplit */
144 void doSplitAudio(const GenTime &pos, int track, bool split);
147 void setAudioAndVideo();
148 void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
149 int hasGuide(int pos, int offset);
150 void reloadTransitionLumas();
151 void updateProjectFps();
153 int selectedTrack() const;
154 QStringList selectedClips() const;
155 QList<ClipItem *> selectedClipItems() const;
157 /** @brief Selects a clip.
158 * @param add Whether to select or deselect
159 * @param group (optional) Whether to add the clip to a group
160 * @param track (optional) The track of the clip (has to be combined with @param pos)
161 * @param pos (optional) The position of the clip (has to be combined with @param track) */
162 void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
163 void selectTransition(bool add, bool group = false);
164 QStringList extractTransitionsLumas();
165 void setEditMode(EDITMODE mode);
167 /** @brief Inserts @param clip.
168 * @param clip The clip to insert
169 * @param in The inpoint of the clip (crop from start)
170 * @param out The outpoint of the clip (crop from end)
172 * Inserts at the position of timeline cursor and selected track. */
173 void insertClipCut(DocClipBase *clip, int in, int out);
174 void clearSelection();
175 void editItemDuration();
176 void buildGuidesMenu(QMenu *goMenu) const;
177 KPixmapCache* pixmapCache;
178 /** update the timeline objects when palette changes */
179 void updatePalette();
180 /** @brief Returns true if a track has audio data on it.
181 * @param track The track number
183 * Check whether given track has a clip with audio in it. */
184 bool hasAudio(int track) const;
187 void setCursorPos(int pos, bool seek = true);
188 void moveCursorPos(int delta);
189 void updateCursorPos();
190 void slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup = true);
191 void slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable);
192 void slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos);
193 void slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix);
194 void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
195 void slotRefreshEffects(ClipItem *clip);
196 void setDuration(int duration);
197 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
198 void slotAddTransitionToSelectedClips(QDomElement transition);
199 void slotTransitionUpdated(Transition *, QDomElement);
200 void slotSwitchTrackAudio(int ix);
201 void slotSwitchTrackVideo(int ix);
202 void slotSwitchTrackLock(int ix);
203 void slotUpdateClip(const QString &clipId, bool reload = true);
204 void slotAddClipMarker(const QString &id, GenTime t, QString c);
205 bool addGuide(const GenTime pos, const QString &comment);
207 void slotEditGuide(CommentedTime guide);
208 void slotEditGuide(int guidePos = -1);
209 void slotDeleteGuide(int guidePos = -1);
210 void slotDeleteAllGuides();
211 void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
214 void pasteClipEffects();
215 void slotUpdateAllThumbs();
216 void slotCheckPositionScrolling();
217 void slotInsertTrack(int ix);
219 /** @brief Shows a dialog for selecting a track to delete.
220 * @param ix Number of the track, which should be pre-selected in the dialog */
221 void slotDeleteTrack(int ix);
222 /** @brief Shows the configure tracks dialog. */
223 void slotConfigTracks(int ix);
224 void clipNameChanged(const QString id, const QString name);
226 void slotTrackDown();
227 void slotSelectTrack(int ix);
228 void insertZoneOverwrite(QStringList data, int in);
230 /** @brief Rebuilds a group to fit again after children changed.
231 * @param childTrack the track of one of the groups children
232 * @param childPos The position of the same child */
233 void rebuildGroup(int childTrack, GenTime childPos);
234 /** @brief Rebuilds a group to fit again after children changed.
235 * @param group The group to rebuild */
236 void rebuildGroup(AbstractGroupItem *group);
238 /** @brief Cuts a group into two parts.
239 * @param clips1 Clips before the cut
240 * @param transitions1 Transitions before the cut
241 * @param clipsCut Clips that need to be cut
242 * @param transitionsCut Transitions that need to be cut
243 * @param clips2 Clips behind the cut
244 * @param transitions2 Transitions behind the cut
245 * @param cutPos Absolute position of the cut
246 * @param cut true = cut, false = "uncut" */
247 void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
249 /** @brief Add en effect to a track.
250 * @param effect The new effect xml
251 * @param ix The track index */
252 void slotAddTrackEffect(const QDomElement effect, int ix);
255 virtual void drawBackground(QPainter * painter, const QRectF & rect);
256 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
257 virtual void dragEnterEvent(QDragEnterEvent * event);
258 virtual void dragMoveEvent(QDragMoveEvent * event);
259 virtual void dragLeaveEvent(QDragLeaveEvent * event);
260 /** @brief Something has been dropped onto the timeline */
261 virtual void dropEvent(QDropEvent * event);
262 virtual void wheelEvent(QWheelEvent * e);
263 virtual void keyPressEvent(QKeyEvent * event);
264 virtual QStringList mimeTypes() const;
265 virtual Qt::DropActions supportedDropActions() const;
269 int m_projectDuration;
271 KdenliveDoc *m_document;
272 CustomTrackScene *m_scene;
273 QGraphicsLineItem *m_cursorLine;
274 ItemInfo m_dragItemInfo;
275 ItemInfo m_selectionGroupInfo;
276 OPERATIONTYPE m_operationMode;
277 OPERATIONTYPE m_moveOpMode;
278 AbstractClipItem *m_dragItem;
280 QUndoStack *m_commandStack;
281 QGraphicsItem *m_visualTip;
282 QGraphicsItemAnimation *m_animation;
283 QTimeLine *m_animationTimer;
288 QList <CommentedTime> m_searchPoints;
289 QList <Guide *> m_guides;
290 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
291 ClipItem *getClipItemAt(int pos, int track);
292 ClipItem *getClipItemAt(GenTime pos, int track);
293 ClipItem *getClipItemAtEnd(GenTime pos, int track);
294 ClipItem *getClipItemAtStart(GenTime pos, int track);
295 Transition *getTransitionItemAt(int pos, int track);
296 Transition *getTransitionItemAt(GenTime pos, int track);
297 Transition *getTransitionItemAtEnd(GenTime pos, int track);
298 Transition *getTransitionItemAtStart(GenTime pos, int track);
299 void checkScrolling();
300 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
302 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
303 QMenu *m_timelineContextMenu;
304 QMenu *m_timelineContextClipMenu;
305 QMenu *m_timelineContextTransitionMenu;
307 QAction *m_autoTransition;
308 QAction *m_pasteEffectsAction;
309 QAction *m_ungroupAction;
310 QAction *m_editGuide;
311 QAction *m_deleteGuide;
312 QActionGroup *m_clipTypeGroup;
313 QTimer m_scrollTimer;
314 QTimer m_thumbsTimer;
320 QCursor m_razorCursor;
321 QCursor m_spacerCursor;
322 /** list containing items currently copied in the timeline */
323 QList<AbstractClipItem *> m_copiedItems;
324 /** Used to get the point in timeline where a context menu was opened */
325 QPoint m_menuPosition;
327 AbstractGroupItem *m_selectionGroup;
328 QList <ClipItem *> m_waitingThumbs;
333 QWaitCondition m_producerNotReady;
335 /** Get the index of the video track that is just below current track */
336 int getPreviousVideoTrack(int track);
337 void updatePositionEffects(ClipItem * item, ItemInfo info);
338 bool insertDropClips(const QMimeData *data, const QPoint pos);
339 bool canBePastedTo(ItemInfo info, int type) const;
340 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
341 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
342 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
343 ClipItem *getClipUnderCursor() const;
344 AbstractClipItem *getMainActiveClip() const;
345 void resetSelectionGroup(bool selectItems = true);
346 void groupSelectedItems(bool force = false, bool createNewGroup = false);
347 /** Get available space for clip move (min and max free positions) */
348 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
349 /** Get available space for transition move (min and max free positions) */
350 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
351 void updateClipTypeActions(ClipItem *clip);
352 /** Whether an item can be moved to a new position without colliding with similar items */
353 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
354 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
355 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
356 /** Adjust clips under another one when working in overwrite mode */
357 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
358 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
359 /** Adjust keyframes when pasted to another clip */
360 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
362 /** @brief Removes the tip and stops the animation timer. */
363 void removeTipAnimation();
364 /** @brief Creates a new tip animation.
365 * @param clip clip to display the tip on
366 * @param mode operation mode for which the tip should be displayed
367 * @param size size of the tip */
368 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
370 /** @brief Takes care of updating effects and attached transitions during a resize from start.
371 * @param item Item to resize
372 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
373 * @param pos New startPos
374 * @param check (optional, default = false) Whether to check for collisions
375 * @param command (optional) Will be used as parent command (for undo history) */
376 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
378 /** @brief Takes care of updating effects and attached transitions during a resize from end.
379 * @param item Item to resize
380 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
381 * @param pos New endPos
382 * @param check (optional, default = false) Whether to check for collisions
383 * @param command (optional) Will be used as parent command (for undo history) */
384 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
386 /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
387 * @param group The group to cut
388 * @param cutPos The absolute position of the cut */
389 void razorGroup(AbstractGroupItem *group, GenTime cutPos);
391 /** @brief Gets the effect parameters that will be passed to Mlt. */
392 EffectsParameterList getEffectArgs(const QDomElement effect);
395 void slotRefreshGuides();
396 void slotEnableRefresh();
397 void slotCheckMouseScrolling();
398 void slotEditTimeLineGuide();
399 void slotDeleteTimeLineGuide();
400 void slotFetchNextThumbs();
401 void checkTrackSequence(int track);
402 void slotGoToMarker(QAction *action);
403 void slotResetMenuPosition();
404 void slotDoResetMenuPosition();
407 void cursorMoved(int, int);
410 void mousePosition(int);
411 void clipItemSelected(ClipItem*, int ix = -1);
412 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
413 void activateDocumentMonitor();
414 void trackHeightChanged();
415 void tracksChanged();
416 void displayMessage(const QString, MessageType);
417 void showClipFrame(DocClipBase *, QPoint, const int);
418 void doTrackLock(int, bool);
419 void updateClipMarkers(DocClipBase *);
420 void updateTrackHeaders();
422 /** @brief Monitor document changes (for example the presence of audio data in timeline for export widget.*/
423 void documentModified();
424 void forceClipProcessing(const QString &);
425 void showTrackEffects(int, TrackInfo);