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