From a9577d72eeb6f99f9c2f3dc81a0bbe73550f36d2 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 3 Mar 2020 16:34:09 +1100 Subject: [PATCH] pointertool: reused insert code from importtool --- app/widget/timelinewidget/timelinewidget.h | 6 ++ app/widget/timelinewidget/tool/import.cpp | 59 +--------------- app/widget/timelinewidget/tool/pointer.cpp | 5 ++ app/widget/timelinewidget/tool/tool.cpp | 78 ++++++++++++++++++++++ 4 files changed, 90 insertions(+), 58 deletions(-) diff --git a/app/widget/timelinewidget/timelinewidget.h b/app/widget/timelinewidget/timelinewidget.h index 9c43b1d46..ac4e0208b 100644 --- a/app/widget/timelinewidget/timelinewidget.h +++ b/app/widget/timelinewidget/timelinewidget.h @@ -126,6 +126,12 @@ private: */ bool SnapPoint(QList start_times, rational *movement, int snap_points = kSnapAll); + void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command); + + void GetGhostData(const QVector& ghosts, rational *earliest_point, rational *latest_point); + + void InsertGapsAtGhostDestination(const QVector& ghosts, QUndoCommand* command); + QList snap_points_; bool dragging_; diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index e78a067be..d50873501 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -273,64 +273,7 @@ void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event) // Check if we're inserting if (event->GetModifiers() & Qt::ControlModifier) { - // Get earliest point - rational earliest_point = RATIONAL_MAX; - rational latest_point = RATIONAL_MIN; - - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - earliest_point = qMin(earliest_point, ghost->GetAdjustedIn()); - latest_point = qMax(latest_point, ghost->GetAdjustedOut()); - } - - rational insert_length = latest_point - earliest_point; - - QVector blocks_to_split; - QList blocks_to_append_gap_to; - QList gaps_to_extend; - - foreach (TrackOutput* track, parent()->GetConnectedNode()->Tracks()) { - if (track->IsLocked()) { - continue; - } - - foreach (Block* b, track->Blocks()) { - if (b->out() >= earliest_point) { - if (b->type() == Block::kClip) { - - if (b->out() > earliest_point) { - blocks_to_split.append(b); - } - - blocks_to_append_gap_to.append(b); - - } else if (b->type() == Block::kGap) { - - gaps_to_extend.append(b); - - } - - break; - } - } - } - - // Extend gaps that already exist - foreach (Block* gap, gaps_to_extend) { - new BlockResizeCommand(gap, gap->length() + insert_length, command); - } - - // Split clips here - new BlockSplitPreservingLinksCommand(blocks_to_split, {earliest_point}, command); - - // Insert gaps that don't exist yet - foreach (Block* b, blocks_to_append_gap_to) { - GapBlock* gap = new GapBlock(); - gap->set_length_and_media_out(insert_length); - new NodeAddCommand(static_cast(parent()->GetConnectedNode()->parent()), gap, command); - new TrackInsertBlockAfterCommand(TrackOutput::TrackFromBlock(b), gap, b, command); - - qDebug() << "Inserting block on" << TrackOutput::TrackFromBlock(b); - } + InsertGapsAtGhostDestination(parent()->ghost_items_, command); } for (int i=0;ighost_items_.size();i++) { diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index bf77a0b47..16201c54e 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -219,6 +219,11 @@ void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *e // If there are any blocks to remove, remove them parent()->DeleteSelectedInternal(blocks_to_temp_remove, false, false, command); + if (event->GetModifiers() & Qt::ControlModifier) { + // Make room to insert clips to + InsertGapsAtGhostDestination(parent()->ghost_items_, command); + } + // Now we place the clips back in the timeline where the user moved them. It's legal for them to overwrite parts or // all of the gaps we inserted earlier for (int i=0;ighost_items_.size();i++) { diff --git a/app/widget/timelinewidget/tool/tool.cpp b/app/widget/timelinewidget/tool/tool.cpp index aea38e409..6cbe4c33c 100644 --- a/app/widget/timelinewidget/tool/tool.cpp +++ b/app/widget/timelinewidget/tool/tool.cpp @@ -24,6 +24,7 @@ #include "common/range.h" #include "node/block/transition/transition.h" +#include "widget/nodeview/nodeviewundo.h" TimelineWidget::Tool::Tool(TimelineWidget *parent) : dragging_(false), @@ -195,3 +196,80 @@ bool TimelineWidget::Tool::SnapPoint(QList start_times, rational* move return (diff < DBL_MAX); } + +void TimelineWidget::Tool::InsertGapsAt(const rational &earliest_point, const rational &insert_length, QUndoCommand *command) +{ + QVector blocks_to_split; + QList blocks_to_append_gap_to; + QList gaps_to_extend; + + foreach (TrackOutput* track, parent()->GetConnectedNode()->Tracks()) { + if (track->IsLocked()) { + continue; + } + + foreach (Block* b, track->Blocks()) { + if (b->out() >= earliest_point) { + if (b->type() == Block::kClip) { + + if (b->out() > earliest_point) { + blocks_to_split.append(b); + } + + blocks_to_append_gap_to.append(b); + + } else if (b->type() == Block::kGap) { + + gaps_to_extend.append(b); + + } + + break; + } + } + } + + // Extend gaps that already exist + foreach (Block* gap, gaps_to_extend) { + new BlockResizeCommand(gap, gap->length() + insert_length, command); + } + + // Split clips here + new BlockSplitPreservingLinksCommand(blocks_to_split, {earliest_point}, command); + + // Insert gaps that don't exist yet + foreach (Block* b, blocks_to_append_gap_to) { + GapBlock* gap = new GapBlock(); + gap->set_length_and_media_out(insert_length); + new NodeAddCommand(static_cast(parent()->GetConnectedNode()->parent()), gap, command); + new TrackInsertBlockAfterCommand(TrackOutput::TrackFromBlock(b), gap, b, command); + } +} + +void TimelineWidget::Tool::GetGhostData(const QVector &ghosts, rational *earliest_point, rational *latest_point) +{ + rational ep = RATIONAL_MAX; + rational lp = RATIONAL_MIN; + + foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + ep = qMin(ep, ghost->GetAdjustedIn()); + lp = qMax(lp, ghost->GetAdjustedOut()); + } + + if (earliest_point) { + *earliest_point = ep; + } + + if (latest_point) { + *latest_point = lp; + } +} + +void TimelineWidget::Tool::InsertGapsAtGhostDestination(const QVector &ghosts, QUndoCommand *command) +{ + rational earliest_point, latest_point; + + GetGhostData(ghosts, &earliest_point, &latest_point); + + InsertGapsAt(earliest_point, latest_point - earliest_point, command); +}