diff --git a/app/widget/timelineview/timelineview.cpp b/app/widget/timelineview/timelineview.cpp index cde32a592..e4ebacdd0 100644 --- a/app/widget/timelineview/timelineview.cpp +++ b/app/widget/timelineview/timelineview.cpp @@ -39,6 +39,7 @@ TimelineView::TimelineView(QWidget *parent) : ripple_tool_(this), rolling_tool_(this), razor_tool_(this), + slide_tool_(this), hand_tool_(this), zoom_tool_(this), timeline_node_(nullptr), @@ -272,7 +273,7 @@ TimelineView::Tool *TimelineView::GetActiveTool() case olive::tool::kSlip: return nullptr; // FIXME: Implement case olive::tool::kSlide: - return nullptr; // FIXME: Implement + return &slide_tool_; case olive::tool::kHand: return &hand_tool_; case olive::tool::kZoom: diff --git a/app/widget/timelineview/timelineview.h b/app/widget/timelineview/timelineview.h index 592e4f05b..7ed75275a 100644 --- a/app/widget/timelineview/timelineview.h +++ b/app/widget/timelineview/timelineview.h @@ -169,6 +169,8 @@ private: virtual void MouseRelease(QMouseEvent *event) override; protected: void SetMovementAllowed(bool allowed); + void SetTrackMovementAllowed(bool allowed); + void SetTrimmingAllowed(bool allowed); virtual void MouseReleaseInternal(QMouseEvent *event); virtual rational FrameValidateInternal(rational time_movement, const QVector &ghosts); @@ -209,6 +211,8 @@ private: int track_start_; bool movement_allowed_; + bool trimming_allowed_; + bool track_movement_allowed_; }; class ImportTool : public Tool @@ -264,6 +268,19 @@ private: bool allow_gap_trimming) override; }; + class SlideTool : public PointerTool + { + public: + SlideTool(TimelineView* parent); + + protected: + virtual void MouseReleaseInternal(QMouseEvent *event) override; + virtual rational FrameValidateInternal(rational time_movement, const QVector& ghosts) override; + virtual void InitiateGhosts(TimelineViewBlockItem* clicked_item, + olive::timeline::MovementMode trim_mode, + bool allow_gap_trimming) override; + }; + class HandTool : public Tool { public: @@ -298,6 +315,7 @@ private: RippleTool ripple_tool_; RollingTool rolling_tool_; RazorTool razor_tool_; + SlideTool slide_tool_; HandTool hand_tool_; ZoomTool zoom_tool_; diff --git a/app/widget/timelineview/tool/CMakeLists.txt b/app/widget/timelineview/tool/CMakeLists.txt index 854ac72ba..830b77956 100644 --- a/app/widget/timelineview/tool/CMakeLists.txt +++ b/app/widget/timelineview/tool/CMakeLists.txt @@ -22,6 +22,7 @@ set(OLIVE_SOURCES widget/timelineview/tool/razor.cpp widget/timelineview/tool/ripple.cpp widget/timelineview/tool/rolling.cpp + widget/timelineview/tool/slide.cpp widget/timelineview/tool/tool.cpp widget/timelineview/tool/zoom.cpp PARENT_SCOPE diff --git a/app/widget/timelineview/tool/pointer.cpp b/app/widget/timelineview/tool/pointer.cpp index 6c912b762..723c64133 100644 --- a/app/widget/timelineview/tool/pointer.cpp +++ b/app/widget/timelineview/tool/pointer.cpp @@ -32,7 +32,9 @@ TimelineView::PointerTool::PointerTool(TimelineView *parent) : Tool(parent), - movement_allowed_(true) + movement_allowed_(true), + trimming_allowed_(true), + track_movement_allowed_(true) { } @@ -107,6 +109,16 @@ void TimelineView::PointerTool::SetMovementAllowed(bool allowed) movement_allowed_ = allowed; } +void TimelineView::PointerTool::SetTrackMovementAllowed(bool allowed) +{ + track_movement_allowed_ = allowed; +} + +void TimelineView::PointerTool::SetTrimmingAllowed(bool allowed) +{ + trimming_allowed_ = allowed; +} + void TimelineView::PointerTool::MouseReleaseInternal(QMouseEvent *event) { Q_UNUSED(event) @@ -187,9 +199,9 @@ void TimelineView::PointerTool::InitiateDrag(const QPoint& mouse_pos) // FIXME: Hardcoded number const int kTrimHandle = 20; - if (drag_start_.x() < clicked_item->x() + kTrimHandle) { + if (trimming_allowed_ && drag_start_.x() < clicked_item->x() + kTrimHandle) { trim_mode = olive::timeline::kTrimIn; - } else if (drag_start_.x() > clicked_item->x() + clicked_item->rect().right() - kTrimHandle) { + } else if (trimming_allowed_ && drag_start_.x() > clicked_item->x() + clicked_item->rect().right() - kTrimHandle) { trim_mode = olive::timeline::kTrimOut; } else if (movement_allowed_) { // Some derived classes don't allow movement @@ -216,7 +228,11 @@ void TimelineView::PointerTool::ProcessDrag(const QPoint &mouse_pos) // Determine track movement int cursor_track = parent()->SceneToTrack(scene_pos.y()); - int track_movement = cursor_track - track_start_; + int track_movement = 0; + + if (track_movement_allowed_) { + track_movement = cursor_track - track_start_; + } // Determine frame movement rational time_movement = parent()->SceneToTime(movement.x()); diff --git a/app/widget/timelineview/tool/slide.cpp b/app/widget/timelineview/tool/slide.cpp new file mode 100644 index 000000000..32b2c74af --- /dev/null +++ b/app/widget/timelineview/tool/slide.cpp @@ -0,0 +1,93 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#include "widget/timelineview/timelineview.h" + +#include "node/block/gap/gap.h" + +TimelineView::SlideTool::SlideTool(TimelineView* parent) : + PointerTool(parent) +{ + SetTrimmingAllowed(false); + SetTrackMovementAllowed(false); +} + +void TimelineView::SlideTool::MouseReleaseInternal(QMouseEvent *event) +{ + Q_UNUSED(event) + + if (parent()->ghost_items_.isEmpty()) { + return; + } + + QUndoCommand* command = new QUndoCommand(); + + // Find earliest point to ripple around + foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + Block* b = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); + + if (ghost->mode() == olive::timeline::kTrimIn) { + new BlockResizeWithMediaInCommand(b, ghost->AdjustedLength(), command); + } else if (ghost->mode() == olive::timeline::kTrimOut) { + new BlockResizeCommand(b, ghost->AdjustedLength(), command); + } else if (ghost->mode() == olive::timeline::kMove && b->previous() == nullptr) { + GapBlock* gap = new GapBlock(); + gap->set_length(ghost->InAdjustment()); + new TrackPrependBlockCommand(parent()->timeline_node_->TrackAt(ghost->Track()), gap, command); + } + } + + olive::undo_stack.pushIfHasChildren(command); +} + +rational TimelineView::SlideTool::FrameValidateInternal(rational time_movement, const QVector &ghosts) +{ + // Only validate trimming, and we don't care about "overwriting" since the rolling tool is designed to trim at collisions + time_movement = ValidateInTrimming(time_movement, ghosts, false); + time_movement = ValidateOutTrimming(time_movement, ghosts, false); + + return time_movement; +} + +void TimelineView::SlideTool::InitiateGhosts(TimelineViewBlockItem *clicked_item, + olive::timeline::MovementMode trim_mode, + bool allow_gap_trimming) +{ + Q_UNUSED(allow_gap_trimming) + + PointerTool::InitiateGhosts(clicked_item, trim_mode, true); + + // For each ghost, we make an equivalent Ghost on the next/previous block + foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + Block* ghost_block = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); + + // Add trimming ghosts for each side of the Block + + if (ghost_block->previous() != nullptr) { + // Add an extra Ghost for the previous block + AddGhostFromBlock(ghost_block->previous(), ghost->Track(), olive::timeline::kTrimOut); + } + + if (ghost_block->next() != nullptr && ghost_block->next()->type() != Block::kEnd) { + AddGhostFromBlock(ghost_block->next(), ghost->Track(), olive::timeline::kTrimIn); + } + } +} + diff --git a/app/widget/timelineview/undo/undo.cpp b/app/widget/timelineview/undo/undo.cpp index 107ea39cd..d327df25b 100644 --- a/app/widget/timelineview/undo/undo.cpp +++ b/app/widget/timelineview/undo/undo.cpp @@ -414,3 +414,20 @@ void TrackReplaceBlockCommand::undo() { track_->ReplaceBlock(replace_, old_); } + +TrackPrependBlockCommand::TrackPrependBlockCommand(TrackOutput *track, Block *block, QUndoCommand *parent) : + QUndoCommand(parent), + track_(track), + block_(block) +{ +} + +void TrackPrependBlockCommand::redo() +{ + track_->PrependBlock(block_); +} + +void TrackPrependBlockCommand::undo() +{ + track_->RippleRemoveBlock(block_); +} diff --git a/app/widget/timelineview/undo/undo.h b/app/widget/timelineview/undo/undo.h index 786ee4a6b..6c7206ea1 100644 --- a/app/widget/timelineview/undo/undo.h +++ b/app/widget/timelineview/undo/undo.h @@ -83,6 +83,18 @@ private: Block* after_; }; +class TrackPrependBlockCommand : public QUndoCommand { +public: + TrackPrependBlockCommand(TrackOutput* track, Block* block, QUndoCommand* parent = nullptr); + + virtual void redo() override; + virtual void undo() override; + +private: + TrackOutput* track_; + Block* block_; +}; + class TrackInsertBlockBetweenBlocksCommand : public QUndoCommand { public: TrackInsertBlockBetweenBlocksCommand(TrackOutput* track, Block* block, Block* before, Block* after, QUndoCommand* parent = nullptr);