timeline: various work to improve timeline behavior, particularly when dealing with transitions
This commit is contained in:
@@ -256,6 +256,39 @@ NodeValueTable TransitionBlock::Value(NodeValueDatabase &value) const
|
||||
return table;
|
||||
}
|
||||
|
||||
TransitionBlock *GetBlockTransitionInternal(Block *block, Timeline::MovementMode mode)
|
||||
{
|
||||
// See if this block outputs to a transition
|
||||
foreach (NodeEdgePtr edge, block->output()->edges()) {
|
||||
Node* connected_node = edge->input()->parentNode();
|
||||
|
||||
if (connected_node->IsBlock()) {
|
||||
Block* connected_block = static_cast<Block*>(connected_node);
|
||||
|
||||
if (connected_block->type() == Block::kTransition) {
|
||||
TransitionBlock* connected_transition = static_cast<TransitionBlock*>(connected_block);
|
||||
|
||||
if ((mode == Timeline::kTrimIn && edge->input() == connected_transition->in_block_input())
|
||||
|| (mode == Timeline::kTrimOut && edge->input() == connected_transition->out_block_input())) {
|
||||
return connected_transition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TransitionBlock *TransitionBlock::GetBlockInTransition(Block *block)
|
||||
{
|
||||
return GetBlockTransitionInternal(block, Timeline::kTrimIn);
|
||||
}
|
||||
|
||||
TransitionBlock *TransitionBlock::GetBlockOutTransition(Block *block)
|
||||
{
|
||||
return GetBlockTransitionInternal(block, Timeline::kTrimOut);
|
||||
}
|
||||
|
||||
void TransitionBlock::ShaderJobEvent(NodeValueDatabase &value, ShaderJob &job) const
|
||||
{
|
||||
Q_UNUSED(value)
|
||||
|
||||
@@ -51,6 +51,10 @@ public:
|
||||
|
||||
virtual NodeValueTable Value(NodeValueDatabase &value) const override;
|
||||
|
||||
static TransitionBlock* GetBlockInTransition(Block* block);
|
||||
|
||||
static TransitionBlock* GetBlockOutTransition(Block* block);
|
||||
|
||||
protected:
|
||||
virtual void ShaderJobEvent(NodeValueDatabase &value, ShaderJob& job) const;
|
||||
|
||||
|
||||
+5
-2
@@ -556,7 +556,7 @@ bool Node::OutputsTo(const QString &id, bool recursively) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Node::OutputsTo(NodeInput *input, bool recursively) const
|
||||
bool Node::OutputsTo(NodeInput *input, bool recursively, bool include_arrays) const
|
||||
{
|
||||
QList<NodeOutput*> outputs = GetOutputs();
|
||||
|
||||
@@ -566,7 +566,10 @@ bool Node::OutputsTo(NodeInput *input, bool recursively) const
|
||||
|
||||
if (connected == input) {
|
||||
return true;
|
||||
} else if (recursively && connected->parentNode()->OutputsTo(input, recursively)) {
|
||||
} else if (include_arrays && input->IsArray()
|
||||
&& static_cast<NodeInputArray*>(input)->sub_params().contains(connected)) {
|
||||
return true;
|
||||
} else if (recursively && connected->parentNode()->OutputsTo(input, recursively, include_arrays)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ public:
|
||||
/**
|
||||
* @brief Same as OutputsTo(Node*), but for a specific node input rather than just a node.
|
||||
*/
|
||||
bool OutputsTo(NodeInput* input, bool recursively) const;
|
||||
bool OutputsTo(NodeInput* input, bool recursively, bool include_arrays) const;
|
||||
|
||||
/**
|
||||
* @brief Returns whether this node ever receives an input from a particular node instance
|
||||
|
||||
@@ -472,67 +472,13 @@ void TimelineWidget::SplitAtPlayhead()
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::DeleteSelectedInternal(const QList<Block *> &blocks,
|
||||
bool transition_aware,
|
||||
void TimelineWidget::ReplaceBlocksWithGaps(const QList<Block *> &blocks,
|
||||
bool remove_from_graph,
|
||||
QUndoCommand *command)
|
||||
{
|
||||
foreach (Block* b, blocks) {
|
||||
TrackOutput* original_track = TrackOutput::TrackFromBlock(b);
|
||||
|
||||
/*if (transition_aware && b->type() == Block::kTransition) {
|
||||
// Deleting transitions restores their in/out offsets to their attached blocks
|
||||
TransitionBlock* transition = static_cast<TransitionBlock*>(b);
|
||||
|
||||
// Ripple remove transition
|
||||
new TrackRippleRemoveBlockCommand(original_track,
|
||||
transition,
|
||||
command);
|
||||
|
||||
// Resize attached blocks to make up length
|
||||
if (transition->connected_in_block()) {
|
||||
new BlockResizeWithMediaInCommand(transition->connected_in_block(),
|
||||
transition->connected_in_block()->length() + transition->in_offset(),
|
||||
command);
|
||||
}
|
||||
|
||||
if (transition->connected_out_block()) {
|
||||
new BlockResizeCommand(transition->connected_out_block(),
|
||||
transition->connected_out_block()->length() + transition->out_offset(),
|
||||
command);
|
||||
}
|
||||
} else */
|
||||
|
||||
|
||||
/*
|
||||
if (b->next()) {
|
||||
|
||||
new TrackRippleRemoveBlockCommand(original_track, b, command);
|
||||
|
||||
if (b->previous() && b->previous()->type() == Block::kGap
|
||||
&& b->next() && b->next()->type() == Block::kGap) {
|
||||
|
||||
// Both previous AND next are blocks. We'll want to merge them together.
|
||||
new TrackRippleRemoveBlockCommand(original_track, b->next(), command);
|
||||
|
||||
} else {
|
||||
|
||||
// Make new gap and replace old Block with it for now
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length_and_media_out(b->length());
|
||||
|
||||
new NodeAddCommand(static_cast<NodeGraph*>(b->parent()),
|
||||
gap,
|
||||
command);
|
||||
|
||||
new TrackReplaceBlockCommand(original_track,
|
||||
b,
|
||||
gap,
|
||||
command);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
new TrackReplaceBlockWithGapCommand(original_track, b, command);
|
||||
|
||||
if (remove_from_graph) {
|
||||
@@ -566,17 +512,30 @@ void TimelineWidget::DeleteSelected(bool ripple)
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Replace blocks with gaps (effectively deleting them)
|
||||
DeleteSelectedInternal(blocks_to_delete, true, true, command);
|
||||
QList<Block*> clips_to_delete;
|
||||
QList<TransitionBlock*> transitions_to_delete;
|
||||
|
||||
/*
|
||||
// Clean each track
|
||||
foreach (const TrackReference& track, tracks_affected) {
|
||||
new TrackCleanGapsCommand(GetConnectedNode()->track_list(track.type()),
|
||||
track.index(),
|
||||
command);
|
||||
foreach (Block* b, blocks_to_delete) {
|
||||
if (b->type() == Block::kClip) {
|
||||
clips_to_delete.append(b);
|
||||
} else if (b->type() == Block::kTransition) {
|
||||
transitions_to_delete.append(static_cast<TransitionBlock*>(b));
|
||||
}
|
||||
}
|
||||
|
||||
// Replace clips with gaps (effectively deleting them)
|
||||
ReplaceBlocksWithGaps(clips_to_delete, true, command);
|
||||
|
||||
// For transitions, remove them but extend their attached blocks to fill their place
|
||||
foreach (TransitionBlock* transition, transitions_to_delete) {
|
||||
new TransitionRemoveCommand(TrackOutput::TrackFromBlock(transition),
|
||||
transition,
|
||||
command);
|
||||
|
||||
new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(GetConnectedNode()->parent()),
|
||||
transition,
|
||||
command);
|
||||
}
|
||||
*/
|
||||
|
||||
// Insert ripple command now that it's all cleaned up gaps
|
||||
if (ripple) {
|
||||
@@ -634,12 +593,16 @@ void TimelineWidget::ToggleLinksOnSelected()
|
||||
{
|
||||
QList<TimelineViewBlockItem*> sel = GetSelectedBlocks();
|
||||
|
||||
// Prioritize unlinking
|
||||
|
||||
QList<Block*> blocks;
|
||||
bool link = true;
|
||||
|
||||
foreach (TimelineViewBlockItem* item, sel) {
|
||||
// Only clips can be linked
|
||||
if (item->block()->type() != Block::kClip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prioritize unlinking, if any block has links, assume we're unlinking
|
||||
if (link && item->block()->HasLinks()) {
|
||||
link = false;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include "core.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/output/viewer/viewer.h"
|
||||
#include "snapservice.h"
|
||||
#include "timeline/timelinecommon.h"
|
||||
@@ -189,18 +190,18 @@ private:
|
||||
* Validation is the process of ensuring that whatever movements the user is making are "valid" and "legal". This
|
||||
* function's validation ensures that no Ghost's in point ends up in a negative timecode.
|
||||
*/
|
||||
rational ValidateTimeMovement(rational movement, const QVector<TimelineViewGhostItem*> ghosts);
|
||||
rational ValidateTimeMovement(rational movement);
|
||||
|
||||
/**
|
||||
* @brief Validates Ghosts that are moving vertically (track-based)
|
||||
*
|
||||
* This function's validation ensures that no Ghost's track ends up in a negative (non-existent) track.
|
||||
*/
|
||||
int ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem*> ghosts);
|
||||
int ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> &ghosts);
|
||||
|
||||
void GetGhostData(const QVector<TimelineViewGhostItem*>& ghosts, rational *earliest_point, rational *latest_point);
|
||||
void GetGhostData(rational *earliest_point, rational *latest_point);
|
||||
|
||||
void InsertGapsAtGhostDestination(const QVector<TimelineViewGhostItem*>& ghosts, QUndoCommand* command);
|
||||
void InsertGapsAtGhostDestination(QUndoCommand* command);
|
||||
|
||||
QList<rational> snap_points_;
|
||||
|
||||
@@ -242,9 +243,9 @@ private:
|
||||
virtual void InitiateDrag(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode);
|
||||
|
||||
TimelineViewGhostItem* AddGhostFromBlock(Block *block, const TrackReference& track, Timeline::MovementMode mode);
|
||||
TimelineViewGhostItem* AddGhostFromBlock(Block *block, const TrackReference& track, Timeline::MovementMode mode, bool trim_overwrite_allowed);
|
||||
|
||||
TimelineViewGhostItem* AddGhostFromNull(const rational& in, const rational& out, const TrackReference& track, Timeline::MovementMode mode);
|
||||
TimelineViewGhostItem* AddGhostFromNull(const rational& in, const rational& out, const TrackReference& track, Timeline::MovementMode mode, bool trim_overwrite_allowed);
|
||||
|
||||
/**
|
||||
* @brief Validates Ghosts that are getting their in points trimmed
|
||||
@@ -252,7 +253,7 @@ private:
|
||||
* Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no
|
||||
* Ghost's length becomes 0 or negative.
|
||||
*/
|
||||
rational ValidateInTrimming(rational movement, const QVector<TimelineViewGhostItem*> ghosts, bool prevent_overwriting);
|
||||
rational ValidateInTrimming(rational movement);
|
||||
|
||||
/**
|
||||
* @brief Validates Ghosts that are getting their out points trimmed
|
||||
@@ -260,10 +261,21 @@ private:
|
||||
* Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no
|
||||
* Ghost's length becomes 0 or negative.
|
||||
*/
|
||||
rational ValidateOutTrimming(rational movement, const QVector<TimelineViewGhostItem*> ghosts, bool prevent_overwriting);
|
||||
rational ValidateOutTrimming(rational movement);
|
||||
|
||||
virtual void ProcessDrag(const TimelineCoordinate &mouse_pos);
|
||||
|
||||
enum GhostMode {
|
||||
kPointer,
|
||||
kRolling,
|
||||
kSlide
|
||||
};
|
||||
|
||||
void InitiateDragInternal(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode,
|
||||
GhostMode pointer_mode,
|
||||
bool trim_overwrite_allowed);
|
||||
|
||||
const Timeline::MovementMode& drag_movement_mode() const
|
||||
{
|
||||
return drag_movement_mode_;
|
||||
@@ -284,11 +296,6 @@ private:
|
||||
track_movement_allowed_ = e;
|
||||
}
|
||||
|
||||
void SetTrimOverwriteAllowed(bool e)
|
||||
{
|
||||
trim_overwrite_allowed_ = e;
|
||||
}
|
||||
|
||||
void SetGapTrimmingAllowed(bool e)
|
||||
{
|
||||
gap_trimming_allowed_ = e;
|
||||
@@ -297,16 +304,21 @@ private:
|
||||
private:
|
||||
Timeline::MovementMode IsCursorInTrimHandle(TimelineViewBlockItem* block, qreal cursor_x);
|
||||
|
||||
void AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode);
|
||||
void AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode, bool trim_overwrite_allowed);
|
||||
|
||||
bool IsClipTrimmable(TimelineViewBlockItem* clip,
|
||||
const QList<TimelineViewBlockItem*>& items,
|
||||
const Timeline::MovementMode& mode);
|
||||
|
||||
void ProcessGhostsForSliding();
|
||||
|
||||
void ProcessGhostsForRolling();
|
||||
|
||||
bool AddMovingTransitionsToClipGhost(Block *block, const TrackReference &track, Timeline::MovementMode movement, const QList<TimelineViewBlockItem *> &selected_items);
|
||||
|
||||
bool movement_allowed_;
|
||||
bool trimming_allowed_;
|
||||
bool track_movement_allowed_;
|
||||
bool trim_overwrite_allowed_;
|
||||
bool gap_trimming_allowed_;
|
||||
bool rubberband_selecting_;
|
||||
|
||||
@@ -383,8 +395,6 @@ private:
|
||||
RollingTool(TimelineWidget* parent);
|
||||
|
||||
protected:
|
||||
virtual void FinishDrag(TimelineViewMouseEvent *event) override;
|
||||
|
||||
virtual void InitiateDrag(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode) override;
|
||||
};
|
||||
@@ -395,7 +405,6 @@ private:
|
||||
SlideTool(TimelineWidget* parent);
|
||||
|
||||
protected:
|
||||
virtual void FinishDrag(TimelineViewMouseEvent *event) override;
|
||||
virtual void InitiateDrag(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode) override;
|
||||
|
||||
@@ -455,7 +464,7 @@ private:
|
||||
|
||||
void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command);
|
||||
|
||||
void DeleteSelectedInternal(const QList<Block *>& blocks, bool transition_aware, bool remove_from_graph, QUndoCommand* command);
|
||||
void ReplaceBlocksWithGaps(const QList<Block *>& blocks, bool remove_from_graph, QUndoCommand* command);
|
||||
|
||||
void SetBlockLinksSelected(Block *block, bool selected);
|
||||
|
||||
|
||||
@@ -123,14 +123,14 @@ void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event)
|
||||
rational time_movement = event->GetFrame() - drag_start_.GetFrame();
|
||||
int track_movement = event->GetTrack().index() - drag_start_.GetTrack().index();
|
||||
|
||||
time_movement = ValidateTimeMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateTimeMovement(time_movement);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
// If snapping is enabled, check for snap points
|
||||
if (Core::instance()->snapping()) {
|
||||
parent()->SnapPoint(snap_points_, &time_movement);
|
||||
|
||||
time_movement = ValidateTimeMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateTimeMovement(time_movement);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ void TimelineWidget::ImportTool::DropGhosts(bool insert)
|
||||
|
||||
// Check if we're inserting
|
||||
if (insert) {
|
||||
InsertGapsAtGhostDestination(parent()->ghost_items_, command);
|
||||
InsertGapsAtGhostDestination(command);
|
||||
}
|
||||
|
||||
for (int i=0;i<parent()->ghost_items_.size();i++) {
|
||||
|
||||
@@ -41,7 +41,6 @@ TimelineWidget::PointerTool::PointerTool(TimelineWidget *parent) :
|
||||
movement_allowed_(true),
|
||||
trimming_allowed_(true),
|
||||
track_movement_allowed_(true),
|
||||
trim_overwrite_allowed_(false),
|
||||
gap_trimming_allowed_(false),
|
||||
rubberband_selecting_(false)
|
||||
{
|
||||
@@ -119,31 +118,31 @@ void TimelineWidget::PointerTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
if (rubberband_selecting_) {
|
||||
// Process rubberband select
|
||||
parent()->MoveRubberBandSelect(true, !(event->GetModifiers() & Qt::AltModifier));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Process drag
|
||||
if (!dragging_) {
|
||||
|
||||
if (!dragging_) {
|
||||
// Now that the cursor has moved, we will assume the intention is to drag
|
||||
|
||||
// Now that the cursor has moved, we will assume the intention is to drag
|
||||
// Clear snap points
|
||||
snap_points_.clear();
|
||||
|
||||
// Clear snap points
|
||||
snap_points_.clear();
|
||||
// If we're performing an action, we can initiate ghosts
|
||||
if (drag_movement_mode_ != Timeline::kNone) {
|
||||
InitiateDrag(clicked_item_, drag_movement_mode_);
|
||||
}
|
||||
|
||||
// Set dragging to true here so no matter what, the drag isn't re-initiated until it's completed
|
||||
dragging_ = true;
|
||||
|
||||
// If we're performing an action, we can initiate ghosts
|
||||
if (drag_movement_mode_ != Timeline::kNone) {
|
||||
InitiateDrag(clicked_item_, drag_movement_mode_);
|
||||
}
|
||||
|
||||
// Set dragging to true here so no matter what, the drag isn't re-initiated until it's completed
|
||||
dragging_ = true;
|
||||
if (dragging_ && !parent()->ghost_items_.isEmpty()) {
|
||||
|
||||
}
|
||||
|
||||
if (dragging_ && !parent()->ghost_items_.isEmpty()) {
|
||||
|
||||
// We're already dragging AND we have ghosts to work with
|
||||
ProcessDrag(event->GetCoordinates());
|
||||
// We're already dragging AND we have ghosts to work with
|
||||
ProcessDrag(event->GetCoordinates());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +156,12 @@ void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
}
|
||||
|
||||
if (dragging_) {
|
||||
// If we were dragging, process the end of the drag
|
||||
if (!parent()->ghost_items_.isEmpty()) {
|
||||
FinishDrag(event);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
parent()->ClearGhosts();
|
||||
snap_points_.clear();
|
||||
|
||||
@@ -193,92 +194,141 @@ void TimelineWidget::PointerTool::HoverMove(TimelineViewMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event)
|
||||
void TimelineWidget::PointerTool::InitiateDragInternal(TimelineViewBlockItem *clicked_item,
|
||||
Timeline::MovementMode trim_mode,
|
||||
GhostMode pointer_mode,
|
||||
bool trim_overwrite_allowed)
|
||||
{
|
||||
QList<TimelineViewGhostItem*> ghosts_moving;
|
||||
QList<Block*> blocks_moving;
|
||||
QList<TimelineViewGhostItem*> ghosts_trimming;
|
||||
QList<Block*> blocks_trimming;
|
||||
// Get list of selected blocks
|
||||
QList<TimelineViewBlockItem*> clips = parent()->GetSelectedBlocks();
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (!ghost->HasBeenAdjusted()) {
|
||||
continue;
|
||||
if (trim_mode == Timeline::kMove) {
|
||||
|
||||
// Each block type has different behavior, so we determine the type of the block that was
|
||||
// clicked and filter out any others.
|
||||
Block::Type clicked_block_type = clicked_item->block()->type();
|
||||
|
||||
// Gaps are not allowed to move, and since we only allow moving one block type at a time,
|
||||
// dragging a gap is a no-op
|
||||
if (clicked_block_type == Block::kGap) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
// Create ghosts for moving
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
Block* block = clip_item->block();
|
||||
|
||||
if (ghost->mode() == Timeline::kMove) {
|
||||
ghosts_moving.append(ghost);
|
||||
blocks_moving.append(b);
|
||||
} else if (Timeline::IsATrimMode(ghost->mode())) {
|
||||
ghosts_trimming.append(ghost);
|
||||
blocks_trimming.append(b);
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks_moving.isEmpty() && blocks_trimming.isEmpty()) {
|
||||
// Likely means no block was adjusted, so we can skip the rest of the processing
|
||||
return;
|
||||
}
|
||||
|
||||
// See if we're duplicated because ALT is held (only moved blocks can duplicate)
|
||||
bool duplicate_clips = (!blocks_moving.isEmpty() && event->GetModifiers() & Qt::AltModifier);
|
||||
bool inserting = (!blocks_moving.isEmpty() && event->GetModifiers() & Qt::ControlModifier);
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
for (int i=0;i<ghosts_trimming.size();i++) {
|
||||
TimelineViewGhostItem* ghost = ghosts_trimming.at(i);
|
||||
|
||||
new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()),
|
||||
blocks_trimming.at(i),
|
||||
ghost->AdjustedLength(),
|
||||
ghost->mode(),
|
||||
command);
|
||||
}
|
||||
|
||||
if (!blocks_moving.isEmpty()) {
|
||||
// If we're not duplicating, "remove" the clips and replace them with gaps
|
||||
if (!duplicate_clips) {
|
||||
parent()->DeleteSelectedInternal(blocks_moving, false, false, command);
|
||||
}
|
||||
|
||||
if (inserting) {
|
||||
// If we're inserting, ripple everything at the destination with gaps
|
||||
InsertGapsAtGhostDestination(parent()->ghost_items_, command);
|
||||
}
|
||||
|
||||
// Now we can re-add each clip
|
||||
for (int i=0;i<ghosts_moving.size();i++) {
|
||||
TimelineViewGhostItem* ghost = ghosts_moving.at(i);
|
||||
Block* block = blocks_moving.at(i);
|
||||
|
||||
if (duplicate_clips) {
|
||||
// Duplicate rather than move
|
||||
Node* copy = block->copy();
|
||||
|
||||
new NodeAddCommand(static_cast<NodeGraph*>(block->parent()),
|
||||
copy,
|
||||
command);
|
||||
|
||||
new NodeCopyInputsCommand(block, copy, true, command);
|
||||
|
||||
// Place the copy instead of the original block
|
||||
block = static_cast<Block*>(copy);
|
||||
if (block->type() == Block::kGap) {
|
||||
// Gaps cannot move, ignore this block
|
||||
continue;
|
||||
}
|
||||
|
||||
const TrackReference& track_ref = ghost->GetAdjustedTrack();
|
||||
new TrackPlaceBlockCommand(parent()->GetConnectedNode()->track_list(track_ref.type()),
|
||||
track_ref.index(),
|
||||
block,
|
||||
ghost->GetAdjustedIn(),
|
||||
command);
|
||||
if (clicked_block_type == Block::kTransition && block->type() != Block::kTransition) {
|
||||
// Transitions always slide rather than move, so if we clicked a transition, ignore any
|
||||
// non-transitions
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create ghost
|
||||
TimelineViewGhostItem* ghost = AddGhostFromBlock(block, clip_item->Track(),
|
||||
trim_mode, trim_overwrite_allowed);
|
||||
|
||||
if (clicked_block_type == Block::kTransition) {
|
||||
// Transition moves are always a slide
|
||||
ghost->setData(TimelineViewGhostItem::kPointerToolMode, kSlide);
|
||||
} else {
|
||||
// Set to default behavior
|
||||
ghost->setData(TimelineViewGhostItem::kPointerToolMode, pointer_mode);
|
||||
|
||||
// Include transitions (if any)
|
||||
AddMovingTransitionsToClipGhost(block, clip_item->Track(), trim_mode, clips);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Heavy optimization since MOST of the timeline does NOT change in this time
|
||||
}
|
||||
// If we slid the blocks, we must process them as such
|
||||
if (clicked_block_type == Block::kTransition || pointer_mode == kSlide) {
|
||||
ProcessGhostsForSliding();
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
} else {
|
||||
|
||||
// "Multi-trim" is trimming a clip on more than one track. Only the earliest (for in trimming)
|
||||
// or latest (for out trimming) clip on each track can be trimmed. Therefore, it's only enabled
|
||||
// if the clicked item is the earliest/latest on its track.
|
||||
bool multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
|
||||
// Create ghosts for trimming
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
if (clip_item != clicked_item
|
||||
&& (!multitrim_enabled || !IsClipTrimmable(clip_item, clips, trim_mode))) {
|
||||
// Either multitrim is disabled or this clip is NOT the earliest/latest in its track. We
|
||||
// won't include it.
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = clip_item->block();
|
||||
Timeline::MovementMode block_mode = trim_mode;
|
||||
bool block_trim_overwrite_allowed = trim_overwrite_allowed;
|
||||
|
||||
// Some tools interpret "gap trimming" as equivalent to resizing the adjacent block. In that
|
||||
// scenario, we include the adjacent block instead.
|
||||
if (block->type() == Block::kGap && !gap_trimming_allowed_) {
|
||||
block = (trim_mode == Timeline::kTrimIn) ? block->previous() : block->next();
|
||||
block_mode = FlipTrimMode(trim_mode);
|
||||
|
||||
// If there's no adjacent block, do nothing here
|
||||
if (!block) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// For transitions, we create a rolling edit with the attached clip
|
||||
if (block->type() == Block::kTransition) {
|
||||
TransitionBlock* transition = static_cast<TransitionBlock*>(block);
|
||||
TimelineViewGhostItem* g = nullptr;
|
||||
|
||||
Block* previous = transition->previous();
|
||||
Block* next = transition->next();
|
||||
|
||||
if (block_mode == Timeline::kTrimIn
|
||||
&& previous
|
||||
&& (previous == transition->connected_out_block() || previous->type() == Block::kGap)) {
|
||||
g = AddGhostFromBlock(previous, clip_item->Track(), Timeline::kTrimOut, true);
|
||||
} else if (block_mode == Timeline::kTrimOut
|
||||
&& next
|
||||
&& (next == transition->connected_in_block() || next->type() == Block::kGap)) {
|
||||
g = AddGhostFromBlock(next, clip_item->Track(), Timeline::kTrimIn, true);
|
||||
}
|
||||
|
||||
if (g) {
|
||||
g->setData(TimelineViewGhostItem::kPointerToolMode, kRolling);
|
||||
block_trim_overwrite_allowed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ghost for this block
|
||||
TimelineViewGhostItem* ghost = AddGhostFromBlock(block, clip_item->Track(), block_mode, block_trim_overwrite_allowed);
|
||||
|
||||
if (block->type() == Block::kTransition) {
|
||||
|
||||
// If this is a transition, set to rolling as above
|
||||
ghost->setData(TimelineViewGhostItem::kPointerToolMode, kRolling);
|
||||
|
||||
} else {
|
||||
|
||||
// For trimmed clips, we also "move" the transitions if any are attached
|
||||
if (AddMovingTransitionsToClipGhost(block, clip_item->Track(), trim_mode, clips)) {
|
||||
ghost->setData(TimelineViewGhostItem::kPointerToolMode, kSlide);
|
||||
} else {
|
||||
ghost->setData(TimelineViewGhostItem::kPointerToolMode, kPointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pointer_mode == kRolling) {
|
||||
ProcessGhostsForRolling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos)
|
||||
@@ -292,17 +342,17 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po
|
||||
rational time_movement = mouse_pos.GetFrame() - drag_start_.GetFrame();
|
||||
|
||||
// Validate movement (enforce all ghosts moving in legal ways)
|
||||
time_movement = ValidateTimeMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateInTrimming(time_movement, parent()->ghost_items_, !trim_overwrite_allowed_);
|
||||
time_movement = ValidateOutTrimming(time_movement, parent()->ghost_items_, !trim_overwrite_allowed_);
|
||||
time_movement = ValidateTimeMovement(time_movement);
|
||||
time_movement = ValidateInTrimming(time_movement);
|
||||
time_movement = ValidateOutTrimming(time_movement);
|
||||
|
||||
// Perform snapping if enabled (adjusts time_movement if it's close to any potential snap points)
|
||||
if (Core::instance()->snapping()) {
|
||||
parent()->SnapPoint(snap_points_, &time_movement);
|
||||
|
||||
time_movement = ValidateTimeMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateInTrimming(time_movement, parent()->ghost_items_, !trim_overwrite_allowed_);
|
||||
time_movement = ValidateOutTrimming(time_movement, parent()->ghost_items_, !trim_overwrite_allowed_);
|
||||
time_movement = ValidateTimeMovement(time_movement);
|
||||
time_movement = ValidateInTrimming(time_movement);
|
||||
time_movement = ValidateOutTrimming(time_movement);
|
||||
}
|
||||
|
||||
// Validate ghosts that are being moved (clips from other track types do NOT get moved)
|
||||
@@ -357,6 +407,140 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po
|
||||
parent());
|
||||
}
|
||||
|
||||
struct GhostBlockPair {
|
||||
TimelineViewGhostItem* ghost;
|
||||
Block* block;
|
||||
};
|
||||
|
||||
void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event)
|
||||
{
|
||||
QList<GhostBlockPair> blocks_moving;
|
||||
QList<GhostBlockPair> blocks_sliding;
|
||||
QList<GhostBlockPair> blocks_trimming;
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->HasBeenAdjusted()) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == Timeline::kMove) {
|
||||
if (ghost->data(TimelineViewGhostItem::kPointerToolMode) == kSlide) {
|
||||
blocks_sliding.append({ghost, b});
|
||||
} else {
|
||||
blocks_moving.append({ghost, b});
|
||||
}
|
||||
} else if (Timeline::IsATrimMode(ghost->mode())) {
|
||||
blocks_trimming.append({ghost, b});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks_moving.isEmpty()
|
||||
&& blocks_trimming.isEmpty()
|
||||
&& blocks_sliding.isEmpty()) {
|
||||
// No blocks were adjusted, so nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
// See if we're duplicated because ALT is held (only moved blocks can duplicate)
|
||||
bool duplicate_clips = (!blocks_moving.isEmpty() && event->GetModifiers() & Qt::AltModifier);
|
||||
bool inserting = (!blocks_moving.isEmpty() && event->GetModifiers() & Qt::ControlModifier);
|
||||
|
||||
// Slide info
|
||||
QVector<TrackSlideCommand::BlockSlideInfo> slide_info;
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
foreach (const GhostBlockPair& p, blocks_trimming) {
|
||||
TimelineViewGhostItem* ghost = p.ghost;
|
||||
|
||||
GhostMode m = static_cast<GhostMode>(ghost->data(TimelineViewGhostItem::kPointerToolMode).toInt());
|
||||
|
||||
switch (m) {
|
||||
case kPointer:
|
||||
case kRolling:
|
||||
if (m != kRolling || ghost->mode() == drag_movement_mode()) {
|
||||
BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()),
|
||||
p.block,
|
||||
ghost->AdjustedLength(),
|
||||
ghost->mode(),
|
||||
command);
|
||||
|
||||
if (m == kRolling) {
|
||||
c->SetAllowNonGapTrimming(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kSlide:
|
||||
slide_info.append({parent()->GetTrackFromReference(ghost->Track()),
|
||||
p.block,
|
||||
ghost->mode(),
|
||||
ghost->AdjustedLength(),
|
||||
ghost->Length()});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!blocks_moving.isEmpty()) {
|
||||
// If we're not duplicating, "remove" the clips and replace them with gaps
|
||||
if (!duplicate_clips) {
|
||||
QList<Block*> blocks_to_delete;
|
||||
|
||||
foreach (const GhostBlockPair& p, blocks_moving) {
|
||||
blocks_to_delete.append(p.block);
|
||||
}
|
||||
|
||||
parent()->ReplaceBlocksWithGaps(blocks_to_delete, false, command);
|
||||
}
|
||||
|
||||
if (inserting) {
|
||||
// If we're inserting, ripple everything at the destination with gaps
|
||||
InsertGapsAtGhostDestination(command);
|
||||
}
|
||||
|
||||
// Now we can re-add each clip
|
||||
foreach (const GhostBlockPair& p, blocks_moving) {
|
||||
Block* block = p.block;
|
||||
|
||||
if (duplicate_clips) {
|
||||
// Duplicate rather than move
|
||||
Node* copy = block->copy();
|
||||
|
||||
new NodeAddCommand(static_cast<NodeGraph*>(block->parent()),
|
||||
copy,
|
||||
command);
|
||||
|
||||
new NodeCopyInputsCommand(block, copy, true, command);
|
||||
|
||||
// Place the copy instead of the original block
|
||||
block = static_cast<Block*>(copy);
|
||||
}
|
||||
|
||||
const TrackReference& track_ref = p.ghost->GetAdjustedTrack();
|
||||
new TrackPlaceBlockCommand(parent()->GetConnectedNode()->track_list(track_ref.type()),
|
||||
track_ref.index(),
|
||||
block,
|
||||
p.ghost->GetAdjustedIn(),
|
||||
command);
|
||||
}
|
||||
}
|
||||
|
||||
if (!blocks_sliding.isEmpty()) {
|
||||
foreach (const GhostBlockPair& p, blocks_sliding) {
|
||||
slide_info.append({parent()->GetTrackFromReference(p.ghost->Track()),
|
||||
p.block,
|
||||
p.ghost->mode(),
|
||||
p.ghost->GetAdjustedIn(),
|
||||
p.ghost->In()});
|
||||
}
|
||||
}
|
||||
|
||||
if (!slide_info.isEmpty()) {
|
||||
new TrackSlideCommand(slide_info, command);
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
Timeline::MovementMode TimelineWidget::PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x)
|
||||
{
|
||||
double kTrimHandle = QFontMetricsWidth(parent()->fontMetrics(), "H");
|
||||
@@ -378,73 +562,22 @@ Timeline::MovementMode TimelineWidget::PointerTool::IsCursorInTrimHandle(Timelin
|
||||
void TimelineWidget::PointerTool::InitiateDrag(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode)
|
||||
{
|
||||
// Get list of selected blocks
|
||||
QList<TimelineViewBlockItem*> clips = parent()->GetSelectedBlocks();
|
||||
|
||||
if (trim_mode == Timeline::kMove) {
|
||||
|
||||
// Create ghosts for moving
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
|
||||
// Gaps are not allowed to move, so we ignore those here
|
||||
if (clip_item->block()->type() == Block::kGap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AddGhostFromBlock(clip_item->block(), clip_item->Track(), trim_mode);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// "Multi-trim" is trimming a clip on more than one track. Only the earliest (for in trimming)
|
||||
// or latest (for out trimming) clip on each track can be trimmed. Therefore, it's only enabled
|
||||
// if the clicked item is the earliest/latest on its track.
|
||||
bool multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
|
||||
// Create ghosts for trimming
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
if (clip_item != clicked_item
|
||||
&& (!multitrim_enabled || !IsClipTrimmable(clip_item, clips, trim_mode))) {
|
||||
// Either multitrim is disabled or this clip is NOT the earliest/latest in its track. We
|
||||
// won't include it.
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = clip_item->block();
|
||||
Timeline::MovementMode block_mode = trim_mode;
|
||||
|
||||
// Some tools interpret "gap trimming" as equivalent to resizing the adjacent block. In that
|
||||
// scenario, we include the adjacent block instead.
|
||||
if (block->type() == Block::kGap && !gap_trimming_allowed_) {
|
||||
block = (trim_mode == Timeline::kTrimIn) ? block->previous() : block->next();
|
||||
block_mode = FlipTrimMode(trim_mode);
|
||||
|
||||
// If there's no adjacent block, do nothing here
|
||||
if (!block) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ghost for this block
|
||||
AddGhostFromBlock(block, clip_item->Track(), block_mode);
|
||||
}
|
||||
|
||||
}
|
||||
InitiateDragInternal(clicked_item, trim_mode, kPointer, false);
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromBlock(Block* block, const TrackReference& track, Timeline::MovementMode mode)
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromBlock(Block* block, const TrackReference& track, Timeline::MovementMode mode, bool trim_overwrite_allowed)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromBlock(block,
|
||||
track,
|
||||
parent()->GetTrackY(track),
|
||||
parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
AddGhostInternal(ghost, mode, trim_overwrite_allowed);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const rational &in, const rational &out, const TrackReference& track, Timeline::MovementMode mode)
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const rational &in, const rational &out, const TrackReference& track, Timeline::MovementMode mode, bool trim_overwrite_allowed)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
@@ -453,14 +586,15 @@ TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const ratio
|
||||
ghost->SetTrack(track);
|
||||
ghost->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
AddGhostInternal(ghost, mode, trim_overwrite_allowed);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode)
|
||||
void TimelineWidget::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode, bool trim_overwrite_allowed)
|
||||
{
|
||||
ghost->SetMode(mode);
|
||||
ghost->setData(TimelineViewGhostItem::kTrimOverwriteAllowed, trim_overwrite_allowed);
|
||||
|
||||
// Prepare snap points (optimizes snapping for later)
|
||||
switch (mode) {
|
||||
@@ -497,11 +631,145 @@ bool TimelineWidget::PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip,
|
||||
return true;
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
struct TrackBlockListPair {
|
||||
TrackReference track;
|
||||
QList<Block*> blocks;
|
||||
};
|
||||
|
||||
void TimelineWidget::PointerTool::ProcessGhostsForSliding()
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
// Sort blocks into tracks
|
||||
QList<TrackBlockListPair> blocks_per_track;
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
bool found = false;
|
||||
|
||||
for (int i=0;i<blocks_per_track.size();i++) {
|
||||
if (blocks_per_track.at(i).track == ghost->Track()) {
|
||||
blocks_per_track[i].blocks.append(b);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
blocks_per_track.append({ghost->Track(), {b}});
|
||||
}
|
||||
}
|
||||
|
||||
// Make contiguous runs of blocks per each track
|
||||
foreach (const TrackBlockListPair& p, blocks_per_track) {
|
||||
// Blocks must be merged if any are non-adjacent
|
||||
const TrackReference& track = p.track;
|
||||
const QList<Block*>& blocks = p.blocks;
|
||||
|
||||
Block* earliest_block = blocks.first();
|
||||
Block* latest_block = blocks.first();
|
||||
|
||||
// Find the earliest and latest selected blocks
|
||||
for (int j=1;j<blocks.size();j++) {
|
||||
Block* compare = blocks.at(j);
|
||||
|
||||
if (compare->in() < earliest_block->in()) {
|
||||
earliest_block = compare;
|
||||
}
|
||||
|
||||
if (compare->in() > latest_block->in()) {
|
||||
latest_block = compare;
|
||||
}
|
||||
}
|
||||
|
||||
// Add any blocks between these blocks that aren't already in the list
|
||||
if (earliest_block != latest_block) {
|
||||
Block* b = earliest_block;
|
||||
while ((b = b->next()) != latest_block) {
|
||||
if (!blocks.contains(b)) {
|
||||
TimelineViewGhostItem* g = AddGhostFromBlock(b, track, Timeline::kMove, true);
|
||||
g->setData(TimelineViewGhostItem::kPointerToolMode, kSlide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add surrounding blocks that will be trimming instead of moving
|
||||
if (earliest_block->previous()) {
|
||||
TimelineViewGhostItem* g = AddGhostFromBlock(earliest_block->previous(), track, Timeline::kTrimOut, true);
|
||||
g->setData(TimelineViewGhostItem::kPointerToolMode, kSlide);
|
||||
}
|
||||
|
||||
if (latest_block->next()) {
|
||||
TimelineViewGhostItem* g = AddGhostFromBlock(latest_block->next(), track, Timeline::kTrimIn, true);
|
||||
g->setData(TimelineViewGhostItem::kPointerToolMode, kSlide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::ProcessGhostsForRolling()
|
||||
{
|
||||
// For each ghost, we make an equivalent Ghost on the next/previous block
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* ghost_block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == Timeline::kTrimIn && ghost_block->previous()) {
|
||||
// Add an extra Ghost for the previous block
|
||||
AddGhostFromBlock(ghost_block->previous(), ghost->Track(), Timeline::kTrimOut, true);
|
||||
} else if (ghost->mode() == Timeline::kTrimOut && ghost_block->next()) {
|
||||
AddGhostFromBlock(ghost_block->next(), ghost->Track(), Timeline::kTrimIn, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimelineWidget::PointerTool::AddMovingTransitionsToClipGhost(Block* block,
|
||||
const TrackReference& track,
|
||||
Timeline::MovementMode movement,
|
||||
const QList<TimelineViewBlockItem*>& selected_items)
|
||||
{
|
||||
// Assume block is a clip and see if it has any transitions
|
||||
TransitionBlock* transitions[2];
|
||||
|
||||
if (movement == Timeline::kMove || movement == Timeline::kTrimOut) {
|
||||
transitions[0] = TransitionBlock::GetBlockOutTransition(block);
|
||||
} else {
|
||||
transitions[0] = nullptr;
|
||||
}
|
||||
|
||||
if (movement == Timeline::kMove || movement == Timeline::kTrimIn) {
|
||||
transitions[1] = TransitionBlock::GetBlockInTransition(block);
|
||||
} else {
|
||||
transitions[1] = nullptr;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
|
||||
for (int i=0;i<2;i++) {
|
||||
if (!transitions[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
||||
foreach (TimelineViewBlockItem* item, selected_items) {
|
||||
if (item->block() == transitions[i]) {
|
||||
// Do nothing
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
TimelineViewGhostItem* transition_ghost = AddGhostFromBlock(transitions[i], track,
|
||||
Timeline::kMove, false);
|
||||
transition_ghost->setData(TimelineViewGhostItem::kPointerToolMode, kPointer);
|
||||
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->mode() != Timeline::kTrimIn) {
|
||||
continue;
|
||||
}
|
||||
@@ -516,29 +784,7 @@ rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement,
|
||||
}
|
||||
|
||||
if (block) {
|
||||
/* FIXME: Rewrite transition logic
|
||||
if (block->type() == Block::kTransition) {
|
||||
// For transitions, validate with the attached block
|
||||
TransitionBlock* transition = static_cast<TransitionBlock*>(block);
|
||||
|
||||
if (transition->connected_in_block() && transition->connected_out_block()) {
|
||||
// Here, we try to get the latest earliest point for both the in and out blocks, we do in here and out will
|
||||
// be calculated later
|
||||
earliest_in = GetEarliestPointForClip(transition->connected_in_block());
|
||||
|
||||
// We set the block to the out block since that will be before the in block and will be the one we use to
|
||||
// prevent overwriting since we're trimming the in side of this transition
|
||||
block = transition->connected_out_block();
|
||||
|
||||
latest_in = transition->in() + transition->out_offset();
|
||||
} else {
|
||||
// Use whatever block is attached
|
||||
block = transition->connected_in_block() ? transition->connected_in_block() : transition->connected_out_block();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (prevent_overwriting) {
|
||||
if (!ghost->data(TimelineViewGhostItem::kTrimOverwriteAllowed).toBool()) {
|
||||
// Look for a Block in the way
|
||||
Block* prev = block->previous();
|
||||
while (prev != nullptr) {
|
||||
@@ -566,11 +812,9 @@ rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement,
|
||||
return movement;
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->mode() != Timeline::kTrimOut) {
|
||||
continue;
|
||||
}
|
||||
@@ -588,27 +832,7 @@ rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement,
|
||||
|
||||
// Ripple tool creates block-less ghosts and creates gaps with them later
|
||||
if (block) {
|
||||
/* FIXME: Rewrite transition logic
|
||||
if (block->type() == Block::kTransition) {
|
||||
// For transitions, validate with the attached block
|
||||
TransitionBlock* transition = static_cast<TransitionBlock*>(block);
|
||||
|
||||
if (transition->connected_in_block() && transition->connected_out_block()) {
|
||||
// We set the block to the out block since that will be before the in block and will be the one we use to
|
||||
// prevent overwriting since we're trimming the in side of this transition
|
||||
|
||||
// FIXME: At some point we may add some better logic to `latest_out` akin to the logic in ValidateInTrimming
|
||||
// which is why this hasn't yet been collapsed into the ternary below.
|
||||
block = transition->connected_in_block();
|
||||
|
||||
earliest_out = transition->out() - transition->in_offset();
|
||||
} else {
|
||||
block = transition->connected_in_block() ? transition->connected_in_block() : transition->connected_out_block();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (prevent_overwriting) {
|
||||
if (!ghost->data(TimelineViewGhostItem::kTrimOverwriteAllowed).toBool()) {
|
||||
// Determine if there's a block in the way
|
||||
Block* next = block->next();
|
||||
while (next != nullptr) {
|
||||
|
||||
@@ -29,14 +29,13 @@ TimelineWidget::RippleTool::RippleTool(TimelineWidget* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetMovementAllowed(false);
|
||||
SetTrimOverwriteAllowed(true);
|
||||
SetGapTrimmingAllowed(true);
|
||||
}
|
||||
|
||||
void TimelineWidget::RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_item,
|
||||
Timeline::MovementMode trim_mode)
|
||||
{
|
||||
PointerTool::InitiateDrag(clicked_item, trim_mode);
|
||||
InitiateDragInternal(clicked_item, trim_mode, kPointer, true);
|
||||
|
||||
if (parent()->ghost_items_.isEmpty()) {
|
||||
return;
|
||||
@@ -86,16 +85,16 @@ void TimelineWidget::RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_ite
|
||||
|
||||
if (block_before_ripple->type() == Block::kGap) {
|
||||
// If this Block is already a Gap, ghost it now
|
||||
ghost = AddGhostFromBlock(block_before_ripple, track_ref, trim_mode);
|
||||
ghost = AddGhostFromBlock(block_before_ripple, track_ref, trim_mode, true);
|
||||
} else if (block_before_ripple->next()) {
|
||||
// Assuming this block is NOT at the end of the track (i.e. next != null)
|
||||
|
||||
// We're going to create a gap after it. If next is a gap, we can just use that
|
||||
if (block_before_ripple->next()->type() == Block::kGap) {
|
||||
ghost = AddGhostFromBlock(block_before_ripple->next(), track_ref, trim_mode);
|
||||
ghost = AddGhostFromBlock(block_before_ripple->next(), track_ref, trim_mode, true);
|
||||
} 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 = AddGhostFromNull(block_before_ripple->out(), block_before_ripple->out(), track_ref, trim_mode, true);
|
||||
ghost->setData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(block_before_ripple));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,47 +29,13 @@ TimelineWidget::RollingTool::RollingTool(TimelineWidget* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetMovementAllowed(false);
|
||||
SetTrimOverwriteAllowed(true);
|
||||
SetGapTrimmingAllowed(true);
|
||||
}
|
||||
|
||||
void TimelineWidget::RollingTool::InitiateDrag(TimelineViewBlockItem *clicked_item,
|
||||
Timeline::MovementMode trim_mode)
|
||||
{
|
||||
PointerTool::InitiateDrag(clicked_item, trim_mode);
|
||||
|
||||
// For each ghost, we make an equivalent Ghost on the next/previous block
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* ghost_block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == Timeline::kTrimIn && ghost_block->previous()) {
|
||||
// Add an extra Ghost for the previous block
|
||||
AddGhostFromBlock(ghost_block->previous(), ghost->Track(), Timeline::kTrimOut);
|
||||
} else if (ghost->mode() == Timeline::kTrimOut && ghost_block->next()) {
|
||||
AddGhostFromBlock(ghost_block->next(), ghost->Track(), Timeline::kTrimIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::RollingTool::FinishDrag(TimelineViewMouseEvent *event)
|
||||
{
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->mode() == drag_movement_mode()) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->Track()),
|
||||
b,
|
||||
ghost->AdjustedLength(),
|
||||
drag_movement_mode(),
|
||||
command);
|
||||
c->SetAllowNonGapTrimming(true);
|
||||
}
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
InitiateDragInternal(clicked_item, trim_mode, kRolling, true);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -30,105 +30,13 @@ TimelineWidget::SlideTool::SlideTool(TimelineWidget* parent) :
|
||||
{
|
||||
SetTrimmingAllowed(false);
|
||||
SetTrackMovementAllowed(false);
|
||||
SetTrimOverwriteAllowed(true);
|
||||
SetGapTrimmingAllowed(true);
|
||||
}
|
||||
|
||||
struct TrackBlockListPair {
|
||||
TrackReference track;
|
||||
QList<Block*> blocks;
|
||||
};
|
||||
|
||||
void TimelineWidget::SlideTool::InitiateDrag(TimelineViewBlockItem *clicked_item,
|
||||
Timeline::MovementMode trim_mode)
|
||||
{
|
||||
PointerTool::InitiateDrag(clicked_item, trim_mode);
|
||||
|
||||
// Sort blocks into tracks
|
||||
QList<TrackBlockListPair> blocks_per_track;
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
bool found = false;
|
||||
|
||||
for (int i=0;i<blocks_per_track.size();i++) {
|
||||
if (blocks_per_track.at(i).track == ghost->Track()) {
|
||||
blocks_per_track[i].blocks.append(b);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
blocks_per_track.append({ghost->Track(), {b}});
|
||||
}
|
||||
}
|
||||
|
||||
// Make contiguous runs of blocks per each track
|
||||
foreach (const TrackBlockListPair& p, blocks_per_track) {
|
||||
// Blocks must be merged if any are non-adjacent
|
||||
const TrackReference& track = p.track;
|
||||
const QList<Block*>& blocks = p.blocks;
|
||||
|
||||
Block* earliest_block = blocks.first();
|
||||
Block* latest_block = blocks.first();
|
||||
|
||||
// Find the earliest and latest selected blocks
|
||||
for (int j=1;j<blocks.size();j++) {
|
||||
Block* compare = blocks.at(j);
|
||||
|
||||
if (compare->in() < earliest_block->in()) {
|
||||
earliest_block = compare;
|
||||
}
|
||||
|
||||
if (compare->in() > latest_block->in()) {
|
||||
latest_block = compare;
|
||||
}
|
||||
}
|
||||
|
||||
// Add any blocks between these blocks that aren't already in the list
|
||||
if (earliest_block != latest_block) {
|
||||
Block* b = earliest_block;
|
||||
while ((b = b->next()) != latest_block) {
|
||||
if (!blocks.contains(b)) {
|
||||
AddGhostFromBlock(b, track, Timeline::kMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add surrounding blocks that will be trimming instead of moving
|
||||
if (earliest_block->previous()) {
|
||||
AddGhostFromBlock(earliest_block->previous(), track, Timeline::kTrimOut);
|
||||
}
|
||||
|
||||
if (latest_block->next()) {
|
||||
AddGhostFromBlock(latest_block->next(), track, Timeline::kTrimIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::SlideTool::FinishDrag(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QVector<TrackSlideCommand::BlockSlideInfo> info;
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (!ghost->HasBeenAdjusted()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
info.append({parent()->GetTrackFromReference(ghost->Track()),
|
||||
b,
|
||||
ghost->mode(),
|
||||
ghost->mode() == Timeline::kMove ? ghost->GetAdjustedIn() : ghost->AdjustedLength(),
|
||||
ghost->mode() == Timeline::kMove ? ghost->In() : ghost->Length()});
|
||||
}
|
||||
|
||||
if (!info.isEmpty()) {
|
||||
Core::instance()->undo_stack()->push(new TrackSlideCommand(info));
|
||||
}
|
||||
InitiateDragInternal(clicked_item, trim_mode, kSlide, true);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -73,9 +73,9 @@ TimelineViewBlockItem *TimelineWidget::Tool::GetItemAtScenePos(const TimelineCoo
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rational TimelineWidget::Tool::ValidateTimeMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
rational TimelineWidget::Tool::ValidateTimeMovement(rational movement)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->mode() != Timeline::kMove) {
|
||||
continue;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ rational TimelineWidget::Tool::ValidateTimeMovement(rational movement, const QVe
|
||||
return movement;
|
||||
}
|
||||
|
||||
int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem*>& ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != Timeline::kMove) {
|
||||
@@ -115,7 +115,7 @@ int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<Time
|
||||
|
||||
if (!ghost->CanMoveTracks()) {
|
||||
|
||||
movement = 0;
|
||||
return 0;
|
||||
|
||||
} else if (ghost->Track().index() + movement < 0) {
|
||||
|
||||
@@ -128,7 +128,7 @@ int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<Time
|
||||
return movement;
|
||||
}
|
||||
|
||||
void TimelineWidget::Tool::GetGhostData(const QVector<TimelineViewGhostItem *> &ghosts, rational *earliest_point, rational *latest_point)
|
||||
void TimelineWidget::Tool::GetGhostData(rational *earliest_point, rational *latest_point)
|
||||
{
|
||||
rational ep = RATIONAL_MAX;
|
||||
rational lp = RATIONAL_MIN;
|
||||
@@ -147,11 +147,11 @@ void TimelineWidget::Tool::GetGhostData(const QVector<TimelineViewGhostItem *> &
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::Tool::InsertGapsAtGhostDestination(const QVector<TimelineViewGhostItem *> &ghosts, QUndoCommand *command)
|
||||
void TimelineWidget::Tool::InsertGapsAtGhostDestination(QUndoCommand *command)
|
||||
{
|
||||
rational earliest_point, latest_point;
|
||||
|
||||
GetGhostData(ghosts, &earliest_point, &latest_point);
|
||||
GetGhostData(&earliest_point, &latest_point);
|
||||
|
||||
parent()->InsertGapsAt(earliest_point, latest_point - earliest_point, command);
|
||||
}
|
||||
|
||||
@@ -416,12 +416,9 @@ BlockSplitCommand::BlockSplitCommand(TrackOutput* track, Block *block, rational
|
||||
new_block_->setParent(&memory_manager_);
|
||||
|
||||
// Determine if the block outputs to an "out" transition
|
||||
foreach (NodeEdgePtr edge, block_->output()->edges()) {
|
||||
if (edge->input()->parentNode()->IsBlock()
|
||||
&& static_cast<Block*>(edge->input()->parentNode())->type() == Block::kTransition
|
||||
&& edge->input() == static_cast<TransitionBlock*>(edge->input()->parentNode())->out_block_input()) {
|
||||
transitions_to_move_.append(edge->input());
|
||||
}
|
||||
TransitionBlock* transition = TransitionBlock::GetBlockOutTransition(block_);
|
||||
if (transition) {
|
||||
transitions_to_move_.append(transition->out_block_input());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,11 +922,23 @@ void BlockTrimCommand::redo_internal()
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
if (block_->type() == Block::kTransition) {
|
||||
// Whole transition needs to be invalidated
|
||||
invalidate_range = TimeRange(block_->in(), block_->out());
|
||||
}
|
||||
|
||||
track_->InvalidateCache(invalidate_range, track_->block_input(), track_->block_input());
|
||||
}
|
||||
|
||||
void BlockTrimCommand::undo_internal()
|
||||
{
|
||||
TimeRange invalidate_range;
|
||||
|
||||
if (block_->type() == Block::kTransition) {
|
||||
// Whole transition needs to be invalidated
|
||||
invalidate_range = TimeRange(block_->in(), block_->out());
|
||||
}
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
// Will be POSITIVE if trimming shorter and NEGATIVE if trimming longer
|
||||
@@ -969,14 +978,18 @@ void BlockTrimCommand::undo_internal()
|
||||
}
|
||||
}
|
||||
|
||||
TimeRange invalidate_range;
|
||||
|
||||
if (mode_ == Timeline::kTrimIn) {
|
||||
block_->set_length_and_media_in(old_length_);
|
||||
invalidate_range = TimeRange(block_->in(), block_->in() + trim_diff);
|
||||
|
||||
if (block_->type() != Block::kTransition) {
|
||||
invalidate_range = TimeRange(block_->in(), block_->in() + trim_diff);
|
||||
}
|
||||
} else {
|
||||
block_->set_length_and_media_out(old_length_);
|
||||
invalidate_range = TimeRange(block_->out(), block_->out() - trim_diff);
|
||||
|
||||
if (block_->type() != Block::kTransition) {
|
||||
invalidate_range = TimeRange(block_->out(), block_->out() - trim_diff);
|
||||
}
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
@@ -1144,29 +1157,58 @@ void TrackSlideCommand::undo_internal()
|
||||
|
||||
void TrackSlideCommand::slide_internal(bool undo)
|
||||
{
|
||||
QMap<TrackOutput*, TimeRangeList> invalidate_ranges;
|
||||
QMap<TrackOutput*, TimeRange> invalidate_ranges;
|
||||
|
||||
// Make sure all movement blocks' old positions are invalidated
|
||||
foreach (const BlockSlideInfo& info, blocks_) {
|
||||
if (info.mode == Timeline::kMove) {
|
||||
invalidate_ranges[info.track].InsertTimeRange(TimeRange(info.block->in(),
|
||||
info.block->out()));
|
||||
invalidate_ranges.insert(info.track,
|
||||
TimeRange(info.block->in(),
|
||||
info.block->out()));
|
||||
}
|
||||
}
|
||||
|
||||
// Perform trims
|
||||
foreach (const BlockSlideInfo& info, blocks_) {
|
||||
int iterator = undo ? blocks_.size() - 1 : 0;
|
||||
int limit = undo ? -1 : blocks_.size();
|
||||
|
||||
while (iterator != limit) {
|
||||
const BlockSlideInfo& info = blocks_.at(iterator);
|
||||
|
||||
info.track->BeginOperation();
|
||||
|
||||
if (info.mode == Timeline::kTrimIn || info.mode == Timeline::kTrimOut) {
|
||||
rational new_len = undo ? info.old_time : info.new_time;
|
||||
qDebug() << "Trimming block as part of a slide operation:" << info.old_time << info.new_time;
|
||||
if (info.new_time.isNull()) {
|
||||
// Assume this was a gap that was reduced to nothing
|
||||
// On undo, restore it, on redo, remove it
|
||||
if (undo) {
|
||||
Block* next = removed_block_next.takeLast();
|
||||
static_cast<NodeGraph*>(info.track->parent())->AddNode(info.block);
|
||||
|
||||
if (info.mode == Timeline::kTrimIn) {
|
||||
info.block->set_length_and_media_in(new_len);
|
||||
if (next) {
|
||||
info.track->InsertBlockBefore(info.block, next);
|
||||
} else {
|
||||
info.track->AppendBlock(info.block);
|
||||
}
|
||||
} else {
|
||||
removed_block_next.append(info.block->next());
|
||||
info.track->RippleRemoveBlock(info.block);
|
||||
TakeNodeFromParentGraph(info.block, &memory_manager_);
|
||||
}
|
||||
} else {
|
||||
info.block->set_length_and_media_out(new_len);
|
||||
rational new_len = undo ? info.old_time : info.new_time;
|
||||
|
||||
if (info.mode == Timeline::kTrimIn) {
|
||||
info.block->set_length_and_media_in(new_len);
|
||||
} else {
|
||||
info.block->set_length_and_media_out(new_len);
|
||||
}
|
||||
}
|
||||
} else if (!undo && info.mode == Timeline::kMove && !info.block->previous()) {
|
||||
} else if (!undo
|
||||
&& info.mode == Timeline::kMove
|
||||
&& !info.block->previous()
|
||||
&& info.new_time > info.old_time) {
|
||||
// If this is a moving block and there was nothing before it to offset its time correctly,
|
||||
// insert a gap here
|
||||
GapBlock* gap = new GapBlock();
|
||||
@@ -1177,6 +1219,12 @@ void TrackSlideCommand::slide_internal(bool undo)
|
||||
}
|
||||
|
||||
info.track->EndOperation();
|
||||
|
||||
if (undo) {
|
||||
iterator--;
|
||||
} else {
|
||||
iterator++;
|
||||
}
|
||||
}
|
||||
|
||||
if (undo) {
|
||||
@@ -1198,16 +1246,16 @@ void TrackSlideCommand::slide_internal(bool undo)
|
||||
// Make sure all movement blocks' new positions are invalidated
|
||||
foreach (const BlockSlideInfo& info, blocks_) {
|
||||
if (info.mode == Timeline::kMove) {
|
||||
invalidate_ranges[info.track].InsertTimeRange(TimeRange(info.block->in(),
|
||||
info.block->out()));
|
||||
TimeRange& range = invalidate_ranges[info.track];
|
||||
|
||||
range.set_range(qMin(range.in(), info.block->in()),
|
||||
qMax(range.out(), info.block->out()));
|
||||
}
|
||||
}
|
||||
|
||||
QMap<TrackOutput*, TimeRangeList>::const_iterator i;
|
||||
QMap<TrackOutput*, TimeRange>::const_iterator i;
|
||||
for (i=invalidate_ranges.constBegin(); i!=invalidate_ranges.constEnd(); i++) {
|
||||
foreach (const TimeRange& r, i.value()) {
|
||||
i.key()->InvalidateCache(r, i.key()->block_input(), i.key()->block_input());
|
||||
}
|
||||
i.key()->InvalidateCache(i.value(), i.key()->block_input(), i.key()->block_input());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1588,4 +1636,83 @@ void TrackListInsertGaps::undo_internal()
|
||||
}
|
||||
}
|
||||
|
||||
TransitionRemoveCommand::TransitionRemoveCommand(TrackOutput* track, TransitionBlock *block, QUndoCommand* parent) :
|
||||
UndoCommand(parent),
|
||||
track_(track),
|
||||
block_(block),
|
||||
out_block_(block_->connected_out_block()),
|
||||
in_block_(block_->connected_in_block())
|
||||
{
|
||||
// Can't remove a transition in this way unless it's connected to at least one other block
|
||||
Q_ASSERT(out_block_ || in_block_);
|
||||
}
|
||||
|
||||
Project *TransitionRemoveCommand::GetRelevantProject() const
|
||||
{
|
||||
return static_cast<Sequence*>(track_->parent())->project();
|
||||
}
|
||||
|
||||
void TransitionRemoveCommand::redo_internal()
|
||||
{
|
||||
track_->BeginOperation();
|
||||
|
||||
TimeRange invalidate_range(block_->in(), block_->out());
|
||||
|
||||
if (in_block_) {
|
||||
in_block_->set_length_and_media_in(in_block_->length() + block_->in_offset());
|
||||
}
|
||||
|
||||
if (out_block_) {
|
||||
out_block_->set_length_and_media_out(out_block_->length() + block_->out_offset());
|
||||
}
|
||||
|
||||
if (in_block_) {
|
||||
NodeParam::DisconnectEdge(in_block_->output(), block_->in_block_input());
|
||||
}
|
||||
|
||||
if (out_block_) {
|
||||
NodeParam::DisconnectEdge(out_block_->output(), block_->out_block_input());
|
||||
}
|
||||
|
||||
track_->RippleRemoveBlock(block_);
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->InvalidateCache(invalidate_range, track_->block_input(), track_->block_input());
|
||||
}
|
||||
|
||||
void TransitionRemoveCommand::undo_internal()
|
||||
{
|
||||
track_->BeginOperation();
|
||||
|
||||
if (in_block_) {
|
||||
track_->InsertBlockBefore(block_, in_block_);
|
||||
} else {
|
||||
track_->InsertBlockAfter(block_, out_block_);
|
||||
}
|
||||
|
||||
if (in_block_) {
|
||||
NodeParam::ConnectEdge(in_block_->output(), block_->in_block_input());
|
||||
}
|
||||
|
||||
if (out_block_) {
|
||||
NodeParam::ConnectEdge(out_block_->output(), block_->out_block_input());
|
||||
}
|
||||
|
||||
// These if statements must be separated because in_offset and out_offset report different things
|
||||
// if only one block is connected vs two. So we have to connect the blocks first before we have
|
||||
// an accurate return value from these offset functions.
|
||||
if (in_block_) {
|
||||
in_block_->set_length_and_media_in(in_block_->length() - block_->in_offset());
|
||||
}
|
||||
|
||||
if (out_block_) {
|
||||
out_block_->set_length_and_media_out(out_block_->length() - block_->out_offset());
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->InvalidateCache(TimeRange(block_->in(), block_->out()), track_->block_input(), track_->block_input());
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "node/block/block.h"
|
||||
#include "node/block/gap/gap.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/output/track/track.h"
|
||||
#include "node/output/track/tracklist.h"
|
||||
#include "timeline/timelinepoints.h"
|
||||
@@ -574,6 +575,9 @@ private:
|
||||
|
||||
QVector<BlockSlideInfo> blocks_;
|
||||
QList<GapBlock*> added_gaps_;
|
||||
QList<Block*> removed_block_next;
|
||||
|
||||
QObject memory_manager_;
|
||||
|
||||
};
|
||||
|
||||
@@ -606,6 +610,26 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class TransitionRemoveCommand : public UndoCommand {
|
||||
public:
|
||||
TransitionRemoveCommand(TrackOutput *track, TransitionBlock* block, QUndoCommand *parent = nullptr);
|
||||
|
||||
virtual Project* GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo_internal() override;
|
||||
virtual void undo_internal() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
|
||||
TransitionBlock* block_;
|
||||
|
||||
Block* out_block_;
|
||||
Block* in_block_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
#endif // TIMELINEUNDOABLE_H
|
||||
|
||||
@@ -46,8 +46,16 @@ TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const Trac
|
||||
ghost->SetYCoords(y, height);
|
||||
ghost->setData(kAttachedBlock, Node::PtrToValue(block));
|
||||
|
||||
if (block->type() == Block::kClip) {
|
||||
switch (block->type()) {
|
||||
case Block::kClip:
|
||||
ghost->can_have_zero_length_ = false;
|
||||
break;
|
||||
case Block::kTransition:
|
||||
ghost->can_have_zero_length_ = false;
|
||||
ghost->SetCanMoveTracks(false);
|
||||
break;
|
||||
case Block::kGap:
|
||||
break;
|
||||
}
|
||||
|
||||
return ghost;
|
||||
|
||||
@@ -38,7 +38,9 @@ public:
|
||||
enum DataType {
|
||||
kAttachedBlock,
|
||||
kReferenceBlock,
|
||||
kAttachedFootage
|
||||
kAttachedFootage,
|
||||
kTrimOverwriteAllowed,
|
||||
kPointerToolMode
|
||||
};
|
||||
|
||||
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user