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