reimplemented "add" tool

Tool for adding empty/non-media clips in the timeline. Also basis of the
transition tool.
This commit is contained in:
itsmattkc
2019-12-11 19:54:53 +11:00
parent 7ae37511a2
commit 7b92b21df2
5 changed files with 137 additions and 5 deletions
+5 -5
View File
@@ -144,9 +144,9 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash, N
{
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
QVariant value = table.Get(NodeParam::kTexture);
OpenGLTextureCache::ReferencePtr ref = table.Get(NodeParam::kTexture).value<OpenGLTextureCache::ReferencePtr>();
if (value.isNull()) {
if (!ref) {
// No frame received, we set hash to an empty
frame_cache()->RemoveHash(path.in(), hash);
} else {
@@ -158,7 +158,7 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash, N
"Download",
Q_ARG(NodeDependency, path),
Q_ARG(QByteArray, hash),
Q_ARG(QVariant, value),
Q_ARG(QVariant, QVariant::fromValue(ref)),
Q_ARG(QString, cache_fn));
last_download_thread_++;
@@ -169,8 +169,8 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash, N
// FIXME: This texture is part of the texture cache and therefore volatile, we should probably copy it here instead
OpenGLTexturePtr tex = nullptr;
if (!value.isNull()) {
tex = value.value<OpenGLTextureCache::ReferencePtr>()->texture();
if (ref) {
tex = ref->texture();
}
emit CachedFrameReady(path.in(), QVariant::fromValue(tex));
@@ -287,6 +287,29 @@ private:
virtual void MouseRelease(TimelineViewMouseEvent *event);
};
class TransitionTool : public Tool
{
public:
TransitionTool(TimelineWidget* parent);
virtual void MousePress(TimelineViewMouseEvent *event);
virtual void MouseMove(TimelineViewMouseEvent *event);
virtual void MouseRelease(TimelineViewMouseEvent *event);
};
class AddTool : public Tool
{
public:
AddTool(TimelineWidget* parent);
virtual void MousePress(TimelineViewMouseEvent *event);
virtual void MouseMove(TimelineViewMouseEvent *event);
virtual void MouseRelease(TimelineViewMouseEvent *event);
private:
TimelineViewGhostItem* ghost_;
};
void SetBlockLinksSelected(Block *block, bool selected);
QPoint drag_origin_;
@@ -16,6 +16,7 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/tool/add.cpp
widget/timelinewidget/tool/hand.cpp
widget/timelinewidget/tool/import.cpp
widget/timelinewidget/tool/pointer.cpp
@@ -24,6 +25,7 @@ set(OLIVE_SOURCES
widget/timelinewidget/tool/rolling.cpp
widget/timelinewidget/tool/slide.cpp
widget/timelinewidget/tool/slip.cpp
widget/timelinewidget/tool/transition.cpp
widget/timelinewidget/tool/tool.cpp
widget/timelinewidget/tool/zoom.cpp
PARENT_SCOPE
+78
View File
@@ -0,0 +1,78 @@
#include "widget/timelinewidget/timelinewidget.h"
#include "core.h"
TimelineWidget::AddTool::AddTool(TimelineWidget *parent) :
Tool(parent),
ghost_(nullptr)
{
}
void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event)
{
const TrackReference& track = event->GetCoordinates().GetTrack();
TrackOutput* t = parent()->GetTrackFromReference(track);
if (t && t->IsLocked()) {
return;
}
ghost_ = new TimelineViewGhostItem();
ghost_->SetIn(event->GetCoordinates().GetFrame());
ghost_->SetOut(event->GetCoordinates().GetFrame());
ghost_->SetTrack(track);
ghost_->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
parent()->AddGhost(ghost_);
snap_points_.append(event->GetCoordinates().GetFrame());
}
void TimelineWidget::AddTool::MouseMove(TimelineViewMouseEvent *event)
{
const rational& cursor_frame = event->GetCoordinates().GetFrame();
// Calculate movement
rational movement = cursor_frame - ghost_->Out();
// Snap movement
SnapPoint(snap_points_, &movement);
// Validation: Ensure in point never goes below 0
if (movement < -ghost_->In()) {
movement = -ghost_->In();
}
// Make adjustment
if (!movement) {
ghost_->SetInAdjustment(0);
ghost_->SetOutAdjustment(0);
} else if (movement > 0) {
ghost_->SetInAdjustment(0);
ghost_->SetOutAdjustment(movement);
} else if (movement < 0) {
ghost_->SetInAdjustment(movement);
ghost_->SetOutAdjustment(0);
}
}
void TimelineWidget::AddTool::MouseRelease(TimelineViewMouseEvent *event)
{
MouseMove(event);
const TrackReference& track = ghost_->Track();
if (ghost_) {
if (!ghost_->AdjustedLength().isNull()) {
ClipBlock* clip = new ClipBlock();
clip->set_length(ghost_->AdjustedLength());
olive::undo_stack.push(new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(track.type()),
track.index(),
clip,
ghost_->GetAdjustedIn()));
}
parent()->ClearGhosts();
snap_points_.clear();
ghost_ = nullptr;
}
}
@@ -0,0 +1,29 @@
#include "widget/timelinewidget/timelinewidget.h"
TimelineWidget::TransitionTool::TransitionTool(TimelineWidget *parent) :
Tool(parent)
{
}
void TimelineWidget::TransitionTool::MousePress(TimelineViewMouseEvent *event)
{
TimelineViewBlockItem* item = GetItemAtScenePos(event->GetCoordinates());
bool selectable_item = (item != nullptr
&& item->flags() & QGraphicsItem::ItemIsSelectable
&& !parent()->GetTrackFromReference(item->Track())->IsLocked());
if (!selectable_item) {
return;
}
}
void TimelineWidget::TransitionTool::MouseMove(TimelineViewMouseEvent *event)
{
Q_UNUSED(event)
}
void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
{
Q_UNUSED(event)
}