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);
223 virtual void drawBackground(QPainter * painter, const QRectF & rect);
224 //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
225 virtual void dragEnterEvent(QDragEnterEvent * event);
226 virtual void dragMoveEvent(QDragMoveEvent * event);
227 virtual void dragLeaveEvent(QDragLeaveEvent * event);
228 virtual void dropEvent(QDropEvent * event);
229 virtual void wheelEvent(QWheelEvent * e);
230 virtual void keyPressEvent(QKeyEvent * event);
231 virtual QStringList mimeTypes() const;
232 virtual Qt::DropActions supportedDropActions() const;
236 int m_projectDuration;
238 KdenliveDoc *m_document;
239 CustomTrackScene *m_scene;
240 QGraphicsLineItem *m_cursorLine;
241 ItemInfo m_dragItemInfo;
242 ItemInfo m_selectionGroupInfo;
243 OPERATIONTYPE m_operationMode;
244 OPERATIONTYPE m_moveOpMode;
245 AbstractClipItem *m_dragItem;
247 QUndoStack *m_commandStack;
248 QGraphicsItem *m_visualTip;
249 QGraphicsItemAnimation *m_animation;
250 QTimeLine *m_animationTimer;
255 QList <CommentedTime> m_searchPoints;
256 QList <Guide *> m_guides;
257 void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
258 ClipItem *getClipItemAt(int pos, int track);
259 ClipItem *getClipItemAt(GenTime pos, int track);
260 ClipItem *getClipItemAtEnd(GenTime pos, int track);
261 ClipItem *getClipItemAtStart(GenTime pos, int track);
262 Transition *getTransitionItemAt(int pos, int track);
263 Transition *getTransitionItemAt(GenTime pos, int track);
264 Transition *getTransitionItemAtEnd(GenTime pos, int track);
265 Transition *getTransitionItemAtStart(GenTime pos, int track);
266 void checkScrolling();
267 /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
269 void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
270 QMenu *m_timelineContextMenu;
271 QMenu *m_timelineContextClipMenu;
272 QMenu *m_timelineContextTransitionMenu;
274 QAction *m_autoTransition;
275 QAction *m_pasteEffectsAction;
276 QAction *m_ungroupAction;
277 QAction *m_editGuide;
278 QAction *m_deleteGuide;
279 QActionGroup *m_clipTypeGroup;
280 QTimer m_scrollTimer;
281 QTimer m_thumbsTimer;
287 QCursor m_razorCursor;
288 QCursor m_spacerCursor;
289 /** list containing items currently copied in the timeline */
290 QList<AbstractClipItem *> m_copiedItems;
291 /** Used to get the point in timeline where a context menu was opened */
292 QPoint m_menuPosition;
294 AbstractGroupItem *m_selectionGroup;
295 QList <ClipItem *> m_waitingThumbs;
299 /** Get the index of the video track that is just below current track */
300 int getPreviousVideoTrack(int track);
301 void updatePositionEffects(ClipItem * item, ItemInfo info);
302 bool insertDropClips(const QMimeData *data, const QPoint pos);
303 bool canBePastedTo(ItemInfo info, int type) const;
304 bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
305 bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
306 bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
307 ClipItem *getClipUnderCursor() const;
308 AbstractClipItem *getMainActiveClip() const;
309 /** @brief Rebuilds @param group to fit changes to it's childen. */
310 void rebuildGroup(AbstractGroupItem *group);
311 void resetSelectionGroup(bool selectItems = true);
312 void groupSelectedItems(bool force = false, bool createNewGroup = false);
313 /** Get available space for clip move (min and max free positions) */
314 void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
315 /** Get available space for transition move (min and max free positions) */
316 void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
317 void updateClipTypeActions(ClipItem *clip);
318 /** Whether an item can be moved to a new position without colliding with similar items */
319 bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
320 /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
321 QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
322 /** Adjust clips under another one when working in overwrite mode */
323 void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
324 void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
325 /** Adjust keyframes when pasted to another clip */
326 void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
328 /** @brief Removes the tip and stops the animation timer. */
329 void removeTipAnimation();
330 /** @brief Creates a new tip animation.
331 * @param clip clip to display the tip on
332 * @param mode operation mode for which the tip should be displayed
333 * @param size size of the tip */
334 void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
336 /** @brief Takes care of updating effects and attached transitions during a resize from start.
337 * @param item Item to resize
338 * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
339 * @param pos New startPos
340 * @param check (optional, default = false) Whether to check for collisions */
341 void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false);
343 /** @brief Takes care of updating effects and attached transitions during a resize from end.
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 endPos
347 * @param check (optional, default = false) Whether to check for collisions */
348 void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false);
351 void slotRefreshGuides();
352 void slotEnableRefresh();
353 void slotCheckMouseScrolling();
354 void slotEditTimeLineGuide();
355 void slotDeleteTimeLineGuide();
356 void slotFetchNextThumbs();
357 void checkTrackSequence(int track);
358 void slotGoToMarker(QAction *action);
359 void slotResetMenuPosition();
360 void slotDoResetMenuPosition();
363 void cursorMoved(int, int);
366 void mousePosition(int);
367 void clipItemSelected(ClipItem*, int ix = -1);
368 void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
369 void activateDocumentMonitor();
370 void trackHeightChanged();
371 void tracksChanged();
372 void displayMessage(const QString, MessageType);
373 void showClipFrame(DocClipBase *, QPoint, const int);
374 void doTrackLock(int, bool);
375 void updateClipMarkers(DocClipBase *);
376 void updateTrackHeaders();