refined pointer and ripple timeline tools
This commit is contained in:
@@ -95,7 +95,7 @@ void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
|
||||
snap_points_.append(ghost->In());
|
||||
snap_points_.append(ghost->Out());
|
||||
|
||||
ghost->setData(0, QVariant::fromValue(stream));
|
||||
ghost->setData(TimelineViewGhostItem::kAttachedFootage, QVariant::fromValue(stream));
|
||||
ghost->SetMode(olive::timeline::kMove);
|
||||
|
||||
parent()->AddGhost(ghost);
|
||||
@@ -179,7 +179,7 @@ void TimelineView::ImportTool::DragDrop(QDropEvent *event)
|
||||
opacity->setParent(&node_memory_manager);
|
||||
|
||||
clip->set_length(ghost->Length());
|
||||
media->SetFootage(ghost->data(0).value<StreamPtr>());
|
||||
media->SetFootage(ghost->data(TimelineViewGhostItem::kAttachedFootage).value<StreamPtr>());
|
||||
|
||||
NodeParam::ConnectEdge(opacity->texture_output(), clip->texture_input());
|
||||
NodeParam::ConnectEdge(media->texture_output(), opacity->texture_input());
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "common/clamp.h"
|
||||
#include "common/range.h"
|
||||
#include "core.h"
|
||||
#include "node/block/gap/gap.h"
|
||||
@@ -114,7 +115,7 @@ void TimelineView::PointerTool::MouseReleaseInternal(QMouseEvent *event)
|
||||
// Since all the ghosts will be leaving their old position in some way, we replace all of them with gaps here so the
|
||||
// entire timeline isn't disrupted in the process
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(0));
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Replace old Block with a new Gap
|
||||
GapBlock* gap = new GapBlock();
|
||||
@@ -127,8 +128,9 @@ void TimelineView::PointerTool::MouseReleaseInternal(QMouseEvent *event)
|
||||
// Now we place the clips back in the timeline where the user moved them. It's legal for them to overwrite parts or
|
||||
// all of the gaps we inserted earlier
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(0));
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Normal blocks work in conjunction with the gap made above
|
||||
if (ghost->mode() == olive::timeline::kTrimIn || ghost->mode() == olive::timeline::kTrimOut) {
|
||||
// If we were trimming, we'll need to change the length
|
||||
|
||||
@@ -144,12 +146,12 @@ void TimelineView::PointerTool::MouseReleaseInternal(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
rational TimelineView::PointerTool::FrameValidateInternal(rational time_movement, QVector<TimelineViewGhostItem *>)
|
||||
rational TimelineView::PointerTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *>& ghosts)
|
||||
{
|
||||
// Default behavior is to validate all movement and trimming
|
||||
time_movement = ValidateFrameMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateInTrimming(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateOutTrimming(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateFrameMovement(time_movement, ghosts);
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, true);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, true);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
@@ -160,7 +162,7 @@ void TimelineView::PointerTool::InitiateDrag(const QPoint& mouse_pos)
|
||||
drag_start_ = GetScenePos(mouse_pos);
|
||||
|
||||
// Get the item that was clicked
|
||||
TimelineViewClipItem* clicked_item = dynamic_cast<TimelineViewClipItem*>(GetItemAtScenePos(drag_start_));
|
||||
TimelineViewBlockItem* clicked_item = dynamic_cast<TimelineViewBlockItem*>(GetItemAtScenePos(drag_start_));
|
||||
|
||||
// We only initiate a pointer drag if the user actually dragged an item, otherwise if they dragged on empty space
|
||||
// QGraphicsView default behavior would initiate a rubberband drag
|
||||
@@ -187,61 +189,14 @@ void TimelineView::PointerTool::InitiateDrag(const QPoint& mouse_pos)
|
||||
trim_mode = olive::timeline::kMove;
|
||||
}
|
||||
|
||||
// Gaps can't be moved, only trimmed
|
||||
if (clicked_item->block()->type() == Block::kGap && trim_mode == olive::timeline::kMove) {
|
||||
trim_mode = olive::timeline::kNone;
|
||||
}
|
||||
|
||||
// Make sure we can actually perform an action here
|
||||
if (trim_mode != olive::timeline::kNone) {
|
||||
// Convert selected items list to clips list
|
||||
QList<TimelineViewClipItem*> clips = GetSelectedClips();
|
||||
|
||||
// If trimming multiple clips, we only trim the earliest in each track (trimming in) or the latest in each track
|
||||
// (trimming out). If the current clip is NOT one of these, we only trim it.
|
||||
bool multitrim_enabled = true;
|
||||
|
||||
// Determine if the clicked item is the earliest/latest in the track for in/out trimming respectively
|
||||
if (trim_mode == olive::timeline::kTrimIn
|
||||
|| trim_mode == olive::timeline::kTrimOut) {
|
||||
multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
}
|
||||
|
||||
// For each selected item, create a "ghost", a visual representation of the action before it gets performed
|
||||
foreach (TimelineViewClipItem* clip_item, clips) {
|
||||
// Determine correct mode for ghost
|
||||
//
|
||||
// Movement is indiscriminate, all the ghosts can be set to do this, however trimming is limited to one block
|
||||
// PER TRACK
|
||||
|
||||
bool include_this_clip = true;
|
||||
|
||||
if (clip_item != clicked_item
|
||||
&& (trim_mode == olive::timeline::kTrimIn || trim_mode == olive::timeline::kTrimOut)) {
|
||||
include_this_clip = multitrim_enabled ? IsClipTrimmable(clip_item, clips, trim_mode) : false;
|
||||
}
|
||||
|
||||
if (include_this_clip) {
|
||||
TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromClip(clip_item);
|
||||
|
||||
ghost->SetScale(parent()->scale_);
|
||||
ghost->SetMode(trim_mode);
|
||||
|
||||
// Prepare snap points (optimizes snapping for later)
|
||||
switch (trim_mode) {
|
||||
case olive::timeline::kMove:
|
||||
snap_points_.append(ghost->In());
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
case olive::timeline::kTrimIn:
|
||||
snap_points_.append(ghost->In());
|
||||
break;
|
||||
case olive::timeline::kTrimOut:
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
parent()->ghost_items_.append(ghost);
|
||||
parent()->scene_.addItem(ghost);
|
||||
}
|
||||
}
|
||||
InitiateGhosts(clicked_item, trim_mode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,15 +214,15 @@ void TimelineView::PointerTool::ProcessDrag(const QPoint &mouse_pos)
|
||||
// Determine frame movement
|
||||
rational time_movement = parent()->SceneToTime(movement.x());
|
||||
|
||||
// Validate movement (enforce all ghosts moving in legal ways)
|
||||
time_movement = FrameValidateInternal(time_movement, parent()->ghost_items_);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
// Perform snapping if enabled (adjusts time_movement if it's close to any potential snap points)
|
||||
if (olive::core.snapping()) {
|
||||
SnapPoint(snap_points_, &time_movement);
|
||||
}
|
||||
|
||||
// Validate movement (enforce all ghosts moving in legal ways)
|
||||
time_movement = FrameValidateInternal(time_movement, parent()->ghost_items_);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
// Perform movement
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
switch (ghost->mode()) {
|
||||
@@ -295,14 +250,119 @@ void TimelineView::PointerTool::ProcessDrag(const QPoint &mouse_pos)
|
||||
}
|
||||
}
|
||||
|
||||
QList<TimelineViewClipItem *> TimelineView::PointerTool::GetSelectedClips()
|
||||
void TimelineView::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_item,
|
||||
olive::timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
{
|
||||
// Convert selected items list to clips list
|
||||
QList<TimelineViewBlockItem*> clips = GetSelectedClips();
|
||||
|
||||
// If trimming multiple clips, we only trim the earliest in each track (trimming in) or the latest in each track
|
||||
// (trimming out). If the current clip is NOT one of these, we only trim it.
|
||||
bool multitrim_enabled = true;
|
||||
|
||||
// Determine if the clicked item is the earliest/latest in the track for in/out trimming respectively
|
||||
if (trim_mode == olive::timeline::kTrimIn
|
||||
|| trim_mode == olive::timeline::kTrimOut) {
|
||||
multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
}
|
||||
|
||||
// For each selected item, create a "ghost", a visual representation of the action before it gets performed
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
// Determine correct mode for ghost
|
||||
//
|
||||
// Movement is indiscriminate, all the ghosts can be set to do this, however trimming is limited to one block
|
||||
// PER TRACK
|
||||
|
||||
bool include_this_clip = true;
|
||||
|
||||
if (clip_item != clicked_item
|
||||
&& (trim_mode == olive::timeline::kTrimIn || trim_mode == olive::timeline::kTrimOut)) {
|
||||
include_this_clip = multitrim_enabled ? IsClipTrimmable(clip_item, clips, trim_mode) : false;
|
||||
}
|
||||
|
||||
if (include_this_clip) {
|
||||
Block* block = clip_item->block();
|
||||
olive::timeline::MovementMode block_mode = trim_mode;
|
||||
|
||||
if (block->type() == Block::kGap && !allow_gap_trimming) {
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
// Trim the previous clip's out point instead
|
||||
block = block->previous();
|
||||
} else {
|
||||
// Assume kTrimOut
|
||||
block = block->next();
|
||||
}
|
||||
block_mode = FlipTrimMode(trim_mode);
|
||||
}
|
||||
|
||||
if (block != nullptr) {
|
||||
AddGhostFromBlock(block, clip_item->Track(), block_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineView::PointerTool::AddGhostFromBlock(Block* block, int track, olive::timeline::MovementMode mode)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromBlock(block,
|
||||
track,
|
||||
parent()->GetTrackY(track),
|
||||
parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineView::PointerTool::AddGhostFromNull(const rational &in, const rational &out, int track, olive::timeline::MovementMode mode)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
ghost->SetIn(in);
|
||||
ghost->SetOut(out);
|
||||
ghost->SetTrack(track);
|
||||
ghost->SetY(parent()->GetTrackY(track));
|
||||
ghost->SetHeight(parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
void TimelineView::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, olive::timeline::MovementMode mode)
|
||||
{
|
||||
ghost->SetScale(parent()->scale_);
|
||||
ghost->SetMode(mode);
|
||||
|
||||
// Prepare snap points (optimizes snapping for later)
|
||||
switch (mode) {
|
||||
case olive::timeline::kMove:
|
||||
snap_points_.append(ghost->In());
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
case olive::timeline::kTrimIn:
|
||||
snap_points_.append(ghost->In());
|
||||
break;
|
||||
case olive::timeline::kTrimOut:
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
parent()->ghost_items_.append(ghost);
|
||||
parent()->scene_.addItem(ghost);
|
||||
}
|
||||
|
||||
QList<TimelineViewBlockItem *> TimelineView::PointerTool::GetSelectedClips()
|
||||
{
|
||||
QList<QGraphicsItem*> selected_items = parent()->scene_.selectedItems();
|
||||
|
||||
// Convert selected items list to clips list
|
||||
QList<TimelineViewClipItem*> clips;
|
||||
QList<TimelineViewBlockItem*> clips;
|
||||
foreach (QGraphicsItem* item, selected_items) {
|
||||
TimelineViewClipItem* clip_cast = dynamic_cast<TimelineViewClipItem*>(item);
|
||||
TimelineViewBlockItem* clip_cast = dynamic_cast<TimelineViewBlockItem*>(item);
|
||||
|
||||
if (clip_cast != nullptr) {
|
||||
clips.append(clip_cast);
|
||||
@@ -312,18 +372,107 @@ QList<TimelineViewClipItem *> TimelineView::PointerTool::GetSelectedClips()
|
||||
return clips;
|
||||
}
|
||||
|
||||
bool TimelineView::PointerTool::IsClipTrimmable(TimelineViewClipItem* clip,
|
||||
const QList<TimelineViewClipItem*>& items,
|
||||
bool TimelineView::PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip,
|
||||
const QList<TimelineViewBlockItem*>& items,
|
||||
const olive::timeline::MovementMode& mode)
|
||||
{
|
||||
foreach (TimelineViewClipItem* compare, items) {
|
||||
foreach (TimelineViewBlockItem* compare, items) {
|
||||
if (clip->Track() == compare->Track()
|
||||
&& clip != compare
|
||||
&& ((compare->clip()->in() < clip->clip()->in() && mode == olive::timeline::kTrimIn)
|
||||
|| (compare->clip()->out() > clip->clip()->out() && mode == olive::timeline::kTrimOut))) {
|
||||
&& ((compare->block()->in() < clip->block()->in() && mode == olive::timeline::kTrimIn)
|
||||
|| (compare->block()->out() > clip->block()->out() && mode == olive::timeline::kTrimOut))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
rational TimelineView::PointerTool::ValidateInTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimIn) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Determine the earliest in point this block could have
|
||||
rational earliest_in = qMax(rational(0), block->in() - block->media_in());
|
||||
|
||||
if (prevent_overwriting) {
|
||||
// Look for a Block in the way
|
||||
Block* prev = block->previous();
|
||||
while (prev != nullptr) {
|
||||
if (prev->type() == Block::kClip) {
|
||||
earliest_in = qMax(earliest_in, prev->out());
|
||||
break;
|
||||
}
|
||||
prev = prev->previous();
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the latest point this block could have
|
||||
rational latest_in = ghost->Out();
|
||||
|
||||
if (!ghost->CanHaveZeroLength()) {
|
||||
latest_in -= parent()->timebase_;
|
||||
}
|
||||
|
||||
// Clamp adjusted value between the earliest and latest values
|
||||
rational adjusted = ghost->In() + movement;
|
||||
rational clamped = clamp(adjusted, earliest_in, latest_in);
|
||||
|
||||
if (clamped != adjusted) {
|
||||
movement = clamped - ghost->In();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
rational TimelineView::PointerTool::ValidateOutTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimOut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Determine earliest and latest out points
|
||||
rational earliest_out = ghost->In();
|
||||
|
||||
if (!ghost->CanHaveZeroLength()) {
|
||||
earliest_out += parent()->timebase_;
|
||||
}
|
||||
|
||||
rational latest_out = RATIONAL_MAX;
|
||||
|
||||
if (prevent_overwriting) {
|
||||
// Determine if there's a block in the way
|
||||
Block* next = block->next();
|
||||
while (next != nullptr && next->type() != Block::kEnd) {
|
||||
if (next->type() == Block::kClip) {
|
||||
latest_out = qMin(latest_out, next->in());
|
||||
break;
|
||||
}
|
||||
next = next->next();
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp adjusted value between the earliest and latest values
|
||||
rational adjusted = ghost->Out() + movement;
|
||||
rational clamped = clamp(adjusted, earliest_out, latest_out);
|
||||
|
||||
if (clamped != adjusted) {
|
||||
movement = clamped - ghost->Out();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "widget/timelineview/timelineview.h"
|
||||
|
||||
#include "node/block/gap/gap.h"
|
||||
|
||||
TimelineView::RippleTool::RippleTool(TimelineView* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
@@ -44,21 +46,108 @@ void TimelineView::RippleTool::MouseReleaseInternal(QMouseEvent *event)
|
||||
// The amount to ripple by
|
||||
rational ripple_length = parent()->SceneToTime(movement.x());
|
||||
|
||||
QList<Block *> blocks_to_ripple;
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(0));
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
blocks_to_ripple.append(b);
|
||||
if (b == nullptr) {
|
||||
// This is a gap we are creating
|
||||
|
||||
// Make sure there's actually a gap being created
|
||||
if (ghost->AdjustedLength() > 0) {
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(ghost->AdjustedLength());
|
||||
|
||||
Block* block_to_append_gap_to = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kReferenceBlock));
|
||||
|
||||
parent()->timeline_node_->Tracks().at(ghost->Track())->InsertBlockAfter(gap,
|
||||
block_to_append_gap_to);
|
||||
}
|
||||
} else {
|
||||
// This was a Block that already existed
|
||||
if (ghost->AdjustedLength() > 0) {
|
||||
b->set_length(ghost->AdjustedLength());
|
||||
|
||||
if (movement_mode == olive::timeline::kTrimIn) {
|
||||
// We'll need to shift the media in point too
|
||||
b->set_media_in(b->media_in() + ghost->InAdjustment());
|
||||
}
|
||||
} else {
|
||||
// Assumed the Block was a Gap and it was reduced to zero length, remove it here
|
||||
parent()->timeline_node_->Tracks().at(ghost->Track())->RippleRemoveBlock(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rational TimelineView::RippleTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *> &ghosts)
|
||||
{
|
||||
// Only validate trimming, and we don't care about "overwriting" since the ripple tool is nondestructive
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, false);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, false);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
|
||||
void TimelineView::RippleTool::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);
|
||||
|
||||
if (parent()->ghost_items_.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent()->timeline_node_->RippleBlocks(blocks_to_ripple, ripple_length, movement_mode);
|
||||
}
|
||||
// Find the earliest ripple
|
||||
rational earliest_ripple = RATIONAL_MAX;
|
||||
|
||||
rational TimelineView::RippleTool::FrameValidateInternal(rational time_movement, QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
// FIXME: Validate rippling
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
rational ghost_ripple_point;
|
||||
|
||||
return PointerTool::FrameValidateInternal(time_movement, ghosts);
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
ghost_ripple_point = ghost->In();
|
||||
} else {
|
||||
ghost_ripple_point = ghost->Out();
|
||||
}
|
||||
|
||||
earliest_ripple = qMin(earliest_ripple, ghost_ripple_point);
|
||||
}
|
||||
|
||||
// For each track that does NOT have a ghost, we need to make one for Gaps
|
||||
foreach (TrackOutput* track, parent()->timeline_node_->Tracks()) {
|
||||
// Determine if we've already created a ghost on this track
|
||||
bool ghost_on_this_track_exists = false;
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->Track() == track->Index()) {
|
||||
ghost_on_this_track_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no ghost on this track, create one
|
||||
if (!ghost_on_this_track_exists) {
|
||||
// Find the block that starts just before the ripple point, and ends either on or just after it
|
||||
Block* block_before_ripple = track->NearestBlockBefore(earliest_ripple);
|
||||
|
||||
// If block is null, there will be no blocks after to ripple
|
||||
if (block_before_ripple != nullptr && block_before_ripple->type() != Block::kEnd) {
|
||||
TimelineViewGhostItem* ghost;
|
||||
|
||||
if (block_before_ripple->type() == Block::kGap) {
|
||||
// If this Block is already a Gap, ghost it now
|
||||
ghost = AddGhostFromBlock(block_before_ripple, track->Index(), trim_mode);
|
||||
} else {
|
||||
// If there's no gap here, we'll need to create one
|
||||
ghost = AddGhostFromNull(block_before_ripple->out(), block_before_ripple->out(), track->Index(), trim_mode);
|
||||
ghost->setData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(block_before_ripple));
|
||||
}
|
||||
|
||||
// ghost->SetInvisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,19 @@ TimelineView *TimelineView::Tool::parent()
|
||||
return parent_;
|
||||
}
|
||||
|
||||
olive::timeline::MovementMode TimelineView::Tool::FlipTrimMode(const olive::timeline::MovementMode &trim_mode)
|
||||
{
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
return olive::timeline::kTrimOut;
|
||||
}
|
||||
|
||||
if (trim_mode == olive::timeline::kTrimOut) {
|
||||
return olive::timeline::kTrimIn;
|
||||
}
|
||||
|
||||
return trim_mode;
|
||||
}
|
||||
|
||||
QPointF TimelineView::Tool::GetScenePos(const QPoint &screen_pos)
|
||||
{
|
||||
return parent()->mapToScene(screen_pos);
|
||||
@@ -61,6 +74,28 @@ QGraphicsItem *TimelineView::Tool::GetItemAtScenePos(const QPointF &scene_pos)
|
||||
return parent()->scene_.itemAt(scene_pos, parent()->transform());
|
||||
}
|
||||
|
||||
void AttemptSnap(const QList<double>& proposed_pts,
|
||||
double compare_point,
|
||||
const QList<rational>& start_times,
|
||||
rational compare_time,
|
||||
rational* movement,
|
||||
double* diff) {
|
||||
const qreal kSnapRange = 10; // FIXME: Hardcoded number
|
||||
|
||||
for (int i=0;i<proposed_pts.size();i++) {
|
||||
// Attempt snapping to clip out point
|
||||
if (InRange(proposed_pts.at(i), compare_point, kSnapRange)) {
|
||||
double this_diff = qAbs(compare_point - proposed_pts.at(i));
|
||||
|
||||
if (this_diff < *diff
|
||||
&& start_times.at(i) + *movement >= 0) {
|
||||
*movement = compare_time - start_times.at(i);
|
||||
*diff = this_diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rational TimelineView::Tool::ValidateFrameMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
@@ -93,71 +128,6 @@ int TimelineView::Tool::ValidateTrackMovement(int movement, const QVector<Timeli
|
||||
return movement;
|
||||
}
|
||||
|
||||
rational TimelineView::Tool::ValidateInTrimming(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimIn) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = Node::ValueToPtr<Block>(ghost->data(0));
|
||||
|
||||
// Prevents any media_in points from becoming negative
|
||||
if (block->media_in() + movement < 0) {
|
||||
movement = -block->media_in();
|
||||
}
|
||||
|
||||
// Prevents any clip length's becoming infinitely small (or negative length)
|
||||
if (ghost->In() + movement >= ghost->Out()) {
|
||||
// Since the timebase is considered more or less the "minimum unit", we adjust the movement to make the proposed
|
||||
// length precisely one timebase unit in size
|
||||
movement = ghost->Out() - parent()->timebase_ - ghost->In();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
rational TimelineView::Tool::ValidateOutTrimming(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimOut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prevents any clip length's becoming infinitely small (or negative length)
|
||||
if (ghost->Out() + movement <= ghost->In()) {
|
||||
// Since the timebase is considered more or less the "minimum unit", we adjust the movement to make the proposed
|
||||
// length precisely one timebase unit in size
|
||||
movement = ghost->In() + parent()->timebase_ - ghost->Out();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
void AttemptSnap(const QList<double>& proposed_pts,
|
||||
double compare_point,
|
||||
const QList<rational>& start_times,
|
||||
rational compare_time,
|
||||
rational* movement,
|
||||
double* diff) {
|
||||
const qreal kSnapRange = 10; // FIXME: Hardcoded number
|
||||
|
||||
for (int i=0;i<proposed_pts.size();i++) {
|
||||
// Attempt snapping to clip out point
|
||||
if (InRange(proposed_pts.at(i), compare_point, kSnapRange)) {
|
||||
double this_diff = qAbs(compare_point - proposed_pts.at(i));
|
||||
|
||||
if (this_diff < *diff
|
||||
&& start_times.at(i) + *movement >= 0) {
|
||||
*movement = compare_time - start_times.at(i);
|
||||
*diff = this_diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimelineView::Tool::SnapPoint(QList<rational> start_times, rational* movement, int snap_points)
|
||||
{
|
||||
QList<QGraphicsItem*> items = parent()->scene_.items();
|
||||
@@ -181,17 +151,17 @@ bool TimelineView::Tool::SnapPoint(QList<rational> start_times, rational* moveme
|
||||
|
||||
if (snap_points & kSnapToClips) {
|
||||
foreach (QGraphicsItem* it, items) {
|
||||
TimelineViewClipItem* timeline_rect = dynamic_cast<TimelineViewClipItem*>(it);
|
||||
TimelineViewBlockItem* timeline_rect = dynamic_cast<TimelineViewBlockItem*>(it);
|
||||
|
||||
if (timeline_rect != nullptr) {
|
||||
qreal rect_left = timeline_rect->x();
|
||||
qreal rect_right = rect_left + timeline_rect->rect().width();
|
||||
|
||||
// Attempt snapping to clip in point
|
||||
AttemptSnap(proposed_pts, rect_left, start_times, timeline_rect->clip()->in(), movement, &diff);
|
||||
AttemptSnap(proposed_pts, rect_left, start_times, timeline_rect->block()->in(), movement, &diff);
|
||||
|
||||
// Attempt snapping to clip out point
|
||||
AttemptSnap(proposed_pts, rect_right, start_times, timeline_rect->clip()->out(), movement, &diff);
|
||||
AttemptSnap(proposed_pts, rect_right, start_times, timeline_rect->block()->out(), movement, &diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user