remove block enum
Replaced with dynamic casts.
This commit is contained in:
@@ -39,14 +39,6 @@ public:
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(Block)
|
||||
|
||||
enum Type {
|
||||
kClip,
|
||||
kGap,
|
||||
kTransition
|
||||
};
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
|
||||
const rational& in() const
|
||||
|
||||
@@ -34,11 +34,6 @@ Node *ClipBlock::copy() const
|
||||
return new ClipBlock();
|
||||
}
|
||||
|
||||
Block::Type ClipBlock::type() const
|
||||
{
|
||||
return kClip;
|
||||
}
|
||||
|
||||
QString ClipBlock::Name() const
|
||||
{
|
||||
return tr("Clip");
|
||||
|
||||
@@ -38,8 +38,6 @@ public:
|
||||
|
||||
virtual Node* copy() const override;
|
||||
|
||||
virtual Type type() const override;
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
@@ -31,11 +31,6 @@ Node *GapBlock::copy() const
|
||||
return new GapBlock();
|
||||
}
|
||||
|
||||
Block::Type GapBlock::type() const
|
||||
{
|
||||
return kGap;
|
||||
}
|
||||
|
||||
QString GapBlock::Name() const
|
||||
{
|
||||
return tr("Gap");
|
||||
|
||||
@@ -38,8 +38,6 @@ public:
|
||||
|
||||
virtual Node * copy() const override;
|
||||
|
||||
virtual Type type() const override;
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
@@ -39,11 +39,6 @@ TransitionBlock::TransitionBlock() :
|
||||
AddInput(kCurveInput, NodeValue::kCombo, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
|
||||
}
|
||||
|
||||
Block::Type TransitionBlock::type() const
|
||||
{
|
||||
return kTransition;
|
||||
}
|
||||
|
||||
void TransitionBlock::Retranslate()
|
||||
{
|
||||
Block::Retranslate();
|
||||
@@ -255,7 +250,7 @@ void TransitionBlock::InputConnectedEvent(const QString &input, int element, con
|
||||
// If node is not a block, this will just be null
|
||||
if ((connected_out_block_ = dynamic_cast<Block*>(output.node()))) {
|
||||
|
||||
Q_ASSERT(connected_out_block_->type() != Block::kTransition
|
||||
Q_ASSERT(!dynamic_cast<TransitionBlock*>(connected_out_block_)
|
||||
&& !connected_out_block_->out_transition()
|
||||
&& connected_out_block_ == this->previous());
|
||||
|
||||
@@ -265,7 +260,7 @@ void TransitionBlock::InputConnectedEvent(const QString &input, int element, con
|
||||
// If node is not a block, this will just be null
|
||||
if ((connected_in_block_ = dynamic_cast<Block*>(output.node()))) {
|
||||
|
||||
Q_ASSERT(connected_in_block_->type() != Block::kTransition
|
||||
Q_ASSERT(!dynamic_cast<TransitionBlock*>(connected_in_block_)
|
||||
&& !connected_in_block_->in_transition()
|
||||
&& connected_in_block_ == this->next());
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ public:
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(TransitionBlock)
|
||||
|
||||
virtual Type type() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
rational in_offset() const;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <opentimelineio/serializableObject.h>
|
||||
#include <opentimelineio/transition.h>
|
||||
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "node/block/gap/gap.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/project/footage/footage.h"
|
||||
|
||||
@@ -130,9 +132,7 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
foreach (Block* block, track->Blocks()) {
|
||||
OTIO::Composable* otio_block = nullptr;
|
||||
|
||||
switch (block->type()) {
|
||||
case Block::kClip:
|
||||
{
|
||||
if (dynamic_cast<ClipBlock*>(block)) {
|
||||
auto otio_clip = new OTIO::Clip(block->GetLabel().toStdString());
|
||||
|
||||
otio_clip->set_source_range(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
@@ -145,18 +145,12 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
}
|
||||
|
||||
otio_block = otio_clip;
|
||||
break;
|
||||
}
|
||||
case Block::kGap:
|
||||
{
|
||||
} else if (dynamic_cast<GapBlock*>(block)) {
|
||||
otio_block = new OTIO::Gap(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()),
|
||||
block->GetLabel().toStdString()
|
||||
);
|
||||
break;
|
||||
}
|
||||
case Block::kTransition:
|
||||
{
|
||||
} else if (dynamic_cast<TransitionBlock*>(block)) {
|
||||
auto otio_transition = new OTIO::Transition(block->GetLabel().toStdString());
|
||||
|
||||
TransitionBlock* our_transition = static_cast<TransitionBlock*>(block);
|
||||
@@ -165,8 +159,6 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
otio_transition->set_out_offset(our_transition->out_offset().toRationalTime());
|
||||
|
||||
otio_block = new OTIO::Transition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!otio_block) {
|
||||
|
||||
@@ -1666,8 +1666,8 @@ public:
|
||||
Block* previous = block_->previous();
|
||||
Block* next = block_->next();
|
||||
|
||||
bool previous_is_a_gap = (previous && previous->type() == Block::kGap);
|
||||
bool next_is_a_gap = (next && next->type() == Block::kGap);
|
||||
bool previous_is_a_gap = dynamic_cast<GapBlock*>(previous);
|
||||
bool next_is_a_gap = dynamic_cast<GapBlock*>(next);
|
||||
|
||||
if (previous_is_a_gap && next_is_a_gap) {
|
||||
// Clip is preceded and followed by a gap, so we'll merge the two
|
||||
@@ -1717,7 +1717,7 @@ public:
|
||||
|
||||
// Determine if it's proceeded by a gap, and remove that gap if so
|
||||
Block* preceding = block_->previous();
|
||||
if (preceding && preceding->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(preceding)) {
|
||||
track_->RippleRemoveBlock(preceding);
|
||||
preceding->setParent(&memory_manager_);
|
||||
|
||||
@@ -1836,7 +1836,7 @@ public:
|
||||
Block* block_at_time = track->NearestBlockBeforeOrAt(range.in());
|
||||
|
||||
if (block_at_time) {
|
||||
if (block_at_time->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(block_at_time)) {
|
||||
max_ripple_length = qMin(block_at_time->length(), max_ripple_length);
|
||||
} else {
|
||||
max_ripple_length = 0;
|
||||
@@ -2287,11 +2287,11 @@ private:
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
foreach (Block* b, track->Blocks()) {
|
||||
if (b->type() == Block::kGap && b->in() <= point_ && b->out() >= point_) {
|
||||
if (dynamic_cast<GapBlock*>(b) && b->in() <= point_ && b->out() >= point_) {
|
||||
// Found a gap at the location
|
||||
gaps_to_extend_.append(b);
|
||||
break;
|
||||
} else if (b->type() == Block::kClip && b->out() >= point_) {
|
||||
} else if (dynamic_cast<ClipBlock*>(b) && b->out() >= point_) {
|
||||
if (b->out() > point_) {
|
||||
blocks_to_split.append(b);
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ void TimelineWidget::SplitAtPlayhead()
|
||||
foreach (Track* track, sequence()->GetTracks()) {
|
||||
Block* b = track->BlockContainingTime(playhead_time);
|
||||
|
||||
if (b && b->type() == Block::kClip) {
|
||||
if (dynamic_cast<ClipBlock*>(b)) {
|
||||
bool selected = false;
|
||||
|
||||
// See if this block is selected
|
||||
@@ -434,7 +434,7 @@ void TimelineWidget::ReplaceBlocksWithGaps(const QVector<Block *> &blocks,
|
||||
MultiUndoCommand *command)
|
||||
{
|
||||
foreach (Block* b, blocks) {
|
||||
if (b->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(b)) {
|
||||
// No point in replacing a gap with a gap, and TrackReplaceBlockWithGapCommand will clear
|
||||
// up any extraneous gaps
|
||||
continue;
|
||||
@@ -470,9 +470,9 @@ void TimelineWidget::DeleteSelected(bool ripple)
|
||||
QVector<TransitionBlock*> transitions_to_delete;
|
||||
|
||||
foreach (Block* b, blocks_to_delete) {
|
||||
if (b->type() == Block::kClip) {
|
||||
if (dynamic_cast<ClipBlock*>(b)) {
|
||||
clips_to_delete.append(b);
|
||||
} else if (b->type() == Block::kTransition) {
|
||||
} else if (dynamic_cast<TransitionBlock*>(b)) {
|
||||
transitions_to_delete.append(static_cast<TransitionBlock*>(b));
|
||||
}
|
||||
}
|
||||
@@ -548,7 +548,7 @@ void TimelineWidget::ToggleLinksOnSelected()
|
||||
|
||||
foreach (Block* item, GetSelectedBlocks()) {
|
||||
// Only clips can be linked
|
||||
if (item->type() != Block::kClip) {
|
||||
if (!dynamic_cast<ClipBlock*>(item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1279,7 +1279,7 @@ void TimelineWidget::EditTo(Timeline::MovementMode mode)
|
||||
|
||||
foreach (const Timeline::EditToInfo& info, tracks) {
|
||||
if (info.nearest_block
|
||||
&& info.nearest_block->type() != Block::kGap
|
||||
&& !dynamic_cast<GapBlock*>(info.nearest_block)
|
||||
&& info.nearest_time != playhead_time) {
|
||||
rational new_len;
|
||||
|
||||
@@ -1410,7 +1410,7 @@ void TimelineWidget::MoveRubberBandSelect(bool enable_selecting, bool select_lin
|
||||
rubberband_now_selected_.clear();
|
||||
|
||||
foreach (Block* b, items_in_rubberband) {
|
||||
if (b->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(b)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event)
|
||||
// the block is not a gap)
|
||||
if (drag_movement_mode_ == Timeline::kNone
|
||||
&& movement_allowed_
|
||||
&& clicked_item_->type() != Block::kGap) {
|
||||
&& !dynamic_cast<GapBlock*>(clicked_item_)) {
|
||||
drag_movement_mode_ = Timeline::kMove;
|
||||
}
|
||||
|
||||
@@ -250,18 +250,14 @@ void PointerTool::InitiateDragInternal(Block *clicked_item,
|
||||
|
||||
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->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) {
|
||||
if (dynamic_cast<GapBlock*>(clicked_item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine if this move is a slide, which is determined by either
|
||||
bool clips_are_sliding = (slide_instead_of_moving || clicked_block_type == Block::kTransition);
|
||||
bool clips_are_sliding = (slide_instead_of_moving || dynamic_cast<TransitionBlock*>(clicked_item));
|
||||
|
||||
if (clips_are_sliding) {
|
||||
// This is a slide. What we do here is move clips within their own track, between the clips
|
||||
@@ -325,7 +321,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item,
|
||||
} else {
|
||||
// Prepare for a standard pointer move
|
||||
foreach (Block* block, clips) {
|
||||
if (block->type() == Block::kGap || block->type() == Block::kTransition) {
|
||||
if (dynamic_cast<GapBlock*>(block) || dynamic_cast<TransitionBlock*>(block)) {
|
||||
// Gaps cannot move, and we handle transitions further down
|
||||
continue;
|
||||
}
|
||||
@@ -378,7 +374,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item,
|
||||
// transition than a trim/roll
|
||||
bool treat_trim_as_slide = false;
|
||||
|
||||
if (block->type() == Block::kClip) {
|
||||
if (dynamic_cast<ClipBlock*>(block)) {
|
||||
// See if this clip has a transition attached, and move it with the trim if so
|
||||
TransitionBlock* connected_transition;
|
||||
|
||||
@@ -416,9 +412,9 @@ void PointerTool::InitiateDragInternal(Block *clicked_item,
|
||||
}
|
||||
|
||||
// See if we can roll the adjacent or if we'll need to create our own gap
|
||||
if (block->type() != Block::kGap
|
||||
&& !allow_nongap_rolling && adjacent && adjacent->type() != Block::kGap
|
||||
&& !(block->type() == Block::kTransition
|
||||
if (!dynamic_cast<GapBlock*>(block)
|
||||
&& !allow_nongap_rolling && adjacent && !dynamic_cast<GapBlock*>(adjacent)
|
||||
&& !(dynamic_cast<TransitionBlock*>(block)
|
||||
&& ((trim_mode == Timeline::kTrimIn && static_cast<TransitionBlock*>(block)->connected_out_block() == adjacent)
|
||||
|| (trim_mode == Timeline::kTrimOut && static_cast<TransitionBlock*>(block)->connected_in_block() == adjacent)))) {
|
||||
adjacent = nullptr;
|
||||
@@ -445,7 +441,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item,
|
||||
if (treat_trim_as_slide) {
|
||||
// We're sliding a transition rather than a pure trim/roll
|
||||
SetGhostToSlideMode(adjacent_ghost);
|
||||
} else if (block->type() == Block::kGap) {
|
||||
} else if (dynamic_cast<GapBlock*>(block)) {
|
||||
ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true);
|
||||
} else {
|
||||
adjacent_ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true);
|
||||
|
||||
@@ -71,7 +71,7 @@ void RazorTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
// Ensure there's a valid block here
|
||||
if (block_at_time
|
||||
&& block_at_time->out() != split_time
|
||||
&& block_at_time->type() == Block::kClip
|
||||
&& dynamic_cast<ClipBlock*>(block_at_time)
|
||||
&& !blocks_to_split.contains(block_at_time)) {
|
||||
blocks_to_split.append(block_at_time);
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ void RippleTool::InitiateDrag(Block *clicked_item,
|
||||
if (block_after_ripple) {
|
||||
TimelineViewGhostItem* ghost;
|
||||
|
||||
if (block_after_ripple->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(block_after_ripple)) {
|
||||
// If this Block is already a Gap, ghost it now
|
||||
ghost = AddGhostFromBlock(block_after_ripple, trim_mode);
|
||||
} else {
|
||||
@@ -90,7 +90,7 @@ void RippleTool::InitiateDrag(Block *clicked_item,
|
||||
// or we'll have to create a new gap ourselves
|
||||
Block* previous = block_after_ripple->previous();
|
||||
|
||||
if (previous && previous->type() == Block::kGap) {
|
||||
if (dynamic_cast<GapBlock*>(previous)) {
|
||||
// Previous is a gap, that'll make a fine substitute
|
||||
ghost = AddGhostFromBlock(previous, trim_mode);
|
||||
} else {
|
||||
|
||||
@@ -45,7 +45,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event)
|
||||
}
|
||||
|
||||
Block* block_at_time = t->BlockAtTime(event->GetFrame());
|
||||
if (!block_at_time || block_at_time->type() != Block::kClip) {
|
||||
if (!dynamic_cast<ClipBlock*>(block_at_time)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event)
|
||||
trim_mode = Timeline::kTrimIn;
|
||||
|
||||
if (cursor_frame < tenth_point
|
||||
&& block_at_time->previous()
|
||||
&& block_at_time->previous()->type() == Block::kClip) {
|
||||
&& dynamic_cast<ClipBlock*>(block_at_time->previous())) {
|
||||
other_block = block_at_time->previous();
|
||||
}
|
||||
} else {
|
||||
@@ -70,8 +69,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event)
|
||||
dual_transition_ = (cursor_frame > block_at_time->length() - tenth_point);
|
||||
|
||||
if (cursor_frame > block_at_time->length() - tenth_point
|
||||
&& block_at_time->next()
|
||||
&& block_at_time->next()->type() == Block::kClip) {
|
||||
&& dynamic_cast<ClipBlock*>(block_at_time->next())) {
|
||||
other_block = block_at_time->next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ void TimelineView::DrawBlocks(QPainter *painter, bool foreground)
|
||||
Block* block = track->NearestBlockBeforeOrAt(start_time);
|
||||
|
||||
while (block) {
|
||||
if (block->type() == Block::kClip || block->type() == Block::kTransition) {
|
||||
if (dynamic_cast<ClipBlock*>(block) || dynamic_cast<TransitionBlock*>(block)) {
|
||||
|
||||
qreal block_left = qMax(left_bound, TimeToScene(block->in()));
|
||||
qreal block_right = qMin(right_bound, TimeToScene(block->out())) - 1;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/output/track/track.h"
|
||||
#include "node/project/footage/footage.h"
|
||||
#include "timeline/timelinecommon.h"
|
||||
@@ -67,16 +69,11 @@ public:
|
||||
ghost->SetTrack(block->track()->ToReference());
|
||||
ghost->SetData(kAttachedBlock, Node::PtrToValue(block));
|
||||
|
||||
switch (block->type()) {
|
||||
case Block::kClip:
|
||||
if (dynamic_cast<ClipBlock*>(block)) {
|
||||
ghost->can_have_zero_length_ = false;
|
||||
break;
|
||||
case Block::kTransition:
|
||||
} else if (dynamic_cast<TransitionBlock*>(block)) {
|
||||
ghost->can_have_zero_length_ = false;
|
||||
ghost->SetCanMoveTracks(false);
|
||||
break;
|
||||
case Block::kGap:
|
||||
break;
|
||||
}
|
||||
|
||||
return ghost;
|
||||
|
||||
Reference in New Issue
Block a user