From a8d714b6e21ed6345f4ddbf1ff7b5773345d71ec Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 3 Oct 2020 22:33:29 +1000 Subject: [PATCH] timeline: moved tools to separate source files --- app/widget/timelinewidget/tool/add.cpp | 3 +- app/widget/timelinewidget/tool/edit.cpp | 12 ++++- app/widget/timelinewidget/tool/edit.h | 3 +- app/widget/timelinewidget/tool/import.cpp | 9 ++-- app/widget/timelinewidget/tool/pointer.cpp | 50 ++++++++++--------- app/widget/timelinewidget/tool/ripple.cpp | 10 ++-- app/widget/timelinewidget/tool/slip.cpp | 2 +- app/widget/timelinewidget/tool/tool.cpp | 4 +- app/widget/timelinewidget/tool/transition.cpp | 13 +++-- 9 files changed, 58 insertions(+), 48 deletions(-) diff --git a/app/widget/timelinewidget/tool/add.cpp b/app/widget/timelinewidget/tool/add.cpp index eefbf6e37..4ea4831f9 100644 --- a/app/widget/timelinewidget/tool/add.cpp +++ b/app/widget/timelinewidget/tool/add.cpp @@ -72,7 +72,6 @@ void AddTool::MousePress(TimelineViewMouseEvent *event) ghost_->SetIn(drag_start_point_); ghost_->SetOut(drag_start_point_); ghost_->SetTrack(track); - ghost_->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track)); parent()->AddGhost(ghost_); snap_points_.append(drag_start_point_); @@ -90,7 +89,7 @@ void AddTool::MouseMove(TimelineViewMouseEvent *event) void AddTool::MouseRelease(TimelineViewMouseEvent *event) { - const TrackReference& track = ghost_->Track(); + const TrackReference& track = ghost_->GetTrack(); if (ghost_) { if (!ghost_->GetAdjustedLength().isNull()) { diff --git a/app/widget/timelinewidget/tool/edit.cpp b/app/widget/timelinewidget/tool/edit.cpp index ff8c9b9e4..142aca321 100644 --- a/app/widget/timelinewidget/tool/edit.cpp +++ b/app/widget/timelinewidget/tool/edit.cpp @@ -38,8 +38,18 @@ void EditTool::MousePress(TimelineViewMouseEvent *event) void EditTool::MouseMove(TimelineViewMouseEvent *event) { if (dragging_) { + rational end_frame = event->GetFrame(true); + + if (Core::instance()->snapping()) { + rational movement; + parent()->SnapPoint({end_frame}, &movement); + if (!movement.isNull()) { + end_frame += movement; + } + } + parent()->SetSelections(start_selections_); - parent()->AddSelection(TimeRange(start_coord_.GetFrame(), event->GetFrame()), + parent()->AddSelection(TimeRange(start_coord_.GetFrame(), end_frame), start_coord_.GetTrack()); } else { start_selections_ = parent()->GetSelections(); diff --git a/app/widget/timelinewidget/tool/edit.h b/app/widget/timelinewidget/tool/edit.h index 8029014db..9f1e40be3 100644 --- a/app/widget/timelinewidget/tool/edit.h +++ b/app/widget/timelinewidget/tool/edit.h @@ -23,6 +23,7 @@ #include "beam.h" #include "tool.h" +#include "widget/timelinewidget/timelinewidgetselections.h" OLIVE_NAMESPACE_ENTER @@ -37,7 +38,7 @@ public: virtual void MouseDoubleClick(TimelineViewMouseEvent *event) override; private: - QHash start_selections_; + TimelineWidgetSelections start_selections_; TimelineCoordinate start_coord_; diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index 0d8376d09..69006f92c 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -142,9 +142,6 @@ void ImportTool::DragMove(TimelineViewMouseEvent *event) ghost->SetOutAdjustment(time_movement); ghost->SetTrackAdjustment(track_movement); - TrackReference adjusted_track = ghost->GetAdjustedTrack(); - ghost->SetYCoords(parent()->GetTrackY(adjusted_track), parent()->GetTrackHeight(adjusted_track)); - earliest_ghost = qMin(earliest_ghost, ghost->GetAdjustedIn()); } @@ -258,7 +255,7 @@ void ImportTool::FootageToGhosts(rational ghost_start, const QListsetData(TimelineViewGhostItem::kAttachedFootage, QVariant::fromValue(stream)); + ghost->SetData(TimelineViewGhostItem::kAttachedFootage, QVariant::fromValue(stream)); ghost->SetMode(Timeline::kMove); footage_ghosts.append(ghost); @@ -404,7 +401,7 @@ void ImportTool::DropGhosts(bool insert) for (int i=0;iGetGhostItems().size();i++) { TimelineViewGhostItem* ghost = parent()->GetGhostItems().at(i); - StreamPtr footage_stream = ghost->data(TimelineViewGhostItem::kAttachedFootage).value(); + StreamPtr footage_stream = ghost->GetData(TimelineViewGhostItem::kAttachedFootage).value(); ClipBlock* clip = new ClipBlock(); clip->set_media_in(ghost->GetMediaIn()); @@ -463,7 +460,7 @@ void ImportTool::DropGhosts(bool insert) // Link any clips so far that share the same Footage with this one for (int j=0;jGetGhostItems().at(j)->data(TimelineViewGhostItem::kAttachedFootage).value(); + StreamPtr footage_compare = parent()->GetGhostItems().at(j)->GetData(TimelineViewGhostItem::kAttachedFootage).value(); if (footage_compare->footage() == footage_stream->footage()) { Block::Link(block_items.at(j), clip); diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index 31314d133..d3163b947 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -76,7 +76,7 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event) } // If this item is already selected, no further selection needs to be made - if (parent()->IsItemSelected(clicked_item_)) { + if (parent()->IsBlockSelected(clicked_item_->block())) { // Collect item deselections QList deselected_blocks; @@ -93,7 +93,7 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event) } } - emit parent()->BlocksDeselected(deselected_blocks); + parent()->SignalDeselectedBlocks(deselected_blocks); return; } @@ -119,7 +119,7 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event) selected_blocks.append(clicked_item_->block()->linked_clips().toList()); } - emit parent()->BlocksSelected(selected_blocks); + parent()->SignalSelectedBlocks(selected_blocks); } else if (event->GetButton() == Qt::LeftButton) { @@ -215,7 +215,7 @@ void PointerTool::HoverMove(TimelineViewMouseEvent *event) void SetGhostToSlideMode(TimelineViewGhostItem* g) { g->SetCanMoveTracks(false); - g->setData(TimelineViewGhostItem::kGhostIsSliding, true); + g->SetData(TimelineViewGhostItem::kGhostIsSliding, true); } void PointerTool::InitiateDragInternal(TimelineViewBlockItem *clicked_item, @@ -427,16 +427,16 @@ void PointerTool::InitiateDragInternal(TimelineViewBlockItem *clicked_item, // If we have an adjacent block (for any reason), this is a roll edit and the adjacent is // expected to fill the remaining space (no gap needs to be created) - ghost->setData(TimelineViewGhostItem::kTrimIsARollEdit, static_cast(adjacent)); + ghost->SetData(TimelineViewGhostItem::kTrimIsARollEdit, static_cast(adjacent)); if (adjacent_ghost) { if (treat_trim_as_slide) { // We're sliding a transition rather than a pure trim/roll SetGhostToSlideMode(adjacent_ghost); } else if (block->type() == Block::kGap) { - ghost->setData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); + ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); } else { - adjacent_ghost->setData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); + adjacent_ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); } } } @@ -472,7 +472,7 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) { QVector validate_track_ghosts = parent()->GetGhostItems(); for (int i=0;iTrack().type() != drag_track_type_) { + if (validate_track_ghosts.at(i)->GetTrack().type() != drag_track_type_) { validate_track_ghosts.removeAt(i); i--; } @@ -498,11 +498,8 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) // Track movement is only legal for moving, not for trimming // Also, we only move the clips on the same track type that the drag started from - if (ghost->Track().type() == drag_track_type_) { + if (ghost->GetTrack().type() == drag_track_type_) { ghost->SetTrackAdjustment(track_movement); - - const TrackReference& track = ghost->GetAdjustedTrack(); - ghost->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track)); } break; } @@ -534,9 +531,9 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) // Sort ghosts depending on which ones are trimming, which are moving, and which are sliding foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { if (ghost->HasBeenAdjusted()) { - Block* b = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); + Block* b = Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)); - if (ghost->data(TimelineViewGhostItem::kGhostIsSliding).toBool()) { + if (ghost->GetData(TimelineViewGhostItem::kGhostIsSliding).toBool()) { blocks_sliding.append({ghost, b}); } else if (ghost->GetMode() == Timeline::kMove) { blocks_moving.append({ghost, b}); @@ -560,7 +557,7 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) foreach (const GhostBlockPair& p, blocks_trimming) { TimelineViewGhostItem* ghost = p.ghost; - if (!ghost->data(TimelineViewGhostItem::kTrimShouldBeIgnored).toBool()) { + if (!ghost->GetData(TimelineViewGhostItem::kTrimShouldBeIgnored).toBool()) { // Must be an ordinary trim/roll BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()), p.block, @@ -568,7 +565,7 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) ghost->GetMode(), command); - c->SetTrimIsARollEdit(ghost->data(TimelineViewGhostItem::kTrimIsARollEdit).toBool()); + c->SetTrimIsARollEdit(ghost->GetData(TimelineViewGhostItem::kTrimIsARollEdit).toBool()); } } @@ -618,6 +615,12 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) p.ghost->GetAdjustedIn(), command); } + + // Adjust selections + TimelineWidgetSelections new_sel = parent()->GetSelections(); + new_sel.ShiftTime(blocks_moving.first().ghost->GetInAdjustment()); + new_sel.ShiftTracks(drag_track_type_, blocks_moving.first().ghost->GetTrackAdjustment()); + new TimelineSetSelectionsCommand(parent(), new_sel, parent()->GetSelections(), command); } if (!blocks_sliding.isEmpty()) { @@ -630,7 +633,7 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) rational movement; foreach (const GhostBlockPair& p, blocks_sliding) { - const TrackReference& track = p.ghost->Track(); + const TrackReference& track = p.ghost->GetTrack(); switch (p.ghost->GetMode()) { case Timeline::kNone: @@ -675,6 +678,11 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) movement, command); } + + // Adjust selections + TimelineWidgetSelections new_sel = parent()->GetSelections(); + new_sel.ShiftTime(movement); + new TimelineSetSelectionsCommand(parent(), new_sel, parent()->GetSelections(), command); } } @@ -713,16 +721,13 @@ TimelineViewGhostItem* PointerTool::AddGhostFromBlock(Block* block, const TrackR { if (check_if_exists) { foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { - if (Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)) == block) { + if (Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)) == block) { return ghost; } } } - TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromBlock(block, - track, - parent()->GetTrackY(track), - parent()->GetTrackHeight(track)); + TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromBlock(block, track); #ifdef HIDE_GAP_GHOSTS if (block->type() == Block::kGap) { @@ -742,7 +747,6 @@ TimelineViewGhostItem* PointerTool::AddGhostFromNull(const rational &in, const r ghost->SetIn(in); ghost->SetOut(out); ghost->SetTrack(track); - ghost->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track)); #ifdef HIDE_GAP_GHOSTS ghost->SetInvisible(true); diff --git a/app/widget/timelinewidget/tool/ripple.cpp b/app/widget/timelinewidget/tool/ripple.cpp index 3b8273327..1a2110213 100644 --- a/app/widget/timelinewidget/tool/ripple.cpp +++ b/app/widget/timelinewidget/tool/ripple.cpp @@ -67,7 +67,7 @@ void RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_item, bool ghost_on_this_track_exists = false; foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { - if (parent()->GetTrackFromReference(ghost->Track()) == track) { + if (parent()->GetTrackFromReference(ghost->GetTrack()) == track) { ghost_on_this_track_exists = true; break; } @@ -96,7 +96,7 @@ void RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_item, } else { // If next is NOT a gap, we'll need to create one, for which we'll use a null ghost ghost = AddGhostFromNull(block_before_ripple->out(), block_before_ripple->out(), track_ref, trim_mode); - ghost->setData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(block_before_ripple)); + ghost->SetData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(block_before_ripple)); } } } @@ -111,10 +111,10 @@ void RippleTool::FinishDrag(TimelineViewMouseEvent *event) QVector< QList > info_list(Timeline::kTrackTypeCount); foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { - TrackOutput* track = parent()->GetTrackFromReference(ghost->Track()); + TrackOutput* track = parent()->GetTrackFromReference(ghost->GetTrack()); - TrackListRippleToolCommand::RippleInfo i = {Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)), - Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kReferenceBlock)), + TrackListRippleToolCommand::RippleInfo i = {Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)), + Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kReferenceBlock)), track, ghost->GetAdjustedLength(), ghost->GetLength()}; diff --git a/app/widget/timelinewidget/tool/slip.cpp b/app/widget/timelinewidget/tool/slip.cpp index caea2014d..e7636048f 100644 --- a/app/widget/timelinewidget/tool/slip.cpp +++ b/app/widget/timelinewidget/tool/slip.cpp @@ -71,7 +71,7 @@ void SlipTool::FinishDrag(TimelineViewMouseEvent *event) // Find earliest point to ripple around foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { - Block* b = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); + Block* b = Node::ValueToPtr(ghost->GetData(TimelineViewGhostItem::kAttachedBlock)); new BlockSetMediaInCommand(b, ghost->GetAdjustedMediaIn(), command); } diff --git a/app/widget/timelinewidget/tool/tool.cpp b/app/widget/timelinewidget/tool/tool.cpp index 060c82da1..388b4edaf 100644 --- a/app/widget/timelinewidget/tool/tool.cpp +++ b/app/widget/timelinewidget/tool/tool.cpp @@ -80,10 +80,10 @@ int TimelineTool::ValidateTrackMovement(int movement, const QVectorTrack().index() + movement < 0) { + } else if (ghost->GetTrack().index() + movement < 0) { // Prevents any ghosts from going to a non-existent negative track - movement = -ghost->Track().index(); + movement = -ghost->GetTrack().index(); } } diff --git a/app/widget/timelinewidget/tool/transition.cpp b/app/widget/timelinewidget/tool/transition.cpp index 5e7127aea..942e7a6b2 100644 --- a/app/widget/timelinewidget/tool/transition.cpp +++ b/app/widget/timelinewidget/tool/transition.cpp @@ -78,15 +78,14 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event) // Create ghost ghost_ = new TimelineViewGhostItem(); ghost_->SetTrack(track); - ghost_->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track)); ghost_->SetIn(transition_start_point); ghost_->SetOut(transition_start_point); ghost_->SetMode(trim_mode); - ghost_->setData(TimelineViewGhostItem::kAttachedBlock, Node::PtrToValue(block_at_time)); + ghost_->SetData(TimelineViewGhostItem::kAttachedBlock, Node::PtrToValue(block_at_time)); dual_transition_ = (other_block); if (other_block) - ghost_->setData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(other_block)); + ghost_->SetData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(other_block)); parent()->AddGhost(ghost_); @@ -107,7 +106,7 @@ void TransitionTool::MouseMove(TimelineViewMouseEvent *event) void TransitionTool::MouseRelease(TimelineViewMouseEvent *event) { - const TrackReference& track = ghost_->Track(); + const TrackReference& track = ghost_->GetTrack(); if (ghost_) { if (!ghost_->GetAdjustedLength().isNull()) { @@ -138,10 +137,10 @@ void TransitionTool::MouseRelease(TimelineViewMouseEvent *event) transition->set_media_in(-ghost_->GetAdjustedLength()/2); // Block mouse is hovering over - Block* active_block = Node::ValueToPtr(ghost_->data(TimelineViewGhostItem::kAttachedBlock)); + Block* active_block = Node::ValueToPtr(ghost_->GetData(TimelineViewGhostItem::kAttachedBlock)); // Block mouse is next to - Block* friend_block = Node::ValueToPtr(ghost_->data(TimelineViewGhostItem::kReferenceBlock)); + Block* friend_block = Node::ValueToPtr(ghost_->GetData(TimelineViewGhostItem::kReferenceBlock)); // Use ghost mode to determine which block is which Block* out_block = (ghost_->GetMode() == Timeline::kTrimIn) ? friend_block : active_block; @@ -156,7 +155,7 @@ void TransitionTool::MouseRelease(TimelineViewMouseEvent *event) transition->in_block_input(), command); } else { - Block* block_to_transition = Node::ValueToPtr(ghost_->data(TimelineViewGhostItem::kAttachedBlock)); + Block* block_to_transition = Node::ValueToPtr(ghost_->GetData(TimelineViewGhostItem::kAttachedBlock)); NodeInput* transition_input_to_connect; if (ghost_->GetMode() == Timeline::kTrimIn) {