CuteLogger
Fast and simple logging solution for Qt based applications
timelinedock.h
1 /*
2  * Copyright (c) 2013-2021 Meltytech, LLC
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TIMELINEDOCK_H
19 #define TIMELINEDOCK_H
20 
21 #include <QDockWidget>
22 #include <QQuickWidget>
23 #include <QApplication>
24 #include "models/markersmodel.h"
25 #include "models/multitrackmodel.h"
26 #include "sharedframe.h"
27 
28 namespace Ui {
29 class TimelineDock;
30 }
31 namespace Timeline {
32 class UpdateCommand;
33 class TrimCommand;
34 }
35 class UndoHelper;
36 
37 class TimelineDock : public QDockWidget
38 {
39  Q_OBJECT
40  Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged)
41  Q_PROPERTY(int currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged)
42  Q_PROPERTY(QVariantList selection READ selectionForJS WRITE setSelectionFromJS NOTIFY selectionChanged)
43 
44 public:
45  explicit TimelineDock(QWidget *parent = 0);
46  ~TimelineDock();
47 
48  enum TrimLocation {
49  TrimInPoint,
50  TrimOutPoint
51  };
52 
53  MultitrackModel* model() { return &m_model; }
54  MarkersModel* markersModel() { return & m_markersModel; }
55  int position() const { return m_position; }
56  void setPosition(int position);
57  Mlt::ClipInfo* getClipInfo(int trackIndex, int clipIndex);
58  Mlt::Producer producerForClip(int trackIndex, int clipIndex);
59  int clipIndexAtPlayhead(int trackIndex = -1);
60  int clipIndexAtPosition(int trackIndex, int position);
61  void chooseClipAtPosition(int position, int& trackIndex, int& clipIndex);
62  void setCurrentTrack(int currentTrack);
63  int currentTrack() const;
64  int clipCount(int trackIndex) const;
65  void setSelectionFromJS(const QVariantList& list);
66  void setSelection(QList<QPoint> selection = QList<QPoint>(), int trackIndex = -1, bool isMultitrack = false);
67  QVariantList selectionForJS() const;
68  const QList<QPoint> selection() const;
69  const QVector<QUuid> selectionUuids();
70  void saveAndClearSelection();
71  void restoreSelection();
72  void selectClipUnderPlayhead();
73  int centerOfClip(int trackIndex, int clipIndex);
74  bool isTrackLocked(int trackIndex) const;
75  void trimClipAtPlayhead(TrimLocation location, bool ripple);
76  bool isRipple() const;
77  Q_INVOKABLE bool isMultitrackSelected() const { return m_selection.isMultitrackSelected; }
78  Q_INVOKABLE int selectedTrack() const { return m_selection.selectedTrack; }
79  Q_INVOKABLE bool isFloating() const { return QDockWidget::isFloating(); }
80  Q_INVOKABLE void copyToSource();
81  Q_INVOKABLE static void openProperties();
82  void emitSelectedChanged(const QVector<int> &roles);
83  void replaceClipsWithHash(const QString& hash, Mlt::Producer& producer);
84 
85 signals:
86  void currentTrackChanged();
87  void selectionChanged();
88  void seeked(int position);
89  void positionChanged();
90  void clipOpened(Mlt::Producer* producer);
91  void dragging(const QPointF& pos, int duration);
92  void dropped();
93  void dropAccepted(const QString &xml);
94  void fadeInChanged(int duration);
95  void fadeOutChanged(int duration);
96  void selected(Mlt::Producer* producer);
97  void clipClicked();
98  void showStatusMessage(QString);
99  void clipCopied();
100  void clipMoved(int fromTrack, int toTrack, int clipIndex, int position, bool ripple);
101  void filteredClicked();
102  void durationChanged();
103  void transitionAdded(int trackIndex, int clipIndex, int position, bool ripple);
104  void zoomIn();
105  void zoomOut();
106  void zoomToFit();
107  void resetZoom();
108  void makeTracksShorter();
109  void makeTracksTaller();
110  void markerRangesChanged();
111  void markerSeeked(int markerIndex);
112 
113 public slots:
114  void addAudioTrack();
115  void addVideoTrack();
116  void onShowFrame(const SharedFrame& frame);
117  void onSeeked(int position);
118  void append(int trackIndex);
119  void remove(int trackIndex, int clipIndex);
120  bool mergeClipWithNext(int trackIndex, int clipIndex, bool dryrun);
121  void lift(int trackIndex, int clipIndex);
122  void removeSelection(bool withCopy = false);
123  void liftSelection();
124  void incrementCurrentTrack(int by);
125  void selectTrackHead(int trackIndex);
126  void selectMultitrack();
127  void copy(int trackIndex, int clipIndex);
128  void setTrackName(int trackIndex, const QString& value);
129  void toggleTrackMute(int trackIndex);
130  void toggleTrackHidden(int trackIndex);
131  void setTrackComposite(int trackIndex, bool composite);
132  void setTrackLock(int trackIndex, bool lock);
133  bool moveClip(int fromTrack, int toTrack, int clipIndex, int position, bool ripple);
134  void onClipMoved(int fromTrack, int toTrack, int clipIndex, int position, bool ripple);
135  bool trimClipIn(int trackIndex, int clipIndex, int oldClipIndex, int delta, bool ripple);
136  bool trimClipOut(int trackIndex, int clipIndex, int delta, bool ripple);
137  void insert(int trackIndex, int position = -1, const QString &xml = QString(), bool seek = true);
138  void overwrite(int trackIndex, int position = -1, const QString &xml = QString(), bool seek = true);
139  void appendFromPlaylist(Mlt::Playlist* playlist, bool skipProxy);
140  void splitClip(int trackIndex = -1, int clipIndex = -1);
141  void fadeIn(int trackIndex, int clipIndex = -1, int duration = -1);
142  void fadeOut(int trackIndex, int clipIndex = -1, int duration = -1);
143  void seekPreviousEdit();
144  void seekNextEdit();
145  void seekInPoint(int clipIndex);
146  void clearSelectionIfInvalid();
147  void insertTrack();
148  void insertAudioTrack();
149  void insertVideoTrack();
150  void removeTrack();
151  void onProducerChanged(Mlt::Producer*);
152  void emitSelectedFromSelection();
153  void remakeAudioLevels(int trackIndex, int clipIndex, bool force = true);
154  void commitTrimCommand();
155  void onRowsInserted(const QModelIndex& parent, int first, int last);
156  void onRowsRemoved(const QModelIndex& parent, int first, int last);
157  void detachAudio(int trackIndex, int clipIndex);
158  void selectAll();
159  bool blockSelection(bool block);
160  void onProducerModified();
161  void replace(int trackIndex, int clipIndex, const QString& xml = QString());
162  void createOrEditMarker();
163  void createMarker();
164  void editMarker(int markerIndex);
165  void deleteMarker(int markerIndex = -1);
166  void seekNextMarker();
167  void seekPrevMarker();
168 
169 protected:
170  void dragEnterEvent(QDragEnterEvent* event);
171  void dragMoveEvent(QDragMoveEvent* event);
172  void dragLeaveEvent(QDragLeaveEvent* event);
173  void dropEvent(QDropEvent* event);
174  bool event(QEvent *event);
175  void keyPressEvent(QKeyEvent* event);
176  void keyReleaseEvent(QKeyEvent* event);
177 
178 private:
179  bool isBlank(int trackIndex, int clipIndex);
180  void pulseLockButtonOnTrack(int trackIndex);
181  void emitNonSeekableWarning();
182  void addTrackIfNeeded(int mltTrackIndex, Mlt::Producer* srcTrack);
183 
184  Ui::TimelineDock *ui;
185  QQuickWidget m_quickView;
186  MultitrackModel m_model;
187  MarkersModel m_markersModel;
188  int m_position;
189  QScopedPointer<Timeline::UpdateCommand> m_updateCommand;
190  bool m_ignoreNextPositionChange;
191  struct Selection {
192  QList<QPoint> selectedClips; // x is the clip index, y is the track index
193  int selectedTrack;
194  bool isMultitrackSelected;
195  };
196  Selection m_selection;
197  Selection m_savedSelection;
198  QScopedPointer<Timeline::TrimCommand> m_trimCommand;
199  QScopedPointer<UndoHelper> m_undoHelper;
200  int m_trimDelta;
201  int m_transitionDelta;
202  bool m_blockSetSelection;
203 
204 private slots:
205  void load(bool force = false);
206  void onTopLevelChanged(bool floating);
207  void onTransitionAdded(int trackIndex, int clipIndex, int position, bool ripple);
208  void selectClip(int trackIndex, int clipIndex);
209  void onMultitrackClosed();
210  void reloadTimelineMarkers();
211 };
212 
213 class TimelineSelectionBlocker
214 {
215 public:
216  TimelineSelectionBlocker(TimelineDock& timeline)
217  : m_timelineDock(timeline)
218  {
219  m_timelineDock.blockSelection(true);
220  }
221  ~TimelineSelectionBlocker()
222  {
223  QCoreApplication::processEvents();
224  m_timelineDock.blockSelection(false);
225  }
226 
227 private:
228  TimelineDock& m_timelineDock;
229 };
230 
231 #endif // TIMELINEDOCK_H
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:49