CuteLogger
Fast and simple logging solution for Qt based applications
timelinedock.h
1 /*
2  * Copyright (c) 2013-2019 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 zoomIn();
64  void zoomOut();
65  void resetZoom();
66  void makeTracksShorter();
67  void makeTracksTaller();
68  void setSelectionFromJS(const QVariantList& list);
69  void setSelection(QList<QPoint> selection = QList<QPoint>(), int trackIndex = -1, bool isMultitrack = false);
70  QVariantList selectionForJS() const;
71  QList<QPoint> selection() const;
72  void saveAndClearSelection();
73  void restoreSelection();
74  void selectClipUnderPlayhead();
75  int centerOfClip(int trackIndex, int clipIndex);
76  bool isTrackLocked(int trackIndex) const;
77  void trimClipAtPlayhead(TrimLocation location, bool ripple);
78  bool isRipple() const;
79  Q_INVOKABLE bool isMultitrackSelected() const { return m_selection.isMultitrackSelected; }
80  Q_INVOKABLE int selectedTrack() const { return m_selection.selectedTrack; }
81  Q_INVOKABLE bool isFloating() const { return QDockWidget::isFloating(); }
82  Q_INVOKABLE void copyToSource();
83  Q_INVOKABLE static void openProperties();
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 imageDurationChanged();
103  void transitionAdded(int trackIndex, int clipIndex, int position, bool ripple);
104 
105 public slots:
106  void addAudioTrack();
107  void addVideoTrack();
108  void onShowFrame(const SharedFrame& frame);
109  void onSeeked(int position);
110  void append(int trackIndex);
111  void remove(int trackIndex, int clipIndex);
112  bool mergeClipWithNext(int trackIndex, int clipIndex, bool dryrun);
113  void lift(int trackIndex, int clipIndex);
114  void removeSelection(bool withCopy = false);
115  void liftSelection();
116  void selectTrack(int by);
117  void selectTrackHead(int trackIndex);
118  void selectMultitrack();
119  void copyClip(int trackIndex, int clipIndex);
120  void setTrackName(int trackIndex, const QString& value);
121  void toggleTrackMute(int trackIndex);
122  void toggleTrackHidden(int trackIndex);
123  void setTrackComposite(int trackIndex, bool composite);
124  void setTrackLock(int trackIndex, bool lock);
125  bool moveClip(int fromTrack, int toTrack, int clipIndex, int position, bool ripple);
126  void onClipMoved(int fromTrack, int toTrack, int clipIndex, int position, bool ripple);
127  bool trimClipIn(int trackIndex, int clipIndex, int oldClipIndex, int delta, bool ripple);
128  bool trimClipOut(int trackIndex, int clipIndex, int delta, bool ripple);
129  void insert(int trackIndex, int position = -1, const QString &xml = QString(), bool seek = true);
130  void overwrite(int trackIndex, int position = -1, const QString &xml = QString(), bool seek = true);
131  void appendFromPlaylist(Mlt::Playlist* playlist);
132  void splitClip(int trackIndex = -1, int clipIndex = -1);
133  void fadeIn(int trackIndex, int clipIndex = -1, int duration = -1);
134  void fadeOut(int trackIndex, int clipIndex = -1, int duration = -1);
135  void seekPreviousEdit();
136  void seekNextEdit();
137  void seekInPoint(int clipIndex);
138  void clearSelectionIfInvalid();
139  void insertTrack();
140  void removeTrack();
141  void onProducerChanged(Mlt::Producer*);
142  void emitSelectedFromSelection();
143  void remakeAudioLevels(int trackIndex, int clipIndex, bool force = true);
144  void commitTrimCommand();
145  void onRowsInserted(const QModelIndex& parent, int first, int last);
146  void onRowsRemoved(const QModelIndex& parent, int first, int last);
147  void detachAudio(int trackIndex, int clipIndex);
148  void selectAll();
149  bool blockSelection(bool block);
150 
151 protected:
152  void dragEnterEvent(QDragEnterEvent* event);
153  void dragMoveEvent(QDragMoveEvent* event);
154  void dragLeaveEvent(QDragLeaveEvent* event);
155  void dropEvent(QDropEvent* event);
156  bool event(QEvent *event);
157  void keyPressEvent(QKeyEvent* event);
158  void keyReleaseEvent(QKeyEvent* event);
159 
160 private:
161  bool isBlank(int trackIndex, int clipIndex);
162  void pulseLockButtonOnTrack(int trackIndex);
163  bool findClipByUuid(const QUuid& uuid, int& trackIndex, int& clipIndex);
164 
165  Ui::TimelineDock *ui;
166  QQuickWidget m_quickView;
167  MultitrackModel m_model;
168  int m_position;
169  QScopedPointer<Timeline::UpdateCommand> m_updateCommand;
170  bool m_ignoreNextPositionChange;
171  struct Selection {
172  QList<QPoint> selectedClips; // x is the clip index, y is the track index
173  int selectedTrack;
174  bool isMultitrackSelected;
175  };
176  Selection m_selection;
177  Selection m_savedSelection;
178  QScopedPointer<Timeline::TrimCommand> m_trimCommand;
179  QScopedPointer<UndoHelper> m_undoHelper;
180  int m_trimDelta;
181  int m_transitionDelta;
182  bool m_blockSetSelection;
183 
184 private slots:
185  void load(bool force = false);
186  void onTopLevelChanged(bool floating);
187  void onTransitionAdded(int trackIndex, int clipIndex, int position, bool ripple);
188  void onInserted(int trackIndex, int clipIndex);
189  void onOverWritten(int trackIndex, int clipIndex);
190 };
191 
192 class TimelineSelectionBlocker
193 {
194 public:
195  TimelineSelectionBlocker(TimelineDock& timeline)
196  : m_timelineDock(timeline)
197  {
198  m_timelineDock.blockSelection(true);
199  }
200  ~TimelineSelectionBlocker()
201  {
202  QCoreApplication::processEvents();
203  m_timelineDock.blockSelection(false);
204  }
205 
206 private:
207  TimelineDock& m_timelineDock;
208 };
209 
210 #endif // TIMELINEDOCK_H
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48