diff --git a/app/node/block/CMakeLists.txt b/app/node/block/CMakeLists.txt index 12e0fa125..97828e68b 100644 --- a/app/node/block/CMakeLists.txt +++ b/app/node/block/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(clip) add_subdirectory(gap) +add_subdirectory(transition) set(OLIVE_SOURCES ${OLIVE_SOURCES} diff --git a/app/node/block/block.h b/app/node/block/block.h index c8c71db0f..b55e08145 100644 --- a/app/node/block/block.h +++ b/app/node/block/block.h @@ -42,7 +42,8 @@ public: enum Type { kClip, kGap, - kTrack + kTrack, + kTransition }; virtual Type type() const = 0; @@ -54,9 +55,9 @@ public: void set_in(const rational& in); void set_out(const rational& out); - const rational &length() const; - void set_length(const rational &length); - void set_length_and_media_in(const rational &length); + const rational& length() const; + virtual void set_length(const rational &length); + virtual void set_length_and_media_in(const rational &length); Block* previous(); Block* next(); diff --git a/app/node/block/transition/CMakeLists.txt b/app/node/block/transition/CMakeLists.txt new file mode 100644 index 000000000..65f672588 --- /dev/null +++ b/app/node/block/transition/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2019 Olive Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + node/block/transition/transition.h + node/block/transition/transition.cpp + PARENT_SCOPE +) diff --git a/app/node/block/transition/transition.cpp b/app/node/block/transition/transition.cpp new file mode 100644 index 000000000..cf417953c --- /dev/null +++ b/app/node/block/transition/transition.cpp @@ -0,0 +1,62 @@ +#include "transition.h" + +TransitionBlock::TransitionBlock() +{ + out_block_input_ = new NodeInput("out_block_in"); + AddInput(out_block_input_); + + in_block_input_ = new NodeInput("in_block_in"); + AddInput(in_block_input_); +} + +Block::Type TransitionBlock::type() const +{ + return kTransition; +} + +NodeInput *TransitionBlock::out_block_input() const +{ + return out_block_input_; +} + +NodeInput *TransitionBlock::in_block_input() const +{ + return in_block_input_; +} + +void TransitionBlock::Retranslate() +{ + out_block_input_->set_name(tr("From")); + in_block_input_->set_name(tr("To")); +} + +void TransitionBlock::set_length(const rational &length) +{ + Q_UNUSED(length) + qCritical() << "Set length is not permitted on a transition"; + abort(); +} + +void TransitionBlock::set_length_and_media_in(const rational &length) +{ + Q_UNUSED(length) + qCritical() << "Set length and media in is not permitted on a transition"; + abort(); +} + +void TransitionBlock::set_in_offset(const rational &in_offset) +{ + in_offset_ = in_offset; + RecalculateLength(); +} + +void TransitionBlock::set_out_offset(const rational &out_offset) +{ + out_offset_ = out_offset; + RecalculateLength(); +} + +void TransitionBlock::RecalculateLength() +{ + Block::set_length(in_offset_ + out_offset_); +} diff --git a/app/node/block/transition/transition.h b/app/node/block/transition/transition.h new file mode 100644 index 000000000..dc2213fb5 --- /dev/null +++ b/app/node/block/transition/transition.h @@ -0,0 +1,38 @@ +#ifndef TRANSITIONBLOCK_H +#define TRANSITIONBLOCK_H + +#include "node/block/block.h" + +class TransitionBlock : public Block +{ +public: + TransitionBlock(); + + virtual Type type() const override; + + NodeInput* out_block_input() const; + + NodeInput* in_block_input() const; + + virtual void Retranslate() override; + + virtual void set_length(const rational &length) override; + virtual void set_length_and_media_in(const rational &length) override; + + void set_in_offset(const rational& in_offset); + void set_out_offset(const rational& out_offset); + +private: + void RecalculateLength(); + + NodeInput* out_block_input_; + + NodeInput* in_block_input_; + + rational in_offset_; + + rational out_offset_; + +}; + +#endif // TRANSITIONBLOCK_H diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index ecf24e6e8..4c8aababb 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -573,6 +573,7 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track) { switch (block->type()) { case Block::kClip: + case Block::kTransition: case Block::kGap: { TimelineViewBlockItem* item = new TimelineViewBlockItem(); diff --git a/app/widget/timelinewidget/view/timelineviewblockitem.cpp b/app/widget/timelinewidget/view/timelineviewblockitem.cpp index 48752201b..d227e0c12 100644 --- a/app/widget/timelinewidget/view/timelineviewblockitem.cpp +++ b/app/widget/timelinewidget/view/timelineviewblockitem.cpp @@ -79,6 +79,7 @@ void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsI switch (block_->type()) { case Block::kClip: + case Block::kTransition: // FIXME: Temporary, the transition should have its own UI representation at some point /*QLinearGradient grad; grad.setStart(0, rect().top()); grad.setFinalStop(0, rect().bottom());