Olive
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
timeline.h
Go to the documentation of this file.
1 /***
2 
3  Olive - Non-Linear Video Editor
4  Copyright (C) 2019 Olive Team
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 ***/
20 
21 #ifndef TIMELINE_H
22 #define TIMELINE_H
23 
24 #include <QVector>
25 #include <QTime>
26 #include <QPushButton>
27 
28 #include "ui/timelinewidget.h"
29 #include "ui/timelinetools.h"
30 #include "timeline/selection.h"
31 #include "timeline/clip.h"
33 #include "undo/undo.h"
34 #include "ui/timelineheader.h"
35 #include "ui/resizablescrollbar.h"
36 #include "ui/audiomonitor.h"
37 #include "ui/panel.h"
38 
46 };
47 
48 enum TrimType {
52 };
53 
54 namespace olive {
55  namespace timeline {
56  const int kGhostThickness = 2;
57  const int kClipTextPadding = 3;
58 
68 
69  extern int kTrackDefaultHeight;
70  extern int kTrackMinHeight;
71  extern int kTrackHeightIncrement;
72  }
73 }
74 
75 int getScreenPointFromFrame(double zoom, long frame);
76 long getFrameFromScreenPoint(double zoom, int x);
77 bool selection_contains_transition(const Selection& s, Clip *c, int type);
78 void ripple_clips(ComboAction *ca, Sequence *s, long point, long length, const QVector<int>& ignore = QVector<int>());
79 
80 struct Ghost {
81  int clip;
82  long in;
83  long out;
84  int track;
85  long clip_in;
86 
87  long old_in;
88  long old_out;
89  int old_track;
91 
92  // importing variables
95 
96  // other variables
100 
101  // transition trimming
103 };
104 
105 class Timeline : public Panel
106 {
107  Q_OBJECT
108 public:
109  explicit Timeline(QWidget *parent = nullptr);
110  virtual ~Timeline() override;
111 
112  bool focused();
113  void multiply_zoom(double m);
114  void copy(bool del);
115  ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame);
116  ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in);
117  bool split_selection(ComboAction* ca);
118  bool split_all_clips_at_point(ComboAction *ca, long point);
119  bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink);
120  void split_clip_at_positions(ComboAction* ca, int clip_index, QVector<long> positions);
121  void clean_up_selections(QVector<Selection>& areas);
122  void deselect_area(long in, long out, int track);
123  void delete_areas_and_relink(ComboAction *ca, QVector<Selection>& areas, bool deselect_areas);
124  void relink_clips_using_ids(QVector<int>& old_clips, QVector<ClipPtr>& new_clips);
125  void update_sequence();
126 
127  void edit_to_point_internal(bool in, bool ripple);
128  void delete_in_out_internal(bool ripple);
129 
130  void create_ghosts_from_media(Sequence *seq, long entry_point, QVector<olive::timeline::MediaImportData> &media_list);
132 
133  int getTimelineScreenPointFromFrame(long frame);
135  int getDisplayScreenPointFromFrame(long frame);
136  long getDisplayFrameFromScreenPoint(int x);
137 
138  int get_snap_range();
139  bool snap_to_point(long point, long* l);
140  bool snap_to_timeline(long* l, bool use_playhead, bool use_markers, bool use_workarea);
141  void set_marker();
142 
143  // shared information
144  int tool;
147  double zoom;
151  void update_effect_controls();
153  double old_zoom;
154 
155  int GetTrackHeight(int track);
156  void SetTrackHeight(int track, int height);
157 
158  // snapping
159  bool snapping;
160  bool snapped;
162 
163  // selecting functions
164  bool selecting;
166  void delete_selection(QVector<Selection> &selections, bool ripple);
167  void select_all();
171 
172  // moving
175  QVector<Ghost> ghosts;
179 
180  // trimming
184 
185  // splitting
186  bool splitting;
187  QVector<int> split_tracks;
188  QVector<int> split_cache;
189 
190  // importing
191  bool importing;
193 
194  // creating variables
195  bool creating;
197 
198  // transition variables
205 
206  // hand tool variables
210 
212 
216 
217  QPushButton* toolArrowButton;
218  QPushButton* toolEditButton;
219  QPushButton* toolRippleButton;
220  QPushButton* toolRazorButton;
221  QPushButton* toolSlipButton;
222  QPushButton* toolSlideButton;
223  QPushButton* toolHandButton;
224  QPushButton* toolTransitionButton;
225  QPushButton* snappingButton;
226 
227  void scroll_to_frame(long frame);
228  void select_from_playhead();
229 
230  bool can_ripple_empty_space(long frame, int track);
231 
232  virtual void Retranslate() override;
233 protected:
234  virtual void resizeEvent(QResizeEvent *event) override;
235 public slots:
236  void paste(bool insert = false);
237  void repaint_timeline();
238  void toggle_show_all();
239  void deselect();
240  void toggle_links();
241  void split_at_playhead();
242  void ripple_delete();
245 
246  void delete_inout();
247  void ripple_delete_inout();
248 
249  void ripple_to_in_point();
250  void ripple_to_out_point();
251  void edit_to_in_point();
252  void edit_to_out_point();
253 
254  void IncreaseTrackHeight();
255  void DecreaseTrackHeight();
256 
257  void previous_cut();
258  void next_cut();
259 
260  void add_transition();
261 
262  void nest();
263 
264  void zoom_in();
265  void zoom_out();
266 
267 private slots:
268  void snapping_clicked(bool checked);
269  void add_btn_click();
270  void add_menu_item(QAction*);
271  void setScroll(int);
272  void record_btn_click();
273  void transition_tool_click();
274  void transition_menu_select(QAction*);
275  void resize_move(double d);
276  void set_tool();
277 
278 private:
279  void ChangeTrackHeightUniformly(int diff);
280  void set_zoom_value(double v);
281  QVector<QPushButton*> tool_buttons;
282  void decheck_tool_buttons(QObject* sender);
283  void set_tool(int tool);
284  int scroll;
285  void set_sb_max();
286  void UpdateTitle();
287 
288  void setup_ui();
289 
290  // ripple delete empty space variables
293 
294  QVector<TimelineTrackHeight> track_heights;
295 
296  QWidget* timeline_area;
299  QWidget* editAreas;
300  QScrollBar* videoScrollbar;
301  QScrollBar* audioScrollbar;
302  QPushButton* zoomInButton;
303  QPushButton* zoomOutButton;
304  QPushButton* recordButton;
305  QPushButton* addButton;
307 };
308 
309 #endif // TIMELINE_H
void edit_to_out_point()
Definition: timeline.cpp:1768
TimelineWidget * audio_area
Definition: timeline.h:298
Definition: panel.h:26
QPushButton * toolHandButton
Definition: timeline.h:223
void zoom_out()
Definition: timeline.cpp:882
void paste(bool insert=false)
Definition: timeline.cpp:1255
int tool
Definition: timeline.h:144
int transition_select
Definition: timeline.h:183
int scroll
Definition: timeline.h:284
void next_cut()
Definition: timeline.cpp:206
void update_effect_controls()
Definition: selection.h:24
const EffectMeta * transition_tool_meta
Definition: timeline.h:203
int getDisplayScreenPointFromFrame(long frame)
bool audio_ghosts
Definition: timeline.h:177
Definition: timeline.h:45
virtual ~Timeline() override
Definition: timeline.cpp:121
QScrollBar * audioScrollbar
Definition: timeline.h:301
TimelineHeader * headers
Definition: timeline.h:213
void ripple_delete_empty_space()
Definition: timeline.cpp:682
void relink_clips_using_ids(QVector< int > &old_clips, QVector< ClipPtr > &new_clips)
Definition: timeline.cpp:1238
long out
Definition: timeline.h:83
const int kGhostThickness
Definition: timeline.h:56
int creating_object
Definition: timeline.h:196
TrimType trim_type
Definition: timeline.h:182
void ripple_delete_inout()
Definition: timeline.cpp:1752
void ripple_to_in_point()
Definition: timeline.cpp:1756
QPushButton * toolSlipButton
Definition: timeline.h:221
bool move_insert
Definition: timeline.h:178
Definition: timeline.h:50
void multiply_zoom(double m)
Definition: timeline.cpp:867
int drag_track_start
Definition: timeline.h:150
QPushButton * toolTransitionButton
Definition: timeline.h:224
QWidget * timeline_area
Definition: timeline.h:296
bool importing
Definition: timeline.h:191
bool snap_to_timeline(long *l, bool use_playhead, bool use_markers, bool use_workarea)
Definition: timeline.cpp:1666
QPushButton * toolSlideButton
Definition: timeline.h:222
int drag_y_start
Definition: timeline.h:209
void create_ghosts_from_media(Sequence *seq, long entry_point, QVector< olive::timeline::MediaImportData > &media_list)
Definition: timeline.cpp:242
void SetTrackHeight(int track, int height)
Definition: timeline.cpp:895
long in
Definition: timeline.h:82
bool selection_contains_transition(const Selection &s, Clip *c, int type)
Definition: timeline.cpp:1094
QWidget * editAreas
Definition: timeline.h:299
bool zoom_just_changed
Definition: timeline.h:148
Media * media
Definition: timeline.h:93
long snap_point
Definition: timeline.h:161
bool rect_select_proc
Definition: timeline.h:169
std::shared_ptr< Clip > ClipPtr
Definition: clip.h:52
void add_btn_click()
Definition: timeline.cpp:1822
ClipPtr split_clip(ComboAction *ca, bool transitions, int p, long frame)
Definition: timeline.cpp:936
QPushButton * zoomOutButton
Definition: timeline.h:303
void resize_move(double d)
Definition: timeline.cpp:1930
QPushButton * recordButton
Definition: timeline.h:304
bool hand_moving
Definition: timeline.h:207
void add_transition()
Definition: timeline.cpp:432
bool creating
Definition: timeline.h:195
int old_track
Definition: timeline.h:89
void delete_inout()
Definition: timeline.cpp:1748
long getDisplayFrameFromScreenPoint(int x)
QVector< int > split_cache
Definition: timeline.h:188
void scroll_to_frame(long frame)
Definition: timeline.cpp:634
QRect rect_select_rect
Definition: timeline.h:170
void record_btn_click()
Definition: timeline.cpp:1868
Definition: timeline.h:105
void add_clips_from_ghosts(ComboAction *ca, Sequence *s)
Definition: timeline.cpp:364
double old_zoom
Definition: timeline.h:153
long old_clip_in
Definition: timeline.h:90
QPushButton * snappingButton
Definition: timeline.h:225
bool snapping
Definition: timeline.h:159
TrimType trim_type
Definition: timeline.h:99
int GetTrackHeight(int track)
Definition: timeline.cpp:886
void setScroll(int)
Definition: timeline.cpp:1862
void MultiplyTrackSizesByDPI()
Set default track sizes.
Definition: timeline.cpp:2149
bool selecting
Definition: timeline.h:164
Definition: timeline.h:40
void split_clip_at_positions(ComboAction *ca, int clip_index, QVector< long > positions)
Definition: timeline.cpp:141
void add_menu_item(QAction *)
Definition: timeline.cpp:1857
bool split_selection(ComboAction *ca)
Definition: timeline.cpp:1510
bool splitting
Definition: timeline.h:186
Definition: timeline.h:44
double zoom
Definition: timeline.h:147
Definition: clip.h:56
void set_marker()
Definition: timeline.cpp:1715
void split_at_playhead()
Definition: timeline.cpp:1569
long getFrameFromScreenPoint(double zoom, int x)
Definition: timeline.cpp:1802
Definition: timeline.h:51
QScrollBar * videoScrollbar
Definition: timeline.h:300
ResizableScrollBar * horizontalScrollBar
Definition: timeline.h:215
void snapping_clicked(bool checked)
Definition: timeline.cpp:932
int transition_tool_side
Definition: timeline.h:204
QPushButton * toolRippleButton
Definition: timeline.h:219
void ripple_delete()
Definition: timeline.cpp:1613
QPushButton * toolEditButton
Definition: timeline.h:218
void zoom_in()
Definition: timeline.cpp:878
QPushButton * addButton
Definition: timeline.h:305
The ComboAction class.
Definition: comboaction.h:19
void clean_up_selections(QVector< Selection > &areas)
Definition: timeline.cpp:1064
Definition: timeline.h:49
void nest()
Definition: timeline.cpp:468
int clip
Definition: timeline.h:81
bool split_all_clips_at_point(ComboAction *ca, long point)
Definition: timeline.cpp:1555
bool showing_all
Definition: timeline.h:152
int media_stream
Definition: timeline.h:94
long old_out
Definition: timeline.h:88
Definition: effect.h:52
void toggle_show_all()
Definition: timeline.cpp:230
void transition_menu_select(QAction *)
Definition: timeline.cpp:1915
void delete_in_out_internal(bool ripple)
Definition: timeline.cpp:726
const int kClipTextPadding
Definition: timeline.h:57
long old_in
Definition: timeline.h:87
void delete_selection(QVector< Selection > &selections, bool ripple)
Definition: timeline.cpp:773
Definition: media.h:45
void setup_ui()
Definition: timeline.cpp:1948
long getTimelineFrameFromScreenPoint(int x)
Definition: timeline.cpp:1814
Definition: timeline.h:43
void deselect_area(long in, long out, int track)
Definition: timeline.cpp:1625
bool rect_select_init
Definition: timeline.h:168
Definition: timeline.h:42
QVector< Ghost > ghosts
Definition: timeline.h:175
void ripple_to_out_point()
Definition: timeline.cpp:1760
long rc_ripple_min
Definition: timeline.h:291
QPushButton * toolRazorButton
Definition: timeline.h:220
The AudioMonitor class.
Definition: audiomonitor.h:32
long cursor_frame
Definition: timeline.h:145
int transition_tool_open_clip
Definition: timeline.h:201
bool focused()
Definition: timeline.cpp:575
void ChangeTrackHeightUniformly(int diff)
Definition: timeline.cpp:910
bool snapped
Definition: timeline.h:160
void edit_to_in_point()
Definition: timeline.cpp:1764
QPushButton * zoomInButton
Definition: timeline.h:302
std::shared_ptr< Transition > TransitionPtr
Definition: transition.h:42
long media_length
Definition: timeline.h:98
Definition: timeline.h:41
void DecreaseTrackHeight()
Definition: timeline.cpp:928
int getScreenPointFromFrame(double zoom, long frame)
Definition: timeline.cpp:1810
void select_from_playhead()
Definition: timeline.cpp:638
void set_zoom_value(double v)
Definition: timeline.cpp:843
CreateObjects
Definition: timeline.h:39
int selection_offset
Definition: timeline.h:165
int kTrackMinHeight
Definition: timeline.cpp:59
void decheck_tool_buttons(QObject *sender)
Definition: timeline.cpp:872
QVector< TimelineTrackHeight > track_heights
Definition: timeline.h:294
void ripple_clips(ComboAction *ca, Sequence *s, long point, long length, const QVector< int > &ignore)
Definition: timeline.cpp:226
long rc_ripple_max
Definition: timeline.h:292
int trim_target
Definition: timeline.h:181
int get_snap_range()
Definition: timeline.cpp:571
bool importing_files
Definition: timeline.h:192
Definition: timelinewidget.h:48
TrimType
Definition: timeline.h:48
int cursor_track
Definition: timeline.h:146
QWidget * tool_button_widget
Definition: timeline.h:306
void update_sequence()
Definition: timeline.cpp:555
void previous_cut()
Definition: timeline.cpp:188
int track
Definition: timeline.h:84
QPushButton * toolArrowButton
Definition: timeline.h:217
Definition: timeline.h:80
int kTrackDefaultHeight
Definition: timeline.cpp:58
int getTimelineScreenPointFromFrame(long frame)
Definition: timeline.cpp:1818
bool can_ripple_empty_space(long frame, int track)
Definition: timeline.cpp:654
QVector< int > split_tracks
Definition: timeline.h:187
Timeline(QWidget *parent=nullptr)
Definition: timeline.cpp:62
void deselect()
Definition: timeline.cpp:1797
void toggle_enable_on_selected_clips()
Definition: timeline.cpp:750
void repaint_timeline()
Definition: timeline.cpp:579
void delete_areas_and_relink(ComboAction *ca, QVector< Selection > &areas, bool deselect_areas)
Definition: timeline.cpp:1108
int drag_x_start
Definition: timeline.h:208
Definition: resizablescrollbar.h:26
void set_tool()
Definition: timeline.cpp:2129
int transition_tool_close_clip
Definition: timeline.h:202
virtual void resizeEvent(QResizeEvent *event) override
Definition: timeline.cpp:695
bool transition_tool_proc
Definition: timeline.h:200
virtual void Retranslate() override
Definition: timeline.cpp:123
long ghost_length
Definition: timeline.h:97
void copy(bool del)
Definition: timeline.cpp:1179
TransitionPtr transition
Definition: timeline.h:102
QVector< QPushButton * > tool_buttons
Definition: timeline.h:281
void transition_tool_click()
Definition: timeline.cpp:1883
void select_all()
Definition: timeline.cpp:617
long drag_frame_start
Definition: timeline.h:149
Definition: sequence.h:31
void edit_to_point_internal(bool in, bool ripple)
Definition: timeline.cpp:1399
Definition: timelineheader.h:31
int kTrackHeightIncrement
Definition: timeline.cpp:60
long clip_in
Definition: timeline.h:85
TimelineWidget * video_area
Definition: timeline.h:297
bool moving_init
Definition: timeline.h:173
bool video_ghosts
Definition: timeline.h:176
bool transition_tool_init
Definition: timeline.h:199
void set_sb_max()
Definition: timeline.cpp:1934
bool moving_proc
Definition: timeline.h:174
bool block_repaints
Definition: timeline.h:211
void UpdateTitle()
Definition: timeline.cpp:1938
void IncreaseTrackHeight()
Definition: timeline.cpp:924
bool split_clip_and_relink(ComboAction *ca, int clip, long frame, bool relink)
Definition: timeline.cpp:1013
bool snap_to_point(long point, long *l)
Definition: timeline.cpp:1655
void toggle_links()
Definition: timeline.cpp:1772
AudioMonitor * audio_monitor
Definition: timeline.h:214