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 "kdenlivedoc.h"
33 #include "docclipbase.h"
35 #include "effectslist.h"
36 #include "customtrackscene.h"
39 class AbstractClipItem;
40 class AbstractGroupItem;
43 class CustomTrackView : public QGraphicsView
48 CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent = 0);
49 virtual ~ CustomTrackView();
50 virtual void mousePressEvent(QMouseEvent * event);
51 virtual void mouseReleaseEvent(QMouseEvent * event);
52 virtual void mouseMoveEvent(QMouseEvent * event);
53 virtual void mouseDoubleClickEvent(QMouseEvent *event);
54 void addTrack(TrackInfo type, int ix = -1);
55 void removeTrack(int ix);
56 /** @brief Makes the document use new track infos (name, type, ...). */
57 void configTracks(QList <TrackInfo> trackInfos);
59 void checkAutoScroll();
60 void moveClip(const ItemInfo start, const ItemInfo end, bool refresh);
61 void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove = false);
62 /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
63 void moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh);
64 void resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry = false);
65 void addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList list = EffectsList(), bool overwrite = false, bool push = false, bool refresh = true);
66 void deleteClip(ItemInfo info, bool refresh = true);
67 void slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position);
68 void slotDeleteAllClipMarkers(const QString &id);
69 void addMarker(const QString &id, const GenTime &pos, const QString comment);
70 void setScale(double scaleFactor, double verticalScale);
71 void deleteClip(const QString &clipId);
72 void slotAddEffect(QDomElement effect, GenTime pos, int track);
73 void slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group);
74 void addEffect(int track, GenTime pos, QDomElement effect);
75 void deleteEffect(int track, GenTime pos, QDomElement effect);
76 void updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser = true);
77 void moveEffect(int track, GenTime pos, int oldPos, int newPos);
78 void addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
79 void deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh);
80 void updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget);
81 void moveTransition(GenTime oldpos, GenTime newpos);
82 void activateMonitor();
84 void deleteSelectedClips();
85 void cutSelectedClips();
86 void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
87 void checkTrackHeight();
88 //QList <TrackInfo> tracksList() const;
89 void setTool(PROJECTTOOL tool);
90 ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
91 void slotSeekToPreviousSnap();
92 void slotSeekToNextSnap();
93 double getSnapPointForPos(double pos);
94 void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
95 bool findString(const QString &text);
96 void selectFound(QString track, QString pos);
97 bool findNextString(const QString &text);
98 void initSearchStrings();
99 void clearSearchStrings();
100 QList<ItemInfo> findId(const QString &clipId);
103 void changeClipSpeed();
104 void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
105 /** @brief Sets the document as modified. */
106 void setDocumentModified();
110 /** @brief Prepares inserting space.
112 * Shows a dialog to configure length and track. */
113 void slotInsertSpace();
114 /** @brief Prepares removing space. */
115 void slotRemoveSpace();
116 void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset);
117 ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
118 void deleteTimelineTrack(int ix, TrackInfo trackinfo);
119 void saveThumbnails();
120 void autoTransition();
121 QStringList getLadspaParams(QDomElement effect) const;
122 void initCursorPos(int pos);
124 /** @brief Locks or unlocks a track.
125 * @param ix number of track
126 * @param lock whether to lock or unlock
128 * Makes sure no clip on track to lock is selected. */
129 void lockTrack(int ix, bool lock);
130 void groupClips(bool group = true);
131 void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
132 void loadGroups(const QDomNodeList groups);
134 /** @brief Creates SplitAudioCommands for selected clips. */
137 /** @brief Seperates the audio of a clip to a audio track.
138 * @param pos Position of the clip to split
139 * @param track Track of the clip
140 * @param split Split or unsplit */
141 void doSplitAudio(const GenTime &pos, int track, bool split);
144 void setAudioAndVideo();
145 void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
146 int hasGuide(int pos, int offset);
147 void reloadTransitionLumas();
148 void updateProjectFps();
150 int selectedTrack() const;
151 QStringList selectedClips() const;
152 QList<ClipItem *> selectedClipItems() const;
154 /** @brief Selects a clip.
155 * @param add Whether to select or deselect
156 * @param group (optional) Whether to add the clip to a group
157 * @param track (optional) The track of the clip (has to be combined with @param pos)
158 * @param pos (optional) The position of the clip (has to be combined with @param track) */
159 void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
160 void selectTransition(bool add, bool group = false);
161 QStringList extractTransitionsLumas();
162 void setEditMode(EDITMODE mode);
164 /** @brief Inserts @param clip.
165 * @param clip The clip to insert
166 * @param in The inpoint of the clip (crop from start)
167 * @param out The outpoint of the clip (crop from end)
169 * Inserts at the position of timeline cursor and selected track. */
170 void insertClipCut(DocClipBase *clip, int in, int out);
171 void clearSelection();
172 void editItemDuration();
173 void buildGuidesMenu(QMenu *goMenu) const;
174 KPixmapCache* pixmapCache;
175 /** update the timeline objects when palette changes */
176 void updatePalette();
179 void setCursorPos(int pos, bool seek = true);
180 void moveCursorPos(int delta);
181 void updateCursorPos();
182 void slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup = true);
183 void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
184 void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
185 void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
186 void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
187 void slotRefreshEffects(ClipItem *clip);
188 void setDuration(int duration);
189 void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
190 void slotAddTransitionToSelectedClips(QDomElement transition);
191 void slotTransitionUpdated(Transition *, QDomElement);
192 void slotSwitchTrackAudio(int ix);
193 void slotSwitchTrackVideo(int ix);
194 void slotSwitchTrackLock(int ix);
195 void slotUpdateClip(const QString &clipId, bool reload = true);
196 void slotAddClipMarker(const QString &id, GenTime t, QString c);
197 bool addGuide(const GenTime pos, const QString &comment);
199 void slotEditGuide(CommentedTime guide);
200 void slotEditGuide(int guidePos = -1);
201 void slotDeleteGuide(int guidePos = -1);
202 void slotDeleteAllGuides();
203 void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
206 void pasteClipEffects();
207 void slotUpdateAllThumbs();
208 void slotCheckPositionScrolling();
209 void slotInsertTrack(int ix);
211 /** @brief Shows a dialog for selecting a track to delete.
212 * @param ix Number of the track, which should be pre-selected in the dialog */
213 void slotDeleteTrack(int ix);
214 /** @brief Shows the configure tracks dialog. */
215 void slotConfigTracks(int ix);
216 void clipNameChanged(const QString id, const QString name);
218 void slotTrackDown();
219 void slotSelectTrack(int ix);
220 void insertZoneOverwrite(QStringList data, int in);
222 /** @brief Rebuilds a group to fit again after children changed.
223 * @param childTrack the track of one of the groups children
224 * @param childPos The position of the same child */
225 void rebuildGroup(int childTrack, GenTime childPos);
226 /** @brief Rebuilds a group to fit again after children changed.
227 * @param group The group to rebuild */
228 void rebuildGroup(AbstractGroupItem *group);
231 virtual void drawBackground(QPainter * painter, const QRectF & rect);
232 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
233 virtual void dragEnterEvent(QDragEnterEvent * event);
234 virtual void dragMoveEvent(QDragMoveEvent * event);
235 virtual void dragLeaveEvent(QDragLeaveEvent * event);
236 /** @brief Something has been dropped onto the timeline */
237 virtual void dropEvent(QDropEvent * event);
238 virtual void wheelEvent(QWheelEvent * e);
239 virtual void keyPressEvent(QKeyEvent * event);
240 virtual QStringList mimeTypes() const;
241 virtual Qt::DropActions supportedDropActions() const;
245 int m_projectDuration;
247 KdenliveDoc *m_document;
248 CustomTrackScene *m_scene;
249 QGraphicsLineItem *m_cursorLine;
250 ItemInfo m_dragItemInfo;
251 ItemInfo m_selectionGroupInfo;
252 OPERATIONTYPE m_operationMode;
253 OPERATIONTYPE m_moveOpMode;
254 AbstractClipItem *m_dragItem;
256 QUndoStack *m_commandStack;
257 QGraphicsItem *m_visualTip;
258 QGraphicsItemAnimation *m_animation;
259 QTimeLine *m_animationTimer;
264 QList <CommentedTime> m_searchPoints;
265 QList <Guide *> m_guides;
266 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
267 ClipItem *getClipItemAt(int pos, int track);
268 ClipItem *getClipItemAt(GenTime pos, int track);
269 ClipItem *getClipItemAtEnd(GenTime pos, int track);
270 ClipItem *getClipItemAtStart(GenTime pos, int track);
271 Transition *getTransitionItemAt(int pos, int track);
272 Transition *getTransitionItemAt(GenTime pos, int track);
273 Transition *getTransitionItemAtEnd(GenTime pos, int track);
274 Transition *getTransitionItemAtStart(GenTime pos, int track);
275 void checkScrolling();
276 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
278 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
279 QMenu *m_timelineContextMenu;
280 QMenu *m_timelineContextClipMenu;
281 QMenu *m_timelineContextTransitionMenu;
283 QAction *m_autoTransition;
284 QAction *m_pasteEffectsAction;
285 QAction *m_ungroupAction;
286 QAction *m_editGuide;
287 QAction *m_deleteGuide;
288 QActionGroup *m_clipTypeGroup;
289 QTimer m_scrollTimer;
290 QTimer m_thumbsTimer;
296 QCursor m_razorCursor;
297 QCursor m_spacerCursor;
298 /** list containing items currently copied in the timeline */
299 QList<AbstractClipItem *> m_copiedItems;
300 /** Used to get the point in timeline where a context menu was opened */
301 QPoint m_menuPosition;
303 AbstractGroupItem *m_selectionGroup;
304 QList <ClipItem *> m_waitingThumbs;
308 /** Get the index of the video track that is just below current track */
309 int getPreviousVideoTrack(int track);
310 void updatePositionEffects(ClipItem * item, ItemInfo info);
311 bool insertDropClips(const QMimeData *data, const QPoint pos);
312 bool canBePastedTo(ItemInfo info, int type) const;
313 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
314 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
315 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
316 ClipItem *getClipUnderCursor() const;
317 AbstractClipItem *getMainActiveClip() const;
318 void resetSelectionGroup(bool selectItems = true);
319 void groupSelectedItems(bool force = false, bool createNewGroup = false);
320 /** Get available space for clip move (min and max free positions) */
321 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
322 /** Get available space for transition move (min and max free positions) */
323 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
324 void updateClipTypeActions(ClipItem *clip);
325 /** Whether an item can be moved to a new position without colliding with similar items */
326 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
327 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
328 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
329 /** Adjust clips under another one when working in overwrite mode */
330 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
331 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
332 /** Adjust keyframes when pasted to another clip */
333 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
335 /** @brief Removes the tip and stops the animation timer. */
336 void removeTipAnimation();
337 /** @brief Creates a new tip animation.
338 * @param clip clip to display the tip on
339 * @param mode operation mode for which the tip should be displayed
340 * @param size size of the tip */
341 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
343 /** @brief Takes care of updating effects and attached transitions during a resize from start.
344 * @param item Item to resize
345 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
346 * @param pos New startPos
347 * @param check (optional, default = false) Whether to check for collisions
348 * @param command (optional) Will be used as parent command (for undo history) */
349 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
351 /** @brief Takes care of updating effects and attached transitions during a resize from end.
352 * @param item Item to resize
353 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
354 * @param pos New endPos
355 * @param check (optional, default = false) Whether to check for collisions
356 * @param command (optional) Will be used as parent command (for undo history) */
357 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
360 void slotRefreshGuides();
361 void slotEnableRefresh();
362 void slotCheckMouseScrolling();
363 void slotEditTimeLineGuide();
364 void slotDeleteTimeLineGuide();
365 void slotFetchNextThumbs();
366 void checkTrackSequence(int track);
367 void slotGoToMarker(QAction *action);
368 void slotResetMenuPosition();
369 void slotDoResetMenuPosition();
372 void cursorMoved(int, int);
375 void mousePosition(int);
376 void clipItemSelected(ClipItem*, int ix = -1);
377 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
378 void activateDocumentMonitor();
379 void trackHeightChanged();
380 void tracksChanged();
381 void displayMessage(const QString, MessageType);
382 void showClipFrame(DocClipBase *, QPoint, const int);
383 void doTrackLock(int, bool);
384 void updateClipMarkers(DocClipBase *);
385 void updateTrackHeaders();