]> git.sesse.net Git - kdenlive/blob - src/customtrackview.h
Allow cutting groups
[kdenlive] / src / customtrackview.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef CUSTOMTRACKVIEW_H
22 #define CUSTOMTRACKVIEW_H
23
24 #include <KPixmapCache>
25
26 #include <QGraphicsView>
27 #include <QGraphicsItemAnimation>
28 #include <QTimeLine>
29 #include <QMenu>
30 #include <QUndoStack>
31
32 #include "kdenlivedoc.h"
33 #include "docclipbase.h"
34 #include "guide.h"
35 #include "effectslist.h"
36 #include "customtrackscene.h"
37
38 class ClipItem;
39 class AbstractClipItem;
40 class AbstractGroupItem;
41 class Transition;
42
43 class CustomTrackView : public QGraphicsView
44 {
45     Q_OBJECT
46
47 public:
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);
58     int cursorPos();
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();
83     int duration() const;
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);
101     void clipStart();
102     void clipEnd();
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();
107     void setInPoint();
108     void setOutPoint();
109
110     /** @brief Prepares inserting space.
111     *
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);
123
124     /** @brief Locks or unlocks a track.
125     * @param ix number of track
126     * @param lock whether to lock or unlock
127     *
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);
133
134     /** @brief Creates SplitAudioCommands for selected clips. */
135     void splitAudio();
136
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);
142     void setVideoOnly();
143     void setAudioOnly();
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();
149     double fps() const;
150     int selectedTrack() const;
151     QStringList selectedClips() const;
152     QList<ClipItem *> selectedClipItems() const;
153
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);
163
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)
168     *
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();
177
178 public slots:
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);
198     void slotAddGuide();
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);
204     void copyClip();
205     void pasteClip();
206     void pasteClipEffects();
207     void slotUpdateAllThumbs();
208     void slotCheckPositionScrolling();
209     void slotInsertTrack(int ix);
210
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);
217     void slotTrackUp();
218     void slotTrackDown();
219     void slotSelectTrack(int ix);
220     void insertZoneOverwrite(QStringList data, int in);
221
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);
229
230     /** @brief Cuts a group into two parts.
231     * @param clips1 Clips before the cut
232     * @param transitions1 Transitions before the cut
233     * @param clipsCut Clips that need to be cut
234     * @param transitionsCut Transitions that need to be cut
235     * @param clips2 Clips behind the cut
236     * @param transitions2 Transitions behind the cut
237     * @param cutPos Absolute position of the cut
238     * @param cut true = cut, false = "uncut" */
239     void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
240
241 protected:
242     virtual void drawBackground(QPainter * painter, const QRectF & rect);
243     //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
244     virtual void dragEnterEvent(QDragEnterEvent * event);
245     virtual void dragMoveEvent(QDragMoveEvent * event);
246     virtual void dragLeaveEvent(QDragLeaveEvent * event);
247     /** @brief Something has been dropped onto the timeline */
248     virtual void dropEvent(QDropEvent * event);
249     virtual void wheelEvent(QWheelEvent * e);
250     virtual void keyPressEvent(QKeyEvent * event);
251     virtual QStringList mimeTypes() const;
252     virtual Qt::DropActions supportedDropActions() const;
253
254 private:
255     int m_tracksHeight;
256     int m_projectDuration;
257     int m_cursorPos;
258     KdenliveDoc *m_document;
259     CustomTrackScene *m_scene;
260     QGraphicsLineItem *m_cursorLine;
261     ItemInfo m_dragItemInfo;
262     ItemInfo m_selectionGroupInfo;
263     OPERATIONTYPE m_operationMode;
264     OPERATIONTYPE m_moveOpMode;
265     AbstractClipItem *m_dragItem;
266     Guide *m_dragGuide;
267     QUndoStack *m_commandStack;
268     QGraphicsItem *m_visualTip;
269     QGraphicsItemAnimation *m_animation;
270     QTimeLine *m_animationTimer;
271     QColor m_tipColor;
272     QPen m_tipPen;
273     QPoint m_clickPoint;
274     QPoint m_clickEvent;
275     QList <CommentedTime> m_searchPoints;
276     QList <Guide *> m_guides;
277     void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
278     ClipItem *getClipItemAt(int pos, int track);
279     ClipItem *getClipItemAt(GenTime pos, int track);
280     ClipItem *getClipItemAtEnd(GenTime pos, int track);
281     ClipItem *getClipItemAtStart(GenTime pos, int track);
282     Transition *getTransitionItemAt(int pos, int track);
283     Transition *getTransitionItemAt(GenTime pos, int track);
284     Transition *getTransitionItemAtEnd(GenTime pos, int track);
285     Transition *getTransitionItemAtStart(GenTime pos, int track);
286     void checkScrolling();
287     /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
288     bool m_autoScroll;
289     void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
290     QMenu *m_timelineContextMenu;
291     QMenu *m_timelineContextClipMenu;
292     QMenu *m_timelineContextTransitionMenu;
293     QMenu *m_markerMenu;
294     QAction *m_autoTransition;
295     QAction *m_pasteEffectsAction;
296     QAction *m_ungroupAction;
297     QAction *m_editGuide;
298     QAction *m_deleteGuide;
299     QActionGroup *m_clipTypeGroup;
300     QTimer m_scrollTimer;
301     QTimer m_thumbsTimer;
302     int m_scrollOffset;
303     bool m_clipDrag;
304
305     int m_findIndex;
306     PROJECTTOOL m_tool;
307     QCursor m_razorCursor;
308     QCursor m_spacerCursor;
309     /** list containing items currently copied in the timeline */
310     QList<AbstractClipItem *> m_copiedItems;
311     /** Used to get the point in timeline where a context menu was opened */
312     QPoint m_menuPosition;
313     bool m_blockRefresh;
314     AbstractGroupItem *m_selectionGroup;
315     QList <ClipItem *> m_waitingThumbs;
316     int m_selectedTrack;
317     int m_spacerOffset;
318
319     /** Get the index of the video track that is just below current track */
320     int getPreviousVideoTrack(int track);
321     void updatePositionEffects(ClipItem * item, ItemInfo info);
322     bool insertDropClips(const QMimeData *data, const QPoint pos);
323     bool canBePastedTo(ItemInfo info, int type) const;
324     bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
325     bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
326     bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
327     ClipItem *getClipUnderCursor() const;
328     AbstractClipItem *getMainActiveClip() const;
329     void resetSelectionGroup(bool selectItems = true);
330     void groupSelectedItems(bool force = false, bool createNewGroup = false);
331     /** Get available space for clip move (min and max free positions) */
332     void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
333     /** Get available space for transition move (min and max free positions) */
334     void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
335     void updateClipTypeActions(ClipItem *clip);
336     /** Whether an item can be moved to a new position without colliding with similar items */
337     bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
338     /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
339     QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
340     /** Adjust clips under another one when working in overwrite mode */
341     void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
342     void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
343     /** Adjust keyframes when pasted to another clip */
344     void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
345     
346     /** @brief Removes the tip and stops the animation timer. */
347     void removeTipAnimation();
348     /** @brief Creates a new tip animation.
349     * @param clip clip to display the tip on
350     * @param mode operation mode for which the tip should be displayed
351     * @param size size of the tip */
352     void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
353
354     /** @brief Takes care of updating effects and attached transitions during a resize from start.
355     * @param item Item to resize
356     * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
357     * @param pos New startPos
358     * @param check (optional, default = false) Whether to check for collisions
359     * @param command (optional) Will be used as parent command (for undo history) */
360     void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
361
362     /** @brief Takes care of updating effects and attached transitions during a resize from end.
363     * @param item Item to resize
364     * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
365     * @param pos New endPos
366     * @param check (optional, default = false) Whether to check for collisions
367     * @param command (optional) Will be used as parent command (for undo history) */
368     void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
369
370     /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
371     * @param group The group to cut
372     * @param cutPos The absolute position of the cut */
373     void razorGroup(AbstractGroupItem *group, GenTime cutPos);
374
375 private slots:
376     void slotRefreshGuides();
377     void slotEnableRefresh();
378     void slotCheckMouseScrolling();
379     void slotEditTimeLineGuide();
380     void slotDeleteTimeLineGuide();
381     void slotFetchNextThumbs();
382     void checkTrackSequence(int track);
383     void slotGoToMarker(QAction *action);
384     void slotResetMenuPosition();
385     void slotDoResetMenuPosition();
386
387 signals:
388     void cursorMoved(int, int);
389     void zoomIn();
390     void zoomOut();
391     void mousePosition(int);
392     void clipItemSelected(ClipItem*, int ix = -1);
393     void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
394     void activateDocumentMonitor();
395     void trackHeightChanged();
396     void tracksChanged();
397     void displayMessage(const QString, MessageType);
398     void showClipFrame(DocClipBase *, QPoint, const int);
399     void doTrackLock(int, bool);
400     void updateClipMarkers(DocClipBase *);
401     void updateTrackHeaders();
402     void playMonitor();
403 };
404
405 #endif
406