track movement with pointer tool
This commit is contained in:
+1
-1
@@ -147,7 +147,7 @@ QList<Node *> Node::GetExclusiveDependencies()
|
||||
if (deps.contains(edge->input()->parent())) {
|
||||
deps.removeAt(i);
|
||||
|
||||
i--; // -1 since we just removed a Node here
|
||||
i--; // -1 since we just removed a Node in this list
|
||||
j = params.size(); // No need to keep looking at this Node's params
|
||||
break; // Or this param's edges
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ private:
|
||||
|
||||
QGraphicsItem* GetItemAtScenePos(const QPointF& scene_pos);
|
||||
|
||||
rational ValidateMovement(rational movement, const QVector<TimelineViewGhostItem*> ghosts);
|
||||
rational ValidateFrameMovement(rational movement, const QVector<TimelineViewGhostItem*> ghosts);
|
||||
int ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem*> ghosts);
|
||||
|
||||
bool dragging_;
|
||||
|
||||
@@ -117,6 +118,8 @@ private:
|
||||
virtual void MousePress(QMouseEvent *event);
|
||||
virtual void MouseMove(QMouseEvent *event);
|
||||
virtual void MouseRelease(QMouseEvent *event);
|
||||
private:
|
||||
int track_start_;
|
||||
};
|
||||
|
||||
class ImportTool : public Tool
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "timelineviewrect.h"
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "timelineviewghostitem.h"
|
||||
|
||||
/**
|
||||
* @brief A graphical representation of a ClipBlock
|
||||
|
||||
@@ -30,6 +30,24 @@ TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) :
|
||||
setPen(QPen(Qt::yellow, 2)); // FIXME: Make customizable via CSS
|
||||
}
|
||||
|
||||
TimelineViewGhostItem *TimelineViewGhostItem::FromClip(TimelineViewClipItem *clip_item)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
ghost->SetY(clip_item->Y());
|
||||
ghost->SetHeight(clip_item->Height());
|
||||
ghost->SetTrack(clip_item->Track());
|
||||
ghost->setPos(clip_item->pos());
|
||||
|
||||
ClipBlock* clip = clip_item->clip();
|
||||
|
||||
ghost->SetIn(clip->in());
|
||||
ghost->SetOut(clip->out());
|
||||
ghost->SetData(Node::PtrToValue(clip));
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::In()
|
||||
{
|
||||
return in_;
|
||||
@@ -78,6 +96,11 @@ void TimelineViewGhostItem::SetOutAdjustment(const rational &out_adj)
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj)
|
||||
{
|
||||
track_adj_ = track_adj;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::GetAdjustedIn()
|
||||
{
|
||||
return in_ + in_adj_;
|
||||
@@ -88,6 +111,11 @@ rational TimelineViewGhostItem::GetAdjustedOut()
|
||||
return out_ + out_adj_;
|
||||
}
|
||||
|
||||
int TimelineViewGhostItem::GetAdjustedTrack()
|
||||
{
|
||||
return track_ + track_adj_;
|
||||
}
|
||||
|
||||
const QVariant &TimelineViewGhostItem::data()
|
||||
{
|
||||
return data_;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QVariant>
|
||||
|
||||
#include "project/item/footage/footage.h"
|
||||
#include "timelineviewclipitem.h"
|
||||
#include "timelineviewrect.h"
|
||||
|
||||
/**
|
||||
@@ -34,6 +35,8 @@ class TimelineViewGhostItem : public TimelineViewRect
|
||||
public:
|
||||
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
static TimelineViewGhostItem* FromClip(TimelineViewClipItem* clip_item);
|
||||
|
||||
const rational& In();
|
||||
const rational& Out();
|
||||
|
||||
@@ -45,9 +48,11 @@ public:
|
||||
|
||||
void SetInAdjustment(const rational& in_adj);
|
||||
void SetOutAdjustment(const rational& out_adj);
|
||||
void SetTrackAdjustment(const int& track_adj);
|
||||
|
||||
rational GetAdjustedIn();
|
||||
rational GetAdjustedOut();
|
||||
int GetAdjustedTrack();
|
||||
|
||||
const QVariant& data();
|
||||
void SetData(const QVariant& data);
|
||||
@@ -63,6 +68,8 @@ private:
|
||||
rational in_adj_;
|
||||
rational out_adj_;
|
||||
|
||||
int track_adj_;
|
||||
|
||||
StreamPtr stream_;
|
||||
|
||||
QVariant data_;
|
||||
|
||||
@@ -102,7 +102,7 @@ void TimelineView::ImportTool::DragMove(QDragMoveEvent *event)
|
||||
int ghost_y = parent()->GetTrackY(ghost_track);
|
||||
int ghost_height = parent()->GetTrackHeight(ghost_track);
|
||||
|
||||
time_movement = ValidateMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateFrameMovement(time_movement, parent()->ghost_items_);
|
||||
|
||||
// Move ghosts to the mouse cursor
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
|
||||
@@ -55,31 +55,19 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
|
||||
if (!dragging_) {
|
||||
|
||||
drag_start_ = GetScenePos(event->pos());
|
||||
track_start_ = parent()->SceneToTrack(drag_start_.y());
|
||||
|
||||
// Let's see if there's anything selected to drag
|
||||
if (GetItemAtScenePos(drag_start_) != nullptr) {
|
||||
QList<QGraphicsItem*> selected_items = parent()->scene_.selectedItems();
|
||||
|
||||
foreach (QGraphicsItem* item, selected_items) {
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
TimelineViewClipItem* clip_item = static_cast<TimelineViewClipItem*>(item);
|
||||
TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromClip(clip_item);
|
||||
|
||||
ClipBlock* clip = clip_item->clip();
|
||||
|
||||
ghost->SetY(clip_item->Y());
|
||||
ghost->SetHeight(clip_item->Height());
|
||||
ghost->SetIn(clip->in());
|
||||
ghost->SetOut(clip->out());
|
||||
ghost->SetScale(parent()->scale_);
|
||||
ghost->SetData(Node::PtrToValue(clip));
|
||||
|
||||
// FIXME: Very bad. Change immediately.
|
||||
ghost->SetTrack(parent()->SceneToTrack(drag_start_.y()));
|
||||
|
||||
ghost->setPos(clip_item->pos());
|
||||
|
||||
parent()->ghost_items_.append(ghost);
|
||||
|
||||
parent()->scene_.addItem(ghost);
|
||||
}
|
||||
}
|
||||
@@ -89,17 +77,26 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
|
||||
} else if (!parent()->ghost_items_.isEmpty()) {
|
||||
QPointF scene_pos = GetScenePos(event->pos());
|
||||
|
||||
int cursor_track = parent()->SceneToTrack(scene_pos.y());
|
||||
int track_movement = cursor_track - track_start_;
|
||||
|
||||
QPointF movement = scene_pos - drag_start_;
|
||||
|
||||
rational time_movement = parent()->SceneToTime(movement.x());
|
||||
|
||||
// Validate movement
|
||||
time_movement = ValidateMovement(time_movement, parent()->ghost_items_);
|
||||
time_movement = ValidateFrameMovement(time_movement, parent()->ghost_items_);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
// Perform movement
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
ghost->SetInAdjustment(time_movement);
|
||||
ghost->SetOutAdjustment(time_movement);
|
||||
|
||||
ghost->SetTrackAdjustment(track_movement);
|
||||
int track = ghost->GetAdjustedTrack();
|
||||
ghost->SetY(parent()->GetTrackY(track));
|
||||
ghost->SetHeight(parent()->GetTrackHeight(track));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +123,7 @@ void TimelineView::PointerTool::MouseRelease(QMouseEvent *event)
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data());
|
||||
|
||||
emit parent()->RequestPlaceBlock(b, ghost->GetAdjustedIn(), ghost->Track());
|
||||
emit parent()->RequestPlaceBlock(b, ghost->GetAdjustedIn(), ghost->GetAdjustedTrack());
|
||||
}
|
||||
|
||||
parent()->ClearGhosts();
|
||||
|
||||
@@ -57,12 +57,26 @@ QGraphicsItem *TimelineView::Tool::GetItemAtScenePos(const QPointF &scene_pos)
|
||||
return parent()->scene_.itemAt(scene_pos, parent()->transform());
|
||||
}
|
||||
|
||||
rational TimelineView::Tool::ValidateMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
rational TimelineView::Tool::ValidateFrameMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
// Prevents any ghosts from going below 0:00:00 time
|
||||
rational validator = ghost->In() + movement;
|
||||
if (validator < 0) {
|
||||
movement = rational(0) - ghost->In();
|
||||
movement = -ghost->In();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
int TimelineView::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
// Prevents any ghosts from going to a non-existent negative track
|
||||
int validator = ghost->Track() + movement;
|
||||
if (validator < 0) {
|
||||
movement = -ghost->Track();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user