]> git.sesse.net Git - kdenlive/blob - src/customtrackview.h
Improve the export audio automatic setting:
[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     /** @brief Cuts all clips that are selected at the timeline cursor position. */
86     void cutSelectedClips();
87     void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
88     void checkTrackHeight();
89     //QList <TrackInfo> tracksList() const;
90     void setTool(PROJECTTOOL tool);
91     ClipItem *cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute = true);
92     void slotSeekToPreviousSnap();
93     void slotSeekToNextSnap();
94     double getSnapPointForPos(double pos);
95     void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes);
96     bool findString(const QString &text);
97     void selectFound(QString track, QString pos);
98     bool findNextString(const QString &text);
99     void initSearchStrings();
100     void clearSearchStrings();
101     QList<ItemInfo> findId(const QString &clipId);
102     void clipStart();
103     void clipEnd();
104     void changeClipSpeed();
105     void doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id);
106     /** @brief Sets the document as modified. */
107     void setDocumentModified();
108     void setInPoint();
109     void setOutPoint();
110
111     /** @brief Prepares inserting space.
112     *
113     * Shows a dialog to configure length and track. */
114     void slotInsertSpace();
115     /** @brief Prepares removing space. */
116     void slotRemoveSpace();
117     void insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset);
118     ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
119     void deleteTimelineTrack(int ix, TrackInfo trackinfo);
120     void saveThumbnails();
121     void autoTransition();
122     QStringList getLadspaParams(QDomElement effect) const;
123     void initCursorPos(int pos);
124
125     /** @brief Locks or unlocks a track.
126     * @param ix number of track
127     * @param lock whether to lock or unlock
128     *
129     * Makes sure no clip on track to lock is selected. */
130     void lockTrack(int ix, bool lock);
131     void groupClips(bool group = true);
132     void doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group);
133     void loadGroups(const QDomNodeList groups);
134
135     /** @brief Creates SplitAudioCommands for selected clips. */
136     void splitAudio();
137
138     /** @brief Seperates the audio of a clip to a audio track.
139     * @param pos Position of the clip to split
140     * @param track Track of the clip
141     * @param split Split or unsplit */
142     void doSplitAudio(const GenTime &pos, int track, bool split);
143     void setVideoOnly();
144     void setAudioOnly();
145     void setAudioAndVideo();
146     void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
147     int hasGuide(int pos, int offset);
148     void reloadTransitionLumas();
149     void updateProjectFps();
150     double fps() const;
151     int selectedTrack() const;
152     QStringList selectedClips() const;
153     QList<ClipItem *> selectedClipItems() const;
154
155     /** @brief Selects a clip.
156     * @param add Whether to select or deselect
157     * @param group (optional) Whether to add the clip to a group
158     * @param track (optional) The track of the clip (has to be combined with @param pos)
159     * @param pos (optional) The position of the clip (has to be combined with @param track) */
160     void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
161     void selectTransition(bool add, bool group = false);
162     QStringList extractTransitionsLumas();
163     void setEditMode(EDITMODE mode);
164
165     /** @brief Inserts @param clip.
166     * @param clip The clip to insert
167     * @param in The inpoint of the clip (crop from start)
168     * @param out The outpoint of the clip (crop from end)
169     *
170     * Inserts at the position of timeline cursor and selected track. */
171     void insertClipCut(DocClipBase *clip, int in, int out);
172     void clearSelection();
173     void editItemDuration();
174     void buildGuidesMenu(QMenu *goMenu) const;
175     KPixmapCache* pixmapCache;
176     /** update the timeline objects when palette changes */
177     void updatePalette();
178     /** @brief Returns true if a track has audio data on it.
179     * @param track The track number
180     *
181     * Check whether given track has a clip with audio in it. */
182     bool hasAudio(int track) const;
183
184 public slots:
185     void setCursorPos(int pos, bool seek = true);
186     void moveCursorPos(int delta);
187     void updateCursorPos();
188     void slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup = true);
189     void slotChangeEffectState(ClipItem *clip, int effectPos, bool disable);
190     void slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos);
191     void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix);
192     void slotUpdateClipRegion(ClipItem *clip, int ix, QString region);
193     void slotRefreshEffects(ClipItem *clip);
194     void setDuration(int duration);
195     void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
196     void slotAddTransitionToSelectedClips(QDomElement transition);
197     void slotTransitionUpdated(Transition *, QDomElement);
198     void slotSwitchTrackAudio(int ix);
199     void slotSwitchTrackVideo(int ix);
200     void slotSwitchTrackLock(int ix);
201     void slotUpdateClip(const QString &clipId, bool reload = true);
202     void slotAddClipMarker(const QString &id, GenTime t, QString c);
203     bool addGuide(const GenTime pos, const QString &comment);
204     void slotAddGuide();
205     void slotEditGuide(CommentedTime guide);
206     void slotEditGuide(int guidePos = -1);
207     void slotDeleteGuide(int guidePos = -1);
208     void slotDeleteAllGuides();
209     void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
210     void copyClip();
211     void pasteClip();
212     void pasteClipEffects();
213     void slotUpdateAllThumbs();
214     void slotCheckPositionScrolling();
215     void slotInsertTrack(int ix);
216
217     /** @brief Shows a dialog for selecting a track to delete.
218     * @param ix Number of the track, which should be pre-selected in the dialog */
219     void slotDeleteTrack(int ix);
220     /** @brief Shows the configure tracks dialog. */
221     void slotConfigTracks(int ix);
222     void clipNameChanged(const QString id, const QString name);
223     void slotTrackUp();
224     void slotTrackDown();
225     void slotSelectTrack(int ix);
226     void insertZoneOverwrite(QStringList data, int in);
227
228     /** @brief Rebuilds a group to fit again after children changed.
229     * @param childTrack the track of one of the groups children
230     * @param childPos The position of the same child */
231     void rebuildGroup(int childTrack, GenTime childPos);
232     /** @brief Rebuilds a group to fit again after children changed.
233     * @param group The group to rebuild */
234     void rebuildGroup(AbstractGroupItem *group);
235
236     /** @brief Cuts a group into two parts.
237     * @param clips1 Clips before the cut
238     * @param transitions1 Transitions before the cut
239     * @param clipsCut Clips that need to be cut
240     * @param transitionsCut Transitions that need to be cut
241     * @param clips2 Clips behind the cut
242     * @param transitions2 Transitions behind the cut
243     * @param cutPos Absolute position of the cut
244     * @param cut true = cut, false = "uncut" */
245     void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
246
247 protected:
248     virtual void drawBackground(QPainter * painter, const QRectF & rect);
249     //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
250     virtual void dragEnterEvent(QDragEnterEvent * event);
251     virtual void dragMoveEvent(QDragMoveEvent * event);
252     virtual void dragLeaveEvent(QDragLeaveEvent * event);
253     /** @brief Something has been dropped onto the timeline */
254     virtual void dropEvent(QDropEvent * event);
255     virtual void wheelEvent(QWheelEvent * e);
256     virtual void keyPressEvent(QKeyEvent * event);
257     virtual QStringList mimeTypes() const;
258     virtual Qt::DropActions supportedDropActions() const;
259
260 private:
261     int m_tracksHeight;
262     int m_projectDuration;
263     int m_cursorPos;
264     KdenliveDoc *m_document;
265     CustomTrackScene *m_scene;
266     QGraphicsLineItem *m_cursorLine;
267     ItemInfo m_dragItemInfo;
268     ItemInfo m_selectionGroupInfo;
269     OPERATIONTYPE m_operationMode;
270     OPERATIONTYPE m_moveOpMode;
271     AbstractClipItem *m_dragItem;
272     Guide *m_dragGuide;
273     QUndoStack *m_commandStack;
274     QGraphicsItem *m_visualTip;
275     QGraphicsItemAnimation *m_animation;
276     QTimeLine *m_animationTimer;
277     QColor m_tipColor;
278     QPen m_tipPen;
279     QPoint m_clickPoint;
280     QPoint m_clickEvent;
281     QList <CommentedTime> m_searchPoints;
282     QList <Guide *> m_guides;
283     void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
284     ClipItem *getClipItemAt(int pos, int track);
285     ClipItem *getClipItemAt(GenTime pos, int track);
286     ClipItem *getClipItemAtEnd(GenTime pos, int track);
287     ClipItem *getClipItemAtStart(GenTime pos, int track);
288     Transition *getTransitionItemAt(int pos, int track);
289     Transition *getTransitionItemAt(GenTime pos, int track);
290     Transition *getTransitionItemAtEnd(GenTime pos, int track);
291     Transition *getTransitionItemAtStart(GenTime pos, int track);
292     void checkScrolling();
293     /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
294     bool m_autoScroll;
295     void displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group);
296     QMenu *m_timelineContextMenu;
297     QMenu *m_timelineContextClipMenu;
298     QMenu *m_timelineContextTransitionMenu;
299     QMenu *m_markerMenu;
300     QAction *m_autoTransition;
301     QAction *m_pasteEffectsAction;
302     QAction *m_ungroupAction;
303     QAction *m_editGuide;
304     QAction *m_deleteGuide;
305     QActionGroup *m_clipTypeGroup;
306     QTimer m_scrollTimer;
307     QTimer m_thumbsTimer;
308     int m_scrollOffset;
309     bool m_clipDrag;
310
311     int m_findIndex;
312     PROJECTTOOL m_tool;
313     QCursor m_razorCursor;
314     QCursor m_spacerCursor;
315     /** list containing items currently copied in the timeline */
316     QList<AbstractClipItem *> m_copiedItems;
317     /** Used to get the point in timeline where a context menu was opened */
318     QPoint m_menuPosition;
319     bool m_blockRefresh;
320     AbstractGroupItem *m_selectionGroup;
321     QList <ClipItem *> m_waitingThumbs;
322     int m_selectedTrack;
323     int m_spacerOffset;
324
325     /** Get the index of the video track that is just below current track */
326     int getPreviousVideoTrack(int track);
327     void updatePositionEffects(ClipItem * item, ItemInfo info);
328     bool insertDropClips(const QMimeData *data, const QPoint pos);
329     bool canBePastedTo(ItemInfo info, int type) const;
330     bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
331     bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
332     bool canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
333     ClipItem *getClipUnderCursor() const;
334     AbstractClipItem *getMainActiveClip() const;
335     void resetSelectionGroup(bool selectItems = true);
336     void groupSelectedItems(bool force = false, bool createNewGroup = false);
337     /** Get available space for clip move (min and max free positions) */
338     void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
339     /** Get available space for transition move (min and max free positions) */
340     void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
341     void updateClipTypeActions(ClipItem *clip);
342     /** Whether an item can be moved to a new position without colliding with similar items */
343     bool itemCollision(AbstractClipItem *item, ItemInfo newPos);
344     /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
345     QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
346     /** Adjust clips under another one when working in overwrite mode */
347     void adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command);
348     void adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command);
349     /** Adjust keyframes when pasted to another clip */
350     void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
351
352     /** @brief Removes the tip and stops the animation timer. */
353     void removeTipAnimation();
354     /** @brief Creates a new tip animation.
355     * @param clip clip to display the tip on
356     * @param mode operation mode for which the tip should be displayed
357     * @param size size of the tip */
358     void setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size);
359
360     /** @brief Takes care of updating effects and attached transitions during a resize from start.
361     * @param item Item to resize
362     * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
363     * @param pos New startPos
364     * @param check (optional, default = false) Whether to check for collisions
365     * @param command (optional) Will be used as parent command (for undo history) */
366     void prepareResizeClipStart(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
367
368     /** @brief Takes care of updating effects and attached transitions during a resize from end.
369     * @param item Item to resize
370     * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
371     * @param pos New endPos
372     * @param check (optional, default = false) Whether to check for collisions
373     * @param command (optional) Will be used as parent command (for undo history) */
374     void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
375
376     /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
377     * @param group The group to cut
378     * @param cutPos The absolute position of the cut */
379     void razorGroup(AbstractGroupItem *group, GenTime cutPos);
380
381 private slots:
382     void slotRefreshGuides();
383     void slotEnableRefresh();
384     void slotCheckMouseScrolling();
385     void slotEditTimeLineGuide();
386     void slotDeleteTimeLineGuide();
387     void slotFetchNextThumbs();
388     void checkTrackSequence(int track);
389     void slotGoToMarker(QAction *action);
390     void slotResetMenuPosition();
391     void slotDoResetMenuPosition();
392
393 signals:
394     void cursorMoved(int, int);
395     void zoomIn();
396     void zoomOut();
397     void mousePosition(int);
398     void clipItemSelected(ClipItem*, int ix = -1);
399     void transitionItemSelected(Transition*, int track = 0, QPoint p = QPoint(), bool update = false);
400     void activateDocumentMonitor();
401     void trackHeightChanged();
402     void tracksChanged();
403     void displayMessage(const QString, MessageType);
404     void showClipFrame(DocClipBase *, QPoint, const int);
405     void doTrackLock(int, bool);
406     void updateClipMarkers(DocClipBase *);
407     void updateTrackHeaders();
408     void playMonitor();
409     /** @brief Monitor document changes (for example the presence of audio data in timeline for export widget.*/
410     void documentModified();
411 };
412
413 #endif
414