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