diff --git a/app/widget/timelinewidget/timelinewidgetselections.cpp b/app/widget/timelinewidget/timelinewidgetselections.cpp index 036911895..951b80946 100644 --- a/app/widget/timelinewidget/timelinewidgetselections.cpp +++ b/app/widget/timelinewidget/timelinewidgetselections.cpp @@ -56,4 +56,22 @@ void TimelineWidgetSelections::ShiftTracks(Timeline::TrackType type, int diff) } } +void TimelineWidgetSelections::TrimIn(const rational &diff) +{ + for (auto it=this->begin(); it!=this->end(); it++) { + for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) { + (*it2).set_in((*it2).in() + diff); + } + } +} + +void TimelineWidgetSelections::TrimOut(const rational &diff) +{ + for (auto it=this->begin(); it!=this->end(); it++) { + for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) { + (*it2).set_out((*it2).out() + diff); + } + } +} + OLIVE_NAMESPACE_EXIT diff --git a/app/widget/timelinewidget/timelinewidgetselections.h b/app/widget/timelinewidget/timelinewidgetselections.h index f5bea68ed..1413bbac0 100644 --- a/app/widget/timelinewidget/timelinewidgetselections.h +++ b/app/widget/timelinewidget/timelinewidgetselections.h @@ -37,6 +37,10 @@ public: void ShiftTracks(Timeline::TrackType type, int diff); + void TrimIn(const rational& diff); + + void TrimOut(const rational& diff); + }; OLIVE_NAMESPACE_EXIT diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index d3163b947..7f4f8e772 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -554,18 +554,32 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) new NodeGraphBeginOperationCommand(static_cast(parent()->GetConnectedNode()->parent()), command); - foreach (const GhostBlockPair& p, blocks_trimming) { - TimelineViewGhostItem* ghost = p.ghost; + if (!blocks_trimming.isEmpty()) { + foreach (const GhostBlockPair& p, blocks_trimming) { + TimelineViewGhostItem* ghost = p.ghost; - if (!ghost->GetData(TimelineViewGhostItem::kTrimShouldBeIgnored).toBool()) { - // Must be an ordinary trim/roll - BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()), - p.block, - ghost->GetAdjustedLength(), - ghost->GetMode(), - command); + if (!ghost->GetData(TimelineViewGhostItem::kTrimShouldBeIgnored).toBool()) { + // Must be an ordinary trim/roll + BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()), + p.block, + ghost->GetAdjustedLength(), + ghost->GetMode(), + command); - c->SetTrimIsARollEdit(ghost->GetData(TimelineViewGhostItem::kTrimIsARollEdit).toBool()); + c->SetTrimIsARollEdit(ghost->GetData(TimelineViewGhostItem::kTrimIsARollEdit).toBool()); + } + } + + if (blocks_moving.isEmpty() && blocks_sliding.isEmpty()) { + // Trim selections (deferring to moving/sliding blocks when necessary) + TimelineWidgetSelections new_sel = parent()->GetSelections(); + TimelineViewGhostItem* reference_ghost = blocks_trimming.first().ghost; + if (reference_ghost->GetMode() == Timeline::kTrimIn) { + new_sel.TrimIn(reference_ghost->GetInAdjustment()); + } else { + new_sel.TrimOut(reference_ghost->GetOutAdjustment()); + } + new TimelineSetSelectionsCommand(parent(), new_sel, parent()->GetSelections(), command); } } diff --git a/app/widget/timelinewidget/tool/ripple.cpp b/app/widget/timelinewidget/tool/ripple.cpp index 1a2110213..f9455483e 100644 --- a/app/widget/timelinewidget/tool/ripple.cpp +++ b/app/widget/timelinewidget/tool/ripple.cpp @@ -108,30 +108,43 @@ void RippleTool::FinishDrag(TimelineViewMouseEvent *event) { Q_UNUSED(event) - QVector< QList > info_list(Timeline::kTrackTypeCount); + if (parent()->HasGhosts()) { + QVector< QList > info_list(Timeline::kTrackTypeCount); - foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { - TrackOutput* track = parent()->GetTrackFromReference(ghost->GetTrack()); + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + TrackOutput* track = parent()->GetTrackFromReference(ghost->GetTrack()); - TrackListRippleToolCommand::RippleInfo i = {Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)), - Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kReferenceBlock)), - track, - ghost->GetAdjustedLength(), - ghost->GetLength()}; + TrackListRippleToolCommand::RippleInfo i = {Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)), + Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kReferenceBlock)), + track, + ghost->GetAdjustedLength(), + ghost->GetLength()}; - info_list[track->track_type()].append(i); + info_list[track->track_type()].append(i); + } + + QUndoCommand* command = new QUndoCommand(); + + if (!info_list.isEmpty()) { + for (int i=0;iGetConnectedNode()->track_list(static_cast(i)), + info_list.at(i), + drag_movement_mode(), + command); + } + + TimelineWidgetSelections new_sel = parent()->GetSelections(); + TimelineViewGhostItem* reference_ghost = parent()->GetGhostItems().first(); + if (drag_movement_mode() == Timeline::kTrimIn) { + new_sel.TrimOut(-reference_ghost->GetInAdjustment()); + } else { + new_sel.TrimOut(reference_ghost->GetOutAdjustment()); + } + new TimelineSetSelectionsCommand(parent(), new_sel, parent()->GetSelections(), command); + } + + Core::instance()->undo_stack()->pushIfHasChildren(command); } - - QUndoCommand* command = new QUndoCommand(); - - for (int i=0;iGetConnectedNode()->track_list(static_cast(i)), - info_list.at(i), - drag_movement_mode(), - command); - } - - Core::instance()->undo_stack()->pushIfHasChildren(command); } OLIVE_NAMESPACE_EXIT