Olive
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 "project/selection.h"
31 #include "project/clip.h"
32 #include "project/undo.h"
33 #include "ui/timelineheader.h"
34 #include "ui/resizablescrollbar.h"
35 #include "ui/audiomonitor.h"
36 #include "ui/panel.h"
37 
45 };
46 
47 enum TrimType {
51 };
52 
53 bool is_clip_selected(ClipPtr clip, bool containing);
54 int getScreenPointFromFrame(double zoom, long frame);
55 long getFrameFromScreenPoint(double zoom, int x);
56 bool selection_contains_transition(const Selection& s, ClipPtr c, int type);
57 void move_clip(ComboAction *ca, ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions = true, bool relative = false);
58 void ripple_clips(ComboAction *ca, SequencePtr s, long point, long length, const QVector<int>& ignore = QVector<int>());
59 
60 struct Ghost {
61  int clip;
62  long in;
63  long out;
64  int track;
65  long clip_in;
66 
67  long old_in;
68  long old_out;
69  int old_track;
71 
72  // importing variables
75 
76  // other variables
80 
81  // transition trimming
83 };
84 
85 class Timeline : public Panel
86 {
87  Q_OBJECT
88 public:
89  explicit Timeline(QWidget *parent = nullptr);
90  virtual ~Timeline() override;
91 
92  bool focused();
93  void multiply_zoom(double m);
94  void copy(bool del);
95  ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame);
96  ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in);
97  bool split_selection(ComboAction* ca);
98  bool split_all_clips_at_point(ComboAction *ca, long point);
99  bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink);
100  void clean_up_selections(QVector<Selection>& areas);
101  void deselect_area(long in, long out, int track);
102  void delete_areas_and_relink(ComboAction *ca, QVector<Selection>& areas, bool deselect_areas);
103  void relink_clips_using_ids(QVector<int>& old_clips, QVector<ClipPtr>& new_clips);
104  void update_sequence();
105 
106  void edit_to_point_internal(bool in, bool ripple);
107  void delete_in_out_internal(bool ripple);
108 
109  void create_ghosts_from_media(SequencePtr seq, long entry_point, QVector<Media *> &media_list);
111 
112  int getTimelineScreenPointFromFrame(long frame);
114  int getDisplayScreenPointFromFrame(long frame);
115  long getDisplayFrameFromScreenPoint(int x);
116 
117  int get_snap_range();
118  bool snap_to_point(long point, long* l);
119  bool snap_to_timeline(long* l, bool use_playhead, bool use_markers, bool use_workarea);
120  void set_marker();
121 
122  // shared information
123  int tool;
126  double zoom;
130  void update_effect_controls();
132  double old_zoom;
133 
134  int GetTrackHeight(int track);
135  void SetTrackHeight(int track, int height);
136 
137  // snapping
138  bool snapping;
139  bool snapped;
141 
142  // selecting functions
143  bool selecting;
145  void delete_selection(QVector<Selection> &selections, bool ripple);
146  void select_all();
150 
151  // moving
154  QVector<Ghost> ghosts;
158 
159  // trimming
163 
164  // splitting
165  bool splitting;
166  QVector<int> split_tracks;
167  QVector<int> split_cache;
168 
169  // importing
170  bool importing;
172 
173  // creating variables
174  bool creating;
176 
177  // transition variables
184 
185  // hand tool variables
189 
191 
195 
196  QPushButton* toolArrowButton;
197  QPushButton* toolEditButton;
198  QPushButton* toolRippleButton;
199  QPushButton* toolRazorButton;
200  QPushButton* toolSlipButton;
201  QPushButton* toolSlideButton;
202  QPushButton* toolHandButton;
203  QPushButton* toolTransitionButton;
204  QPushButton* snappingButton;
205 
206  void scroll_to_frame(long frame);
207  void select_from_playhead();
208 
209  bool can_ripple_empty_space(long frame, int track);
210 
211 protected:
212  virtual void resizeEvent(QResizeEvent *event) override;
213  virtual void Retranslate() override;
214 public slots:
215  void paste(bool insert = false);
216  void repaint_timeline();
217  void toggle_show_all();
218  void deselect();
219  void toggle_links();
220  void split_at_playhead();
221  void ripple_delete();
224 
225  void delete_inout();
226  void ripple_delete_inout();
227 
228  void ripple_to_in_point();
229  void ripple_to_out_point();
230  void edit_to_in_point();
231  void edit_to_out_point();
232 
233  void IncreaseTrackHeight();
234  void DecreaseTrackHeight();
235 
236  void previous_cut();
237  void next_cut();
238 
239  void add_transition();
240 
241  void nest();
242 
243  void zoom_in();
244  void zoom_out();
245 
246 private slots:
247  void snapping_clicked(bool checked);
248  void add_btn_click();
249  void add_menu_item(QAction*);
250  void setScroll(int);
251  void record_btn_click();
252  void transition_tool_click();
253  void transition_menu_select(QAction*);
254  void resize_move(double d);
255  void set_tool();
256 
257 private:
258  void set_zoom_value(double v);
259  QVector<QPushButton*> tool_buttons;
260  void decheck_tool_buttons(QObject* sender);
261  void set_tool(int tool);
262  int scroll;
263  void set_sb_max();
264  void UpdateTitle();
265 
266  void setup_ui();
267 
268  // ripple delete empty space variables
271 
272  QVector<TimelineTrackHeight> track_heights;
273 
274  QWidget* timeline_area;
277  QWidget* editAreas;
278  QScrollBar* videoScrollbar;
279  QScrollBar* audioScrollbar;
280  QPushButton* zoomInButton;
281  QPushButton* zoomOutButton;
282  QPushButton* recordButton;
283  QPushButton* addButton;
285 };
286 
287 #endif // TIMELINE_H
virtual void Retranslate() override
Definition: timeline.cpp:118
bool can_ripple_empty_space(long frame, int track)
Definition: timeline.cpp:570
TrimType trim_type
Definition: timeline.h:161
void ripple_delete_inout()
Definition: timeline.cpp:1656
bool is_clip_selected(ClipPtr clip, bool containing)
Definition: timeline.cpp:827
void add_clips_from_ghosts(ComboAction *ca, SequencePtr s)
Definition: timeline.cpp:295
void select_from_playhead()
Definition: timeline.cpp:554
void ripple_clips(ComboAction *ca, SequencePtr s, long point, long length, const QVector< int > &ignore=QVector< int >())
Definition: timeline.cpp:174
bool showing_all
Definition: timeline.h:131
void toggle_show_all()
Definition: timeline.cpp:178
bool video_ghosts
Definition: timeline.h:155
double old_zoom
Definition: timeline.h:132
void set_sb_max()
Definition: timeline.cpp:1838
void transition_menu_select(QAction *)
Definition: timeline.cpp:1819
int transition_tool_side
Definition: timeline.h:183
TimelineWidget * video_area
Definition: timeline.h:275
void decheck_tool_buttons(QObject *sender)
Definition: timeline.cpp:774
void ripple_to_in_point()
Definition: timeline.cpp:1660
bool transition_tool_proc
Definition: timeline.h:179
Definition: selection.h:24
Definition: timeline.h:44
const EffectMeta * transition_tool_meta
Definition: timeline.h:182
void set_tool()
Definition: timeline.cpp:2104
long in
Definition: timeline.h:62
long getFrameFromScreenPoint(double zoom, int x)
Definition: timeline.cpp:1706
QRect rect_select_rect
Definition: timeline.h:149
bool selecting
Definition: timeline.h:143
void toggle_links()
Definition: timeline.cpp:1676
QVector< int > split_cache
Definition: timeline.h:167
QWidget * tool_button_widget
Definition: timeline.h:284
void repaint_timeline()
Definition: timeline.cpp:495
void create_ghosts_from_media(SequencePtr seq, long entry_point, QVector< Media * > &media_list)
Definition: timeline.cpp:190
QPushButton * zoomOutButton
Definition: timeline.h:281
bool focused()
Definition: timeline.cpp:491
int selection_offset
Definition: timeline.h:144
bool transition_tool_init
Definition: timeline.h:178
void resize_move(double d)
Definition: timeline.cpp:1834
bool selection_contains_transition(const Selection &s, ClipPtr c, int type)
Definition: timeline.cpp:1000
void add_menu_item(QAction *)
Definition: timeline.cpp:1761
Definition: timeline.h:49
void nest()
Definition: timeline.cpp:409
int clip
Definition: timeline.h:61
bool snapped
Definition: timeline.h:139
long old_out
Definition: timeline.h:68
QPushButton * toolEditButton
Definition: timeline.h:197
void record_btn_click()
Definition: timeline.cpp:1772
The ComboAction class.
Definition: comboaction.h:19
void scroll_to_frame(long frame)
Definition: timeline.cpp:550
QPushButton * zoomInButton
Definition: timeline.h:280
QVector< TimelineTrackHeight > track_heights
Definition: timeline.h:272
bool creating
Definition: timeline.h:174
int old_track
Definition: timeline.h:69
Definition: audiomonitor.h:27
void ripple_delete()
Definition: timeline.cpp:1517
void UpdateTitle()
Definition: timeline.cpp:1842
void edit_to_in_point()
Definition: timeline.cpp:1668
int drag_y_start
Definition: timeline.h:188
long rc_ripple_max
Definition: timeline.h:270
AudioMonitor * audio_monitor
Definition: timeline.h:193
Definition: effect.h:50
bool moving_proc
Definition: timeline.h:153
Definition: timelinewidget.h:59
virtual ~Timeline() override
Definition: timeline.cpp:116
long getDisplayFrameFromScreenPoint(int x)
Definition: timeline.h:85
long old_clip_in
Definition: timeline.h:70
void toggle_enable_on_selected_clips()
Definition: timeline.cpp:663
void SetTrackHeight(int track, int height)
Definition: timeline.cpp:797
void delete_areas_and_relink(ComboAction *ca, QVector< Selection > &areas, bool deselect_areas)
Definition: timeline.cpp:1014
void transition_tool_click()
Definition: timeline.cpp:1787
void clean_up_selections(QVector< Selection > &areas)
Definition: timeline.cpp:970
QWidget * timeline_area
Definition: timeline.h:274
void edit_to_out_point()
Definition: timeline.cpp:1672
Definition: timelineheader.h:31
QPushButton * recordButton
Definition: timeline.h:282
long rc_ripple_min
Definition: timeline.h:269
int transition_select
Definition: timeline.h:162
void zoom_in()
Definition: timeline.cpp:780
Definition: media.h:42
bool snapping
Definition: timeline.h:138
Media * media
Definition: timeline.h:73
std::shared_ptr< Clip > ClipPtr
Definition: cacher.h:28
QScrollBar * audioScrollbar
Definition: timeline.h:279
Definition: timeline.h:39
void paste(bool insert=false)
Definition: timeline.cpp:1158
void delete_in_out_internal(bool ripple)
Definition: timeline.cpp:642
long clip_in
Definition: timeline.h:65
void edit_to_point_internal(bool in, bool ripple)
Definition: timeline.cpp:1305
int media_stream
Definition: timeline.h:74
QPushButton * toolSlipButton
Definition: timeline.h:200
int transition_tool_close_clip
Definition: timeline.h:181
Definition: timeline.h:43
void previous_cut()
Definition: timeline.cpp:136
bool block_repaints
Definition: timeline.h:190
bool moving_init
Definition: timeline.h:152
int GetTrackHeight(int track)
Definition: timeline.cpp:788
bool split_clip_and_relink(ComboAction *ca, int clip, long frame, bool relink)
Definition: timeline.cpp:919
Definition: panel.h:26
Definition: timeline.h:50
QPushButton * toolRippleButton
Definition: timeline.h:198
int transition_tool_open_clip
Definition: timeline.h:180
bool rect_select_init
Definition: timeline.h:147
QPushButton * toolSlideButton
Definition: timeline.h:201
int getScreenPointFromFrame(double zoom, long frame)
Definition: timeline.cpp:1714
bool splitting
Definition: timeline.h:165
int track
Definition: timeline.h:64
int cursor_track
Definition: timeline.h:125
Definition: timeline.h:48
int scroll
Definition: timeline.h:262
void update_sequence()
Definition: timeline.cpp:471
int get_snap_range()
Definition: timeline.cpp:487
void set_marker()
Definition: timeline.cpp:1619
long getTimelineFrameFromScreenPoint(int x)
Definition: timeline.cpp:1718
QVector< QPushButton * > tool_buttons
Definition: timeline.h:259
int trim_target
Definition: timeline.h:160
int tool
Definition: timeline.h:123
Timeline(QWidget *parent=nullptr)
Definition: timeline.cpp:57
TrimType trim_type
Definition: timeline.h:79
void delete_inout()
Definition: timeline.cpp:1652
Definition: timeline.h:42
QVector< Ghost > ghosts
Definition: timeline.h:154
void ripple_to_out_point()
Definition: timeline.cpp:1664
Definition: timeline.h:41
long media_length
Definition: timeline.h:78
QWidget * editAreas
Definition: timeline.h:277
int creating_object
Definition: timeline.h:175
void DecreaseTrackHeight()
Definition: timeline.cpp:819
int drag_track_start
Definition: timeline.h:129
long ghost_length
Definition: timeline.h:77
double zoom
Definition: timeline.h:126
std::shared_ptr< Transition > TransitionPtr
Definition: transition.h:42
bool move_insert
Definition: timeline.h:157
void zoom_out()
Definition: timeline.cpp:784
void deselect_area(long in, long out, int track)
Definition: timeline.cpp:1529
bool importing
Definition: timeline.h:170
Definition: timeline.h:40
TimelineWidget * audio_area
Definition: timeline.h:276
long out
Definition: timeline.h:63
std::shared_ptr< Sequence > SequencePtr
Definition: clip.h:48
CreateObjects
Definition: timeline.h:38
bool hand_moving
Definition: timeline.h:186
QPushButton * toolHandButton
Definition: timeline.h:202
ClipPtr split_clip(ComboAction *ca, bool transitions, int p, long frame)
Definition: timeline.cpp:842
int drag_x_start
Definition: timeline.h:187
long old_in
Definition: timeline.h:67
void update_effect_controls()
TrimType
Definition: timeline.h:47
void select_all()
Definition: timeline.cpp:533
Definition: resizablescrollbar.h:26
void set_zoom_value(double v)
Definition: timeline.cpp:746
Definition: timeline.h:60
void next_cut()
Definition: timeline.cpp:154
long drag_frame_start
Definition: timeline.h:128
QPushButton * toolArrowButton
Definition: timeline.h:196
bool split_selection(ComboAction *ca)
Definition: timeline.cpp:1414
bool rect_select_proc
Definition: timeline.h:148
void move_clip(ComboAction *ca, ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions=true, bool relative=false)
Definition: timeline.cpp:2072
QScrollBar * videoScrollbar
Definition: timeline.h:278
void relink_clips_using_ids(QVector< int > &old_clips, QVector< ClipPtr > &new_clips)
Definition: timeline.cpp:1141
void add_btn_click()
Definition: timeline.cpp:1726
void delete_selection(QVector< Selection > &selections, bool ripple)
Definition: timeline.cpp:683
void setScroll(int)
Definition: timeline.cpp:1766
int getTimelineScreenPointFromFrame(long frame)
Definition: timeline.cpp:1722
long cursor_frame
Definition: timeline.h:124
bool split_all_clips_at_point(ComboAction *ca, long point)
Definition: timeline.cpp:1459
bool audio_ghosts
Definition: timeline.h:156
void copy(bool del)
Definition: timeline.cpp:1083
QPushButton * snappingButton
Definition: timeline.h:204
QPushButton * toolRazorButton
Definition: timeline.h:199
void multiply_zoom(double m)
Definition: timeline.cpp:769
TimelineHeader * headers
Definition: timeline.h:192
TransitionPtr transition
Definition: timeline.h:82
ResizableScrollBar * horizontalScrollBar
Definition: timeline.h:194
int getDisplayScreenPointFromFrame(long frame)
virtual void resizeEvent(QResizeEvent *event) override
Definition: timeline.cpp:611
bool snap_to_timeline(long *l, bool use_playhead, bool use_markers, bool use_workarea)
Definition: timeline.cpp:1570
void snapping_clicked(bool checked)
Definition: timeline.cpp:838
bool importing_files
Definition: timeline.h:171
long snap_point
Definition: timeline.h:140
void ripple_delete_empty_space()
Definition: timeline.cpp:598
bool snap_to_point(long point, long *l)
Definition: timeline.cpp:1559
void setup_ui()
Definition: timeline.cpp:1852
void IncreaseTrackHeight()
Definition: timeline.cpp:812
QVector< int > split_tracks
Definition: timeline.h:166
void add_transition()
Definition: timeline.cpp:373
void deselect()
Definition: timeline.cpp:1701
bool zoom_just_changed
Definition: timeline.h:127
QPushButton * addButton
Definition: timeline.h:283
virtual bool event(QEvent *e) override
Definition: panel.cpp:29
void split_at_playhead()
Definition: timeline.cpp:1473
QPushButton * toolTransitionButton
Definition: timeline.h:203