customtrackview.h 33.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/***************************************************************************
 *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef CUSTOMTRACKVIEW_H
#define CUSTOMTRACKVIEW_H

23
#include <KColorScheme>
24

25
#include <QGraphicsView>
26 27
#include <QGraphicsItemAnimation>
#include <QTimeLine>
28
#include <QMenu>
29 30
#include <QMutex>
#include <QWaitCondition>
31

32 33
#include "doc/kdenlivedoc.h"
#include "timeline/guide.h"
Vincent Pinon's avatar
Vincent Pinon committed
34
#include "effectslist/effectslist.h"
35
#include "timeline/customtrackscene.h"
36
#include "timeline/managers/abstracttoolmanager.h"
37

38
class Timeline;
39
class ClipController;
40 41
class ClipItem;
class AbstractClipItem;
42
class AbstractGroupItem;
43
class Transition;
Simon Eugster's avatar
Simon Eugster committed
44
class AudioCorrelation;
45
class KSelectAction;
46

47 48
class CustomTrackView : public QGraphicsView
{
49 50 51
    Q_OBJECT

public:
Laurent Montel's avatar
Laurent Montel committed
52
    CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTrackScene *projectscene, QWidget *parent = nullptr);
53
    virtual ~ CustomTrackView();
54

55 56 57
    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
Laurent Montel's avatar
Laurent Montel committed
58
    void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
59
    void addTrack(const TrackInfo &type, int ix = -1);
60
    void removeTrack(int ix);
Vincent Pinon's avatar
Vincent Pinon committed
61
    /** @brief Makes the document use new track info (name, type, ...). */
62 63
    void configTracks(const QList<TrackInfo> &trackInfos);
    int cursorPos() const;
64
    void checkAutoScroll();
65 66 67
    /**
      Move the clip at \c start to \c end.

Laurent Montel's avatar
Laurent Montel committed
68
      If \c out_actualEnd is not nullptr, it will be set to the position the clip really ended up at.
69 70
      For example, attempting to move a clip to t = -1 s will actually move it to t = 0 s.
      */
Laurent Montel's avatar
Laurent Montel committed
71
    bool moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh, bool alreadyMoved, ItemInfo *out_actualEnd = nullptr);
72
    void moveGroup(QList<ItemInfo> startClip, QList<ItemInfo> startTransition, const GenTime &offset, const int trackOffset, bool alreadyMoved, bool reverseMove);
73
    /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
Jean-Baptiste Mardelle's avatar
cleanup  
Jean-Baptiste Mardelle committed
74
    void moveTransition(const ItemInfo &start, const ItemInfo &end, bool refresh);
75
    void resizeClip(const ItemInfo &start, const ItemInfo &end, bool dontWorry = false);
Laurent Montel's avatar
Laurent Montel committed
76 77
    void addClip(const QString &clipId, const ItemInfo &info, const EffectsList &list, PlaylistState::ClipState state, bool refresh = true);
    void deleteClip(const ItemInfo &info, bool refresh = true);
78
    void addMarker(const QString &id, const CommentedTime &marker);
79
    void addData(const QString &id, const QString &key, const QString &data);
80
    void setScale(double scaleFactor, double verticalScale, bool zoomOnMouse = false);
81
    void deleteClip(const QString &clipId, QUndoCommand *deleteCommand);
82
    /** @brief An effect was dropped on @param clip */
83
    void slotDropEffect(ClipItem *clip, const QDomElement &effect, GenTime pos, int track);
84
    /** @brief A transition was dropped on @param clip */
Laurent Montel's avatar
Laurent Montel committed
85
    void slotDropTransition(ClipItem *clip, const QDomElement &transition, QPointF scenePos);
86
    /** @brief Add effect to current clip */
87
    void slotAddEffectToCurrentItem(const QDomElement &effect);
88
    /** @brief Add effect to a clip or selection */
89
    void slotAddEffect(const QDomElement &effect, const GenTime &pos, int track);
Laurent Montel's avatar
Laurent Montel committed
90
    void slotAddGroupEffect(const QDomElement &effect, AbstractGroupItem *group, AbstractClipItem *dropTarget = nullptr);
Laurent Montel's avatar
Laurent Montel committed
91
    void addEffect(int track, GenTime pos, const QDomElement &effect);
92
    void deleteEffect(int track, const GenTime &pos, const QDomElement &effect);
Laurent Montel's avatar
Laurent Montel committed
93
    void updateEffect(int track, GenTime pos, const QDomElement &insertedEffect, bool refreshEffectStack = false, bool replaceEffect = false, bool refreshMonitor = true);
94
    /** @brief Enable / disable a list of effects */
Laurent Montel's avatar
Laurent Montel committed
95
    void updateEffectState(int track, GenTime pos, const QList<int> &effectIndexes, bool disable, bool updateEffectStack);
Laurent Montel's avatar
Laurent Montel committed
96
    void moveEffect(int track, const GenTime &pos, const QList<int> &oldPos, const QList<int> &newPos);
97
    void addTransition(const ItemInfo &transitionInfo, int endTrack, const QDomElement &params, bool refresh);
Laurent Montel's avatar
Laurent Montel committed
98
    void deleteTransition(const ItemInfo &transitionInfo, int endTrack, const QDomElement &params, bool refresh);
Laurent Montel's avatar
Laurent Montel committed
99
    void updateTransition(int track, const GenTime &pos,  const QDomElement &oldTransition, const QDomElement &transition, bool updateTransitionWidget);
100
    void activateMonitor();
101
    int duration() const;
102
    void deleteSelectedClips();
103
    /** @brief Cuts all clips that are selected at the timeline cursor position. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
104
    void cutSelectedClips(QList<QGraphicsItem *> itemList = QList<QGraphicsItem *>(), GenTime currentPos = GenTime());
105
    void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
106
    bool checkTrackHeight(bool force = false);
107
    void updateSceneFrameWidth(double fpsChanged = 1.0);
108
    void setTool(ProjectTool tool);
109
    void cutClip(const ItemInfo &info, const GenTime &cutTime, bool cut, const EffectsList &oldStack = EffectsList(), bool execute = true);
110
    Transition *cutTransition(const ItemInfo &info, const GenTime &cutTime, bool cut, const QDomElement &oldStack = QDomElement(), bool execute = true);
111 112
    void slotSeekToPreviousSnap();
    void slotSeekToNextSnap();
113
    double getSnapPointForPos(double pos);
114
    bool findString(const QString &text);
Laurent Montel's avatar
Laurent Montel committed
115
    void selectFound(const QString &track, const QString &pos);
116
    bool findNextString(const QString &text);
117 118
    void initSearchStrings();
    void clearSearchStrings();
119
    QList<ItemInfo> findId(const QString &clipId);
120 121
    void clipStart();
    void clipEnd();
Laurent Montel's avatar
Laurent Montel committed
122
    void doChangeClipSpeed(const ItemInfo &info, const ItemInfo &speedIndependantInfo, PlaylistState::ClipState state, const double speed, int strobe, const QString &id, bool removeEffect = false);
123
    /** @brief Every command added to the undo stack automatically triggers a document change event.
124
     *  This function should only be called when changing a document setting or another function that
125
     *  is not integrated in the undo / redo system */
126
    void setDocumentModified();
127 128
    void setInPoint();
    void setOutPoint();
Till Theato's avatar
Till Theato committed
129

130 131 132
    /** @brief Prepares inserting space.
    *
    * Shows a dialog to configure length and track. */
133
    void slotInsertSpace();
134
    /** @brief Prepares removing space. */
135
    void slotRemoveSpace(bool multiTrack = false);
Laurent Montel's avatar
Laurent Montel committed
136
    void insertSpace(const QList<ItemInfo> &clipsToMove, const QList<ItemInfo> &transToMove, int track, const GenTime &duration, const GenTime &offset);
137
    ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
Laurent Montel's avatar
Laurent Montel committed
138
    void deleteTimelineTrack(int ix, const TrackInfo &trackinfo);
139
    void saveThumbnails();
140
    void autoTransition();
141
    void initCursorPos(int pos);
Till Theato's avatar
Till Theato committed
142

143 144 145
    /** @brief Locks or unlocks a track.
    * @param ix number of track
    * @param lock whether to lock or unlock
146
    * @param requestUpdate (default = true) Whether to request an update of the icon in the track header
147 148
    *
    * Makes sure no clip on track to lock is selected. */
149
    void lockTrack(int ix, bool lock, bool requestUpdate = true);
Laurent Montel's avatar
Laurent Montel committed
150
    void groupClips(bool group = true, QList<QGraphicsItem *> itemList = QList<QGraphicsItem *>(), bool forceLock = false, QUndoCommand *command = nullptr, bool doIt = true);
Laurent Montel's avatar
Laurent Montel committed
151
    void doGroupClips(const QList<ItemInfo> &clipInfos, const QList<ItemInfo> &transitionInfos, bool group);
152
    void loadGroups(const QDomNodeList &groups);
153 154

    /** @brief Creates SplitAudioCommands for selected clips. */
Laurent Montel's avatar
Laurent Montel committed
155
    void splitAudio(bool warn = true, const ItemInfo &info = ItemInfo(), int destTrack = -1, QUndoCommand *masterCommand = nullptr);
156

Simon Eugster's avatar
Simon Eugster committed
157 158 159 160 161 162
    /// Define which clip to take as reference for automatic audio alignment
    void setAudioAlignReference();

    /// Automatically align the currently selected clips to synchronize their audio with the reference's audio
    void alignAudio();

Yuri Chornoivan's avatar
Yuri Chornoivan committed
163
    /** @brief Separates the audio of a clip to a audio track.
164
    * @param pos Position of the clip to split
165
    * @param track Track of the clip
166
    * @param split Split or unsplit
167 168
    * @return true if the split was successful  */
    bool doSplitAudio(const GenTime &pos, int track, int destTrack, bool split);
169
    /** @brief Sets the clip type (av, video only, audio only) of the current selection. */
170
    void setClipType(PlaylistState::ClipState state);
Laurent Montel's avatar
Laurent Montel committed
171
    void doChangeClipType(const ItemInfo &info, PlaylistState::ClipState state);
172 173 174 175 176
    /** @brief Check if there is a guide at position.
     * @param pos Position to check
     * @param framePos If set to true, pos is an exact frame number, otherwise it's a mouse event pos
     */
    int hasGuide(double pos, bool framePos);
177
    void reloadTransitionLumas();
178 179
    void updateProjectFps();
    double fps() const;
180
    int selectedTrack() const;
181
    QStringList selectedClips() const;
Yuri Chornoivan's avatar
Yuri Chornoivan committed
182
    /** @brief Checks whether an item can be inserted (make sure it does not overlap another item) */
Laurent Montel's avatar
Laurent Montel committed
183
    bool canBePastedTo(const ItemInfo &info, int type, const QList<AbstractClipItem *> &excluded = QList<AbstractClipItem *>()) const;
Till Theato's avatar
Till Theato committed
184

185 186 187 188 189 190
    /** @brief Selects a clip.
    * @param add Whether to select or deselect
    * @param group (optional) Whether to add the clip to a group
    * @param track (optional) The track of the clip (has to be combined with @param pos)
    * @param pos (optional) The position of the clip (has to be combined with @param track) */
    void selectClip(bool add, bool group = false, int track = -1, int pos = -1);
191
    void selectTransition(bool add, bool group = false);
192
    QStringList extractTransitionsLumas();
193
    void setEditMode(TimelineMode::EditMode mode);
Till Theato's avatar
Till Theato committed
194 195 196 197 198 199 200

    /** @brief Inserts @param clip.
    * @param clip The clip to insert
    * @param in The inpoint of the clip (crop from start)
    * @param out The outpoint of the clip (crop from end)
    *
    * Inserts at the position of timeline cursor and selected track. */
Jean-Baptiste Mardelle's avatar
cleanup  
Jean-Baptiste Mardelle committed
201
    void insertClipCut(const QString &id, int in, int out);
202
    void clearSelection(bool emitInfo = true);
203
    void editItemDuration();
204
    void buildGuidesMenu(QMenu *goMenu) const;
205 206
    /** update the timeline objects when palette changes */
    void updatePalette();
207 208 209 210 211
    /** @brief Returns true if a track has audio data on it.
    * @param track The track number
    *
    * Check whether given track has a clip with audio in it. */
    bool hasAudio(int track) const;
212

213
    int getFrameWidth() const;
214
    /** @brief Returns last requested seeking pos, or current cursor position. */
215
    int seekPosition() const;
216

217
    void monitorRefresh(bool invalidateRange = false);
218
    /** @brief Trigger a monitor refresh if timeline cursor is inside range. */
Laurent Montel's avatar
Laurent Montel committed
219
    void monitorRefresh(const ItemInfo &range, bool invalidateRange = false);
220

221 222
    /** @brief Returns frame number of current mouse position. */
    int getMousePos() const;
223 224
    /** @brief Insert space in timeline after clips were moved. if fromstart is true, we assume clips have not yet been moved manually. */
    void completeSpaceOperation(int track, GenTime &timeOffset, bool fromStart = false);
225
    void spaceToolMoveToSnapPos(double snappedPos);
226
    void createRectangleSelection(Qt::KeyboardModifiers modifiers);
227
    int spaceToolSelectTrackOnly(int track, QList<QGraphicsItem *> &selection, GenTime pos = GenTime(-1));
228
    QList<QGraphicsItem *> selectAllItemsToTheRight(int x);
229
    GenTime createGroupForSelectedItems(QList<QGraphicsItem *> &selection);
230
    void resetSelectionGroup(bool selectItems = true);
231
    /** @brief Returns all infos necessary to save guides. */
Laurent Montel's avatar
Laurent Montel committed
232
    QMap<double, QString> guidesData() const;
233 234
    /** @brief Reset scroll bar to 0. */
    void scrollToStart();
235 236 237 238
    /** @brief Returns a track index (in MLT values) from an y position in timeline. */
    int getTrackFromPos(double y) const;
    /** @brief Returns customtrackview y position from an MLT track number. */
    int getPositionFromTrack(int track) const;
239 240 241
    /** @brief Expand current timeline clip (recover clips and tracks from an MLT playlist) */
    void expandActiveClip();
    /** @brief Import amultitrack MLT playlist in timeline */
Laurent Montel's avatar
Laurent Montel committed
242
    void importPlaylist(const ItemInfo &info, const QMap<QString, QString> &idMap, const QDomDocument &doc, QUndoCommand *command);
243 244
    /** @brief Returns true if there is a selected item in timeline */
    bool hasSelection() const;
245 246
    /** @brief Get the index of the video track that is just above current track */
    int getNextVideoTrack(int track);
247
    /** @brief returns id of clip under cursor and set pos to cursor position in clip,
248
     *  zone gets in/out points */
Laurent Montel's avatar
Laurent Montel committed
249
    const QString getClipUnderCursor(int *pos, QPoint *zone = nullptr) const;
250 251 252 253
    /** @brief returns displayable timecode info */
    QString getDisplayTimecode(const GenTime &time) const;
    QString getDisplayTimecodeFromFrames(int frames) const;
    /** @brief Call the default QGraphicsView mouse event */
254
    void graphicsViewMouseEvent(QMouseEvent *event);
255 256 257
    /** @brief Creates an overlay track with filtered clip */
    bool createSplitOverlay(Mlt::Filter *filter);
    void removeSplitOverlay();
258
    /** @brief Geometry keyframes dropped on a transition, start import */
259
    void dropTransitionGeometry(Transition *trans, const QString &geometry);
260
    /** @brief Geometry keyframes dropped on a clip, start import */
Laurent Montel's avatar
Laurent Montel committed
261
    void dropClipGeometry(ClipItem *trans, const QString &geometry);
262 263
    /** @brief Switch current track lock state */
    void switchTrackLock();
264
    void switchAllTrackLock();
265
    /** @brief Insert space in timeline. track = -1 means all tracks */
Laurent Montel's avatar
Laurent Montel committed
266
    void insertTimelineSpace(GenTime startPos, GenTime duration, int track = -1, const QList<ItemInfo> &excludeList = QList<ItemInfo>());
267
    void trimMode(bool enable, int ripplePos = -1);
268 269 270
    /** @brief Returns a clip from timeline
    *  @param pos the end time position
    *  @param track the track where the clip is in MLT coordinates */
271
    ClipItem *getClipItemAtEnd(GenTime pos, int track);
272
    /** @brief Returns a clip from timeline
273
     *  @param pos the time position
274
     *  @param track the track where the clip is in MLT coordinates
275 276 277 278 279 280 281 282
     *  @param end the end position of the clip in case of overlapping clips (overwrite mode) */
    ClipItem *getClipItemAtStart(GenTime pos, int track, GenTime end = GenTime());
    /** @brief Takes care of updating effects and attached transitions during a resize from start.
    * @param item Item to resize
    * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
    * @param pos New startPos
    * @param check (optional, default = false) Whether to check for collisions
    * @param command (optional) Will be used as parent command (for undo history) */
Laurent Montel's avatar
Laurent Montel committed
283
    void prepareResizeClipStart(AbstractClipItem *item, const ItemInfo &oldInfo, int pos, bool check = false, QUndoCommand *command = nullptr);
284 285 286 287 288 289 290

    /** @brief Takes care of updating effects and attached transitions during a resize from end.
    * @param item Item to resize
    * @param oldInfo The item's info before resizement (set to item->info() is @param check true)
    * @param pos New endPos
    * @param check (optional, default = false) Whether to check for collisions
    * @param command (optional) Will be used as parent command (for undo history) */
Laurent Montel's avatar
Laurent Montel committed
291
    void prepareResizeClipEnd(AbstractClipItem *item, const ItemInfo &oldInfo, int pos, bool check = false, QUndoCommand *command = nullptr);
292 293
    AbstractClipItem *dragItem();
    /** @brief Cut clips in all non locked tracks. */
Laurent Montel's avatar
Laurent Montel committed
294
    void cutTimeline(int cutPos, const QList<ItemInfo> &excludedClips, const QList<ItemInfo> &excludedTransitions, QUndoCommand *masterCommand, int track = -1);
295 296
    void updateClipTypeActions(ClipItem *clip);
    void setOperationMode(OperationType mode);
297
    OperationType operationMode() const;
298
    OperationType prepareMode() const;
299
    TimelineMode::EditMode sceneEditMode();
Laurent Montel's avatar
Laurent Montel committed
300
    bool isLastClip(const ItemInfo &info);
301 302 303 304 305 306 307 308 309
    TrackInfo getTrackInfo(int ix);
    Transition *getTransitionItemAtStart(GenTime pos, int track);
    Transition *getTransitionItemAtEnd(GenTime pos, int track);
    void adjustTimelineTransitions(TimelineMode::EditMode mode, Transition *item, QUndoCommand *command);
    /** @brief Get the index of the video track that is just below current track */
    int getPreviousVideoTrack(int track);
    /** @brief Updates the duration stored in a track's TrackInfo.
     * @param track Number of track as used in ItemInfo (not the numbering used in KdenliveDoc) (negative for all tracks)
     * @param command If effects need to be updated the commands to do this will be attached to this undo command
310
     *
311 312 313
     * In addition to update the duration in TrackInfo it updates effects with keyframes on the track. */
    void updateTrackDuration(int track, QUndoCommand *command);
    /** @brief Send updtaed info to transition widget. */
Laurent Montel's avatar
Laurent Montel committed
314
    void updateTransitionWidget(Transition *tr, const ItemInfo &info);
315 316
    AbstractGroupItem *selectionGroup();
    Timecode timecode();
317 318 319 320
    /** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
    * @param group The group to cut
    * @param cutPos The absolute position of the cut */
    void razorGroup(AbstractGroupItem *group, GenTime cutPos);
Laurent Montel's avatar
Laurent Montel committed
321
    void reloadTrack(const ItemInfo &info, bool includeLastFrame);
Laurent Montel's avatar
Laurent Montel committed
322
    GenTime groupSelectedItems(QList<QGraphicsItem *> selection = QList<QGraphicsItem *>(), bool createNewGroup = false, bool selectNewGroup = false);
323
    void sortGuides();
324
    void initTools();
325 326 327
    AbstractToolManager *toolManager(AbstractToolManager::ToolManagerType trimType);
    /** @brief Perform a ripple move on timeline clips */
    bool rippleClip(ClipItem *clip, int diff);
Laurent Montel's avatar
Laurent Montel committed
328
    void finishRipple(ClipItem *clip, const ItemInfo &startInfo, int diff, bool fromStart);
329

330
public slots:
Jean-Baptiste Mardelle's avatar
cleanup  
Jean-Baptiste Mardelle committed
331
    /** @brief Send seek request to MLT. */
332
    void seekCursorPos(int pos);
Jean-Baptiste Mardelle's avatar
cleanup  
Jean-Baptiste Mardelle committed
333 334
    /** @brief Move timeline cursor to new position. */
    void setCursorPos(int pos);
335
    void moveCursorPos(int delta);
Laurent Montel's avatar
Laurent Montel committed
336
    void slotDeleteEffectGroup(ClipItem *clip, int track, const QDomDocument &doc, bool affectGroup = true);
Laurent Montel's avatar
Laurent Montel committed
337
    void slotDeleteEffect(ClipItem *clip, int track, const QDomElement &effect, bool affectGroup = true, QUndoCommand *parentCommand = nullptr);
Laurent Montel's avatar
Laurent Montel committed
338
    void slotChangeEffectState(ClipItem *clip, int track, QList<int> effectIndexes, bool disable);
Laurent Montel's avatar
Laurent Montel committed
339 340
    void slotChangeEffectPosition(ClipItem *clip, int track, const QList<int> &currentPos, int newPos);
    void slotUpdateClipEffect(ClipItem *clip, int track, const QDomElement &oldeffect, const QDomElement &effect, int ix, bool refreshEffectStack = true);
341
    void slotUpdateClipRegion(ClipItem *clip, int ix, const QString &region);
342
    void slotRefreshEffects(ClipItem *clip);
343
    void setDuration(int duration);
344
    void slotAddTransition(ClipItem *clip, const ItemInfo &transitionInfo, int endTrack, const QDomElement &transition = QDomElement());
Laurent Montel's avatar
Laurent Montel committed
345
    void slotAddTransitionToSelectedClips(const QDomElement &transition, QList<QGraphicsItem *> itemList = QList<QGraphicsItem *>());
Laurent Montel's avatar
Laurent Montel committed
346
    void slotTransitionUpdated(Transition *, const QDomElement &);
347
    void slotSwitchTrackLock(int ix, bool enable, bool applyToAll = false);
348
    void slotUpdateClip(const QString &clipId, bool reload = true);
349

350
    bool addGuide(const GenTime &pos, const QString &comment, bool loadingProject = false);
351 352 353 354

    /** @brief Shows a dialog for adding a guide.
     * @param dialog (default = true) false = do not show the dialog but use current position as position and comment */
    void slotAddGuide(bool dialog = true);
355
    void slotEditGuide(const CommentedTime &guide);
356
    void slotEditGuide(int guidePos = -1, const QString &newText = QString());
357
    void slotDeleteGuide(int guidePos = -1);
358
    void slotDeleteAllGuides();
359
    void editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment);
360 361
    void copyClip();
    void pasteClip();
362
    void pasteClipEffects();
363
    void slotUpdateAllThumbs();
364
    void slotCheckPositionScrolling();
365
    void slotInsertTrack(int ix);
366 367
    /** @brief Trigger a monitor refresh. */
    void monitorRefresh(const QList<ItemInfo> &range, bool invalidateRange = false);
368 369

    /** @brief Shows a dialog for selecting a track to delete.
Till Theato's avatar
Till Theato committed
370 371
    * @param ix Number of the track, which should be pre-selected in the dialog */
    void slotDeleteTrack(int ix);
372 373
    /** @brief Shows the configure tracks dialog. */
    void slotConfigTracks(int ix);
374
    void clipNameChanged(const QString &id);
375
    void slotSelectTrack(int ix, bool switchTarget = false);
Laurent Montel's avatar
Laurent Montel committed
376
    int insertZone(TimelineMode::EditMode sceneMode, const QString &clipId, QPoint binZone);
377

378
    /** @brief Rebuilds a group to fit again after children changed.
379 380
    * @param childTrack the track of one of the groups children
    * @param childPos The position of the same child */
381
    void rebuildGroup(int childTrack, const GenTime &childPos);
382 383 384
    /** @brief Rebuilds a group to fit again after children changed.
    * @param group The group to rebuild */
    void rebuildGroup(AbstractGroupItem *group);
385

386 387 388
    /** @brief Add en effect to a track.
    * @param effect The new effect xml
    * @param ix The track index */
Laurent Montel's avatar
Laurent Montel committed
389
    void slotAddTrackEffect(const QDomElement &effect, int ix);
390 391 392 393
    /** @brief Select all clips in selected track. */
    void slotSelectClipsInTrack();
    /** @brief Select all clips in timeline. */
    void slotSelectAllClips();
394

395 396 397 398
    /** @brief Update the list of snap points (sticky timeline hotspots).
    * @param selected The currently selected clip if any
    * @param offsetList The list of points that should also snap (for example when movin a clip, start and end points should snap
    * @param skipSelectedItems if true, the selected item start and end points will not be added to snap list */
Laurent Montel's avatar
Laurent Montel committed
399
    void updateSnapPoints(AbstractClipItem *selected, QList<GenTime> offsetList = QList<GenTime> (), bool skipSelectedItems = false);
400

401
    void slotAddEffect(ClipItem *clip, const QDomElement &effect, int track = -1);
402
    void slotImportClipKeyframes(GraphicsRectItem type, const ItemInfo &info, const QDomElement &xml, QMap<QString, QString> keyframes = QMap<QString, QString>());
403

404
    /** @brief Move playhead to mouse curser position if defined key is pressed */
405
    void slotAlignPlayheadToMousePos();
406

407
    void slotInfoProcessingFinished();
408
    void slotAlignClip(int, int, int);
409
    /** @brief Export part of the playlist in an xml file */
410
    void exportTimelineSelection(QString path = QString());
411
    /** Remove zone from current track */
Laurent Montel's avatar
Laurent Montel committed
412
    void extractZone(QPoint z, bool closeGap, const QList<ItemInfo> &excludedClips = QList<ItemInfo>(), QUndoCommand *masterCommand = nullptr, int track = -1);
413 414
    /** @brief Select an item in timeline. */
    void slotSelectItem(AbstractClipItem *item);
415 416
    /** @brief Cycle through timeline trim modes */
    void switchTrimMode(TrimMode mode = NormalTrim);
417
    void switchTrimMode(int mode);
418

419
protected:
420
    void drawBackground(QPainter *painter, const QRectF &rect) Q_DECL_OVERRIDE;
421
    //virtual void drawForeground ( QPainter * painter, const QRectF & rect );
422 423 424 425
    void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
    void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
    void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
    bool event(QEvent *e) Q_DECL_OVERRIDE;
Simon Eugster's avatar
Simon Eugster committed
426
    /** @brief Something has been dropped onto the timeline */
427 428 429 430 431
    void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
    void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
    void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
    void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
    void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
432
    virtual QStringList mimeTypes() const;
433
    virtual Qt::DropActions supportedDropActions() const;
434
    void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
435

436
private:
437
    int m_ct;
438
    int m_tracksHeight;
439
    int m_projectDuration;
440
    int m_cursorPos;
441
    double m_cursorOffset;
442
    KdenliveDoc *m_document;
443
    Timeline *m_timeline;
444
    CustomTrackScene *m_scene;
445
    QGraphicsLineItem *m_cursorLine;
446
    ItemInfo m_dragItemInfo;
447
    ItemInfo m_selectionGroupInfo;
448
    /** @brief Possible timeline action */
449
    OperationType m_operationMode;
450
    /** @brief Currently running operation */
451
    OperationType m_moveOpMode;
452
    AbstractClipItem *m_dragItem;
453
    Guide *m_dragGuide;
454
    DocUndoStack *m_commandStack;
455
    QGraphicsItem *m_visualTip;
456 457
    QGraphicsItemAnimation *m_keyProperties;
    QTimeLine *m_keyPropertiesTimer;
458
    QColor m_tipColor;
459
    QPen m_tipPen;
460
    QPoint m_clickEvent;
Laurent Montel's avatar
Laurent Montel committed
461 462
    QList<CommentedTime> m_searchPoints;
    QList<Guide *> m_guides;
463
    QColor m_selectedTrackColor;
464
    QColor m_lockedTrackColor;
Laurent Montel's avatar
Laurent Montel committed
465
    QMap<AbstractToolManager::ToolManagerType, AbstractToolManager *> m_toolManagers;
466
    AbstractToolManager *m_currentToolManager;
467

468 469 470
    /** @brief Returns a clip from timeline
     *  @param pos a time value that is inside the clip
     *  @param track the track where the clip is in MLT coordinates */
471
    ClipItem *getClipItemAtMiddlePoint(int pos, int track);
472 473 474
    /** @brief Returns the higher clip at pos on the timeline
     *  @param pos a time value that is inside the clip */
    ClipItem *getUpperClipItemAt(int pos);
475 476
    /** @brief Returns a moved clip from timeline (means that the item was moved but its ItemInfo coordinates have not been updated yet)
     * */
Laurent Montel's avatar
Laurent Montel committed
477
    ClipItem *getMovedClipItem(const ItemInfo &info, GenTime offset, int trackOffset);
478 479 480
    /** @brief Returns a transition from timeline
     *  @param pos a time value that is inside the clip
     *  @param track the track where the clip is in MLT coordinates */
481 482
    Transition *getTransitionItemAt(int pos, int track, bool alreadyMoved = false);
    Transition *getTransitionItemAt(GenTime pos, int track, bool alreadyMoved = false);
483 484 485
    void checkScrolling();
    /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
    bool m_autoScroll;
486
    void displayContextMenu(QPoint pos, AbstractClipItem *clip);
487
    void displayKeyframesMenu(QPoint pos, AbstractClipItem *clip);
488 489 490
    QMenu *m_timelineContextMenu;
    QMenu *m_timelineContextClipMenu;
    QMenu *m_timelineContextTransitionMenu;
491 492
    QMenu *m_timelineContextKeyframeMenu;
    KSelectAction *m_selectKeyframeType;
493
    QAction *m_attachKeyframeToEnd;
494
    QMenu *m_markerMenu;
495
    QAction *m_autoTransition;
496
    QAction *m_pasteEffectsAction;
497
    QAction *m_ungroupAction;
498
    QAction *m_disableClipAction;
499 500
    QAction *m_editGuide;
    QAction *m_deleteGuide;
Laurent Montel's avatar
Laurent Montel committed
501 502
    QList<QAction *> m_audioActions;
    QList<QAction *> m_avActions;
503
    QActionGroup *m_clipTypeGroup;
504
    bool m_clipDrag;
505

506
    int m_findIndex;
507
    ProjectTool m_tool;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
508
    QCursor m_razorCursor;
509 510 511 512
    /** list containing items currently copied in the timeline */
    QList<AbstractClipItem *> m_copiedItems;
    /** Used to get the point in timeline where a context menu was opened */
    QPoint m_menuPosition;
513
    AbstractGroupItem *m_selectionGroup;
514
    int m_selectedTrack;
515

516
    QMutex m_selectionMutex;
517 518 519
    QMutex m_mutex;
    QWaitCondition m_producerNotReady;

Simon Eugster's avatar
Simon Eugster committed
520 521 522
    AudioCorrelation *m_audioCorrelator;
    ClipItem *m_audioAlignmentReference;

523
    void updatePositionEffects(ClipItem *item, const ItemInfo &info, bool standalone = true);
524
    bool insertDropClips(const QMimeData *mimeData, const QPoint &pos);
Laurent Montel's avatar
Laurent Montel committed
525
    bool canBePastedTo(const QList<ItemInfo> &infoList, int type) const;
Laurent Montel's avatar
Laurent Montel committed
526
    bool canBePasted(const QList<AbstractClipItem *> &items, GenTime offset, int trackOffset, QList<AbstractClipItem *>excluded = QList<AbstractClipItem *>()) const;
527
    ClipItem *getClipUnderCursor() const;
528
    AbstractClipItem *getMainActiveClip() const;
529 530 531 532
    /** Get available space for clip move (min and max free positions) */
    void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
    /** Get available space for transition move (min and max free positions) */
    void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
533
    /** Whether an item can be moved to a new position without colliding with similar items */
534
    bool itemCollision(AbstractClipItem *item, const ItemInfo &newPos);
535
    /** Selects all items in the scene rect, and sets ok to false if a group going over several tracks is found in it */
536
    QList<QGraphicsItem *> checkForGroups(const QRectF &rect, bool *ok);
537
    /** Adjust keyframes when pasted to another clip */
538
    void adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml);
539

540 541
    /** @brief Removes the tip and stops the animation timer. */
    void removeTipAnimation();
542

543 544 545 546 547
    /** @brief Adjusts effects after a clip resize.
     * @param item The item that was resized
     * @param oldInfo pre resize info
     * @param fromStart false = resize from end
     * @param command Used as a parent for EditEffectCommand */
Laurent Montel's avatar
Laurent Montel committed
548
    void adjustEffects(ClipItem *item, const ItemInfo &oldInfo, QUndoCommand *command);
549

550
    /** @brief Prepare an add clip command for an effect */
Laurent Montel's avatar
Laurent Montel committed
551
    void processEffect(ClipItem *item, const QDomElement &effect, int offset, QUndoCommand *effectCommand);
552 553
    /** @brief Reload all clips and transitions from MLT's playlist */
    void reloadTimeline();
554
    /** @brief Timeline selection changed, update effect stack. */
555
    void updateTimelineSelection();
556
    /** @brief Break groups containing an item in a locked track. */
Laurent Montel's avatar
Laurent Montel committed
557
    void breakLockedGroups(const QList<ItemInfo> &clipsToMove, const QList<ItemInfo> &transitionsToMove, QUndoCommand *masterCommand, bool doIt = true);
558 559
    void slotTrackUp();
    void slotTrackDown();
560

561 562
private slots:
    void slotRefreshGuides();
563 564
    void slotEditTimeLineGuide();
    void slotDeleteTimeLineGuide();
565
    void checkTrackSequence(int track);
566
    void slotGoToMarker(QAction *action);
567
    /** @brief Context menu is finished, prepare resetting las known menu pos. */
568
    void slotResetMenuPosition();
569 570
    /** @brief Context menu is finished, restore normal operation mode. */
    void slotContextMenuActivated();
571
    void slotDoResetMenuPosition();
572
    /** @brief A Filter job producer results. */
Laurent Montel's avatar
Laurent Montel committed
573
    void slotGotFilterJobResults(const QString &id, int startPos, int track, const stringMap &filterParams, const stringMap &extra);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
574 575
    /** @brief Replace a producer in all tracks (for example when proxying a clip). */
    void slotReplaceTimelineProducer(const QString &id);
576
    void slotPrepareTimelineReplacement(const QString &id);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
577 578
    /** @brief Update a producer in all tracks (for example when an effect changed). */
    void slotUpdateTimelineProducer(const QString &id);
579
    void slotEditKeyframeType(QAction *action);
580
    void slotAttachKeyframeToEnd(bool attach);
581
    void disableClip();
582 583
    void slotAcceptRipple(bool accept);
    void doRipple(bool accept);
584

585
signals:
586
    void cursorMoved(int, int);
587 588
    void zoomIn(bool zoomOnMouse);
    void zoomOut(bool zoomOnMouse);
589
    void mousePosition(int);
590 591 592
    /** @brief A clip was selected in timeline, update the effect stack
     *  @param clip The clip
     *  @param raise If true, the effect stack widget will be raised (come to front). */
593
    void clipItemSelected(ClipItem *clip, bool reloadStack = true);
594
    void transitionItemSelected(Transition *, int track = 0, QPoint p = QPoint(), bool update = false);
595
    void activateDocumentMonitor();
596
    void tracksChanged();
597
    void displayMessage(const QString &, MessageType);
598
    void doTrackLock(int, bool);
599
    void updateClipMarkers(ClipController *);
600
    void updateTrackHeaders();
601
    void playMonitor();
602
    void pauseMonitor();
603 604
    /** @brief Monitor document changes (for example the presence of audio data in timeline for export widget.*/
    void documentModified();
605
    void showTrackEffects(int, TrackInfo);
606 607
    /** @brief Update the track effect button that shows if a track has effects or not.*/
    void updateTrackEffectState(int);
608
    /** @brief Cursor position changed, repaint ruler.*/
609
    void updateRuler(int pos);
610
    /** @brief Send data from a clip to be imported as keyframes for effect / transition.*/
611
    void importKeyframes(GraphicsRectItem type, const QString &, const QString &);
612 613
    /** @brief Guides were changed, inform render widget*/
    void guidesUpdated();
614
    /** @brief Prepare importing and expand of a playlist clip */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
615
    void importPlaylistClips(const ItemInfo &info, const QString &url, QUndoCommand *expandCommand);
616
    /** @brief Show a specific frame in clip monitor */
617
    void showClipFrame(const QString &id, int frame);
618 619
    /** @brief Select active keyframe in effect stack */
    void setActiveKeyframe(int);
620
    void loadMonitorScene(MonitorSceneType, bool);
Laurent Montel's avatar
Laurent Montel committed
621
    void updateTrimMode(const QString &mode = QString());
622
    void setQmlProperty(const QString &, const QVariant &);
623 624 625
};

#endif
626