handle transition track movement

Only allow transitions to move tracks if their attached blocks are moving
with them.
This commit is contained in:
itsmattkc
2020-01-07 03:06:51 +11:00
parent 2941dbff48
commit e09ff4abf6
4 changed files with 53 additions and 17 deletions
+23 -8
View File
@@ -230,7 +230,7 @@ void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *e
} }
const TrackReference& track_ref = ghost->GetAdjustedTrack(); const TrackReference& track_ref = ghost->GetAdjustedTrack();
TrackOutput* track = parent()->GetTrackFromReference(track_ref); //TrackOutput* track = parent()->GetTrackFromReference(track_ref);
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock)); Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
@@ -267,12 +267,13 @@ void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *e
} }
} }
// Remove transitions that have been reduced to zero length if (b->type() == Block::kTransition && ghost->AdjustedLength() == 0) {
if (b->type() == Block::kTransition) { // Remove transitions that have been reduced to zero length
new NodeRemoveCommand(static_cast<NodeGraph*>(b->parent()), new NodeRemoveCommand(static_cast<NodeGraph*>(b->parent()),
{b}, {b},
command); command);
} else { } else {
// Normal block placement
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(track_ref.type()), new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(track_ref.type()),
track_ref.index(), track_ref.index(),
b, b,
@@ -478,19 +479,33 @@ void TimelineWidget::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_
} }
if (block) { if (block) {
AddGhostFromBlock(block, clip_item->Track(), block_mode); TimelineViewGhostItem* ghost = AddGhostFromBlock(block, clip_item->Track(), block_mode);
if (block->type() == Block::kTransition) { if (block->type() == Block::kTransition) {
TransitionBlock* transition = static_cast<TransitionBlock*>(block); TransitionBlock* transition = static_cast<TransitionBlock*>(block);
bool transition_can_move_tracks = false;
// Create a rolling effect with the attached block // Create a rolling effect with the attached block
if (transition->connected_in_block() && (block_mode == Timeline::kTrimOut || block_mode == Timeline::kMove)) { if (transition->connected_in_block()) {
AddGhostFromBlock(transition->connected_in_block(), clip_item->Track(), Timeline::kTrimIn); if (parent()->block_items_.value(transition->connected_in_block())->isSelected()) {
// We'll be moving this item too, no need to create a ghost for it here
transition_can_move_tracks = true;
} else if (block_mode == Timeline::kTrimOut || block_mode == Timeline::kMove) {
AddGhostFromBlock(transition->connected_in_block(), clip_item->Track(), Timeline::kTrimIn);
}
} }
if (transition->connected_out_block() && (block_mode == Timeline::kTrimIn || block_mode == Timeline::kMove)) { if (transition->connected_out_block()) {
AddGhostFromBlock(transition->connected_out_block(), clip_item->Track(), Timeline::kTrimOut); if (parent()->block_items_.value(transition->connected_in_block())->isSelected()) {
// We'll be moving this item too, no need to create a ghost for it here
transition_can_move_tracks = true;
} else if (block_mode == Timeline::kTrimIn || block_mode == Timeline::kMove) {
AddGhostFromBlock(transition->connected_out_block(), clip_item->Track(), Timeline::kTrimOut);
}
} }
ghost->SetCanMoveTracks(transition_can_move_tracks);
} }
} }
} }
+12 -6
View File
@@ -107,7 +107,7 @@ rational TimelineWidget::Tool::ValidateFrameMovement(rational movement, const QV
if (block && block->type() == Block::kTransition) { if (block && block->type() == Block::kTransition) {
TransitionBlock* transition = static_cast<TransitionBlock*>(block); TransitionBlock* transition = static_cast<TransitionBlock*>(block);
// Daul transitions are only allowed to move so that neither of their offsets are < 0 // Dual transitions are only allowed to move so that neither of their offsets are < 0
if (transition->connected_in_block() && transition->connected_out_block()) { if (transition->connected_in_block() && transition->connected_out_block()) {
if (movement > transition->out_offset()) { if (movement > transition->out_offset()) {
movement = transition->out_offset(); movement = transition->out_offset();
@@ -131,13 +131,19 @@ rational TimelineWidget::Tool::ValidateFrameMovement(rational movement, const QV
int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> ghosts) int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> ghosts)
{ {
foreach (TimelineViewGhostItem* ghost, ghosts) { foreach (TimelineViewGhostItem* ghost, ghosts) {
// Prevents any ghosts from going to a non-existent negative track if (ghost->mode() != Timeline::kMove) {
if (ghost->Track().index() + movement < 0) { continue;
if (ghost->mode() != Timeline::kMove) { }
continue;
}
if (!ghost->CanMoveTracks()) {
movement = 0;
} else if (ghost->Track().index() + movement < 0) {
// Prevents any ghosts from going to a non-existent negative track
movement = -ghost->Track().index(); movement = -ghost->Track().index();
} }
} }
@@ -27,7 +27,8 @@ TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) :
track_adj_(0), track_adj_(0),
stream_(nullptr), stream_(nullptr),
mode_(Timeline::kNone), mode_(Timeline::kNone),
can_have_zero_length_(true) can_have_zero_length_(true),
can_move_tracks_(true)
{ {
SetInvisible(false); SetInvisible(false);
} }
@@ -50,11 +51,21 @@ TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const Trac
return ghost; return ghost;
} }
bool TimelineViewGhostItem::CanHaveZeroLength() bool TimelineViewGhostItem::CanHaveZeroLength() const
{ {
return can_have_zero_length_; return can_have_zero_length_;
} }
bool TimelineViewGhostItem::CanMoveTracks() const
{
return can_move_tracks_;
}
void TimelineViewGhostItem::SetCanMoveTracks(bool e)
{
can_move_tracks_ = e;
}
void TimelineViewGhostItem::SetInvisible(bool invisible) void TimelineViewGhostItem::SetInvisible(bool invisible)
{ {
setBrush(Qt::NoBrush); setBrush(Qt::NoBrush);
@@ -44,7 +44,10 @@ public:
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height); static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height);
bool CanHaveZeroLength(); bool CanHaveZeroLength() const;
bool CanMoveTracks() const;
void SetCanMoveTracks(bool e);
void SetInvisible(bool invisible); void SetInvisible(bool invisible);
@@ -99,6 +102,7 @@ private:
Timeline::MovementMode mode_; Timeline::MovementMode mode_;
bool can_have_zero_length_; bool can_have_zero_length_;
bool can_move_tracks_;
}; };
#endif // TIMELINEVIEWGHOSTITEM_H #endif // TIMELINEVIEWGHOSTITEM_H