diff --git a/mainwindow.cpp b/mainwindow.cpp index 657b965cb..be9f761b0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -175,3 +175,10 @@ void MainWindow::on_action_Redo_triggered() panel_timeline->redo(); } } + +void MainWindow::on_actionSplit_at_Playhead_triggered() +{ + if (panel_timeline->focused()) { + panel_timeline->split_at_playhead(); + } +} diff --git a/mainwindow.h b/mainwindow.h index 56294253e..ec0940579 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -55,6 +55,8 @@ private slots: void on_action_Redo_triggered(); + void on_actionSplit_at_Playhead_triggered(); + private: Ui::MainWindow *ui; void setup_layout(); diff --git a/mainwindow.ui b/mainwindow.ui index 7c7d44b55..2fb9381fa 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -24,7 +24,7 @@ 0 0 653 - 21 + 17 @@ -64,6 +64,8 @@ + + @@ -287,6 +289,14 @@ Shift+Del + + + Split at Playhead + + + Ctrl+K + + diff --git a/olive.pro.user b/olive.pro.user index e15a33f3d..3ec776c11 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -292,7 +292,7 @@ olive.pro false - + C:/Users/Matt/Documents/temp 3768 false true diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 3582fbde3..bd578d6cd 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -20,7 +20,7 @@ Timeline::Timeline(QWidget *parent) : { selecting = moving_init = moving_proc = splitting = importing = playing = trim_in = snapped = false; snapping = true; - last_frame = playhead = snap_point = 0; + last_frame = playhead = snap_point = cursor_frame = cursor_track = 0; trim_target = -1; ui->setupUi(this); @@ -340,6 +340,42 @@ void Timeline::on_toolSlipButton_toggled(bool checked) void Timeline::on_snappingButton_toggled(bool checked) { snapping = checked; +} - qDebug() << "clips vector size:" << sizeof(Clip) * sequence->clip_count(); +void Timeline::split_at_playhead() { + bool split_selected = false; + + if (selections.size() > 0) { + // see if whole clips are selected + for (int j=0;jclip_count();j++) { + if (is_clip_selected(j)) { + sequence->split_clip(j, playhead); + split_selected = true; + } + } + + // split a selection if not + if (!split_selected) { + for (int j=0;jclip_count();j++) { + for (int i=0;iget_clip(j).track) { + sequence->split_clip(j, s.in); + sequence->split_clip(j, s.out); + split_selected = true; + } + } + } + } + } + + // if nothing was selected or no selections fell within playhead, simply split at playhead + if (!split_selected) { + for (int j=0;jclip_count();j++) { + sequence->split_clip(j, playhead); + split_selected = true; + } + } + + if (split_selected) redraw_all_clips(); } diff --git a/panels/timeline.h b/panels/timeline.h index abd650e79..ad500423d 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -63,6 +63,7 @@ public: void zoom_out(); void undo(); void redo(); + void split_at_playhead(); void set_sequence(Sequence* s); Sequence* sequence; @@ -85,6 +86,8 @@ public: // shared information int tool; + long cursor_frame; + int cursor_track; float zoom; long drag_frame_start; int drag_track_start; diff --git a/project/sequence.cpp b/project/sequence.cpp index 843c72b86..d9189e2f3 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -113,20 +113,10 @@ void Sequence::split_clip(int i, long frame) { } } -void Sequence::split_at_playhead(long frame) { - for (int j=0;j frame) { - split_clip(j, frame); - } - } -} - void Sequence::undo_add_current() { undo_pointer++; undo_stack.resize(undo_pointer); undo_stack.append(clips); - qDebug() << "a pointer:" << undo_pointer << undo_stack.size(); } void Sequence::undo() { @@ -136,7 +126,6 @@ void Sequence::undo() { } else { qDebug() << "[INFO] No more undos"; } - qDebug() << "u pointer:" << undo_pointer << undo_stack.size(); } void Sequence::redo() { if (undo_pointer == undo_stack.size() - 1) { @@ -145,5 +134,4 @@ void Sequence::redo() { undo_pointer++; clips = undo_stack[undo_pointer]; } - qDebug() << "r pointer:" << undo_pointer << undo_stack.size(); } diff --git a/project/sequence.h b/project/sequence.h index 3297a0df4..ac2245e96 100644 --- a/project/sequence.h +++ b/project/sequence.h @@ -18,8 +18,7 @@ public: Clip& get_clip(int i); void delete_clip(int i); void delete_area(long in, long out, int track); - void split_clip(int i, long frame); - void split_at_playhead(long frame); + void split_clip(int i, long frame); void get_track_limits(int* video_tracks, int* audio_tracks); long getEndFrame(); int width; diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 66a29c831..24fb73cd2 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -128,10 +128,15 @@ void TimelineWidget::dropEvent(QDropEvent* event) { } void TimelineWidget::mousePressEvent(QMouseEvent *event) { - QPoint pos = event->pos(); + if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { + panel_timeline->drag_frame_start = panel_timeline->cursor_frame; + panel_timeline->drag_track_start = panel_timeline->cursor_track; + } else { + QPoint pos = event->pos(); + panel_timeline->drag_frame_start = getFrameFromScreenPoint(pos.x(), false); + panel_timeline->drag_track_start = getTrackFromScreenPoint(pos.y()); + } - panel_timeline->drag_frame_start = getFrameFromScreenPoint(pos.x(), false); - panel_timeline->drag_track_start = getTrackFromScreenPoint(pos.y()); int clip_index = panel_timeline->trim_target; if (clip_index == -1) clip_index = getClipIndexFromCoords(panel_timeline->drag_frame_start, panel_timeline->drag_track_start); @@ -311,12 +316,12 @@ bool subvalidate_snapping(Ghost& g, long* frame_diff, long snap_point) { long in_validator = g.old_in + *frame_diff - snap_point; long out_validator = g.old_out + *frame_diff - snap_point; - if (in_validator > -snap_range && in_validator < snap_range) { + if ((panel_timeline->trim_target == -1 || panel_timeline->trim_in) && in_validator > -snap_range && in_validator < snap_range) { *frame_diff -= in_validator; panel_timeline->snap_point = snap_point; panel_timeline->snapped = true; return true; - } else if (out_validator > -snap_range && out_validator < snap_range) { + } else if (!panel_timeline->trim_in && out_validator > -snap_range && out_validator < snap_range) { *frame_diff -= out_validator; panel_timeline->snap_point = snap_point; panel_timeline->snapped = true; @@ -505,25 +510,30 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) { } void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { - if (panel_timeline->selecting) { - QPoint pos = event->pos(); + if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { + panel_timeline->cursor_frame = getFrameFromScreenPoint(event->pos().x(), false); + panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y()); - int current_selection_track = getTrackFromScreenPoint(pos.y()); - long current_selection_frame = getFrameFromScreenPoint(pos.x(), false);; - int selection_count = 1 + qMax(current_selection_track, panel_timeline->drag_track_start) - qMin(current_selection_track, panel_timeline->drag_track_start); + int limit = getFrameFromScreenPoint(10, false); + if (panel_timeline->snapping && panel_timeline->cursor_frame > panel_timeline->playhead-limit-1 && panel_timeline->cursor_frame < panel_timeline->playhead+limit+1) { + panel_timeline->cursor_frame = panel_timeline->playhead; + } + } + if (panel_timeline->selecting) { + int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start); if (panel_timeline->selections.size() != selection_count) { panel_timeline->selections.resize(selection_count); } - int minimum_selection_track = qMin(current_selection_track, panel_timeline->drag_track_start); + int minimum_selection_track = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start); for (int i=0;iselections[i]; s->track = minimum_selection_track + i; long in = panel_timeline->drag_frame_start; - long out = current_selection_frame; + long out = panel_timeline->cursor_frame; s->in = qMin(in, out); s->out = qMax(in, out); } - panel_timeline->playhead = qMin(panel_timeline->drag_frame_start, current_selection_frame); + panel_timeline->playhead = qMin(panel_timeline->drag_frame_start, panel_timeline->cursor_frame); panel_timeline->repaint_timeline(); } else if (panel_timeline->moving_init) { QPoint pos = event->pos(); @@ -608,7 +618,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } else if (panel_timeline->splitting) { QPoint pos = event->pos(); - int track = getTrackFromScreenPoint(pos.y()); + int track = panel_timeline->cursor_track; bool repaint = false; for (int i=0;isequence->clip_count();i++) { if (panel_timeline->sequence->get_clip(i).track == track) { @@ -770,11 +780,9 @@ void TimelineWidget::paintEvent(QPaintEvent*) { // Draw edit cursor if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { - QPoint mouse_pos = mapFromGlobal(QCursor::pos()); - int track = getTrackFromScreenPoint(mouse_pos.y()); - if (is_track_visible(track)) { - int cursor_x = getScreenPointFromFrame(getFrameFromScreenPoint(mouse_pos.x(), false)); - int cursor_y = getScreenPointFromTrack(track); + if (is_track_visible(panel_timeline->cursor_track)) { + int cursor_x = getScreenPointFromFrame(panel_timeline->cursor_frame); + int cursor_y = getScreenPointFromTrack(panel_timeline->cursor_track); p.setPen(Qt::gray); p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + track_height);