timebased: transform keyframe times to global for snapping
This commit is contained in:
@@ -78,6 +78,11 @@ protected:
|
||||
return &view_->GetKeyframeTracks();
|
||||
}
|
||||
|
||||
virtual const TimeTargetObject *GetKeyframeTimeTarget() const override
|
||||
{
|
||||
return view_;
|
||||
}
|
||||
|
||||
virtual const std::vector<NodeKeyframe*> *GetSnapIgnoreKeyframes() const override
|
||||
{
|
||||
return &view_->GetSelectedKeyframes();
|
||||
|
||||
@@ -261,7 +261,7 @@ void KeyframeView::mousePressEvent(QMouseEvent *event)
|
||||
if (FirstChanceMousePress(event)) {
|
||||
first_chance_mouse_event_ = true;
|
||||
} else if (NodeKeyframe *initial_key = selection_manager_.MousePress(event)) {
|
||||
selection_manager_.DragStart(initial_key, event);
|
||||
selection_manager_.DragStart(initial_key, event, this);
|
||||
KeyframeDragStart(event);
|
||||
} else {
|
||||
selection_manager_.RubberBandStart(event);
|
||||
|
||||
@@ -107,6 +107,11 @@ protected:
|
||||
return keyframe_view_ ? &keyframe_view_->GetSelectedKeyframes() : nullptr;
|
||||
}
|
||||
|
||||
virtual const TimeTargetObject *GetKeyframeTimeTarget() const
|
||||
{
|
||||
return keyframe_view_;
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateItemTime(const rational &time);
|
||||
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
#include <QRubberBand>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "common/qtutils.h"
|
||||
#include "common/rational.h"
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "timebasedview.h"
|
||||
#include "timebasedwidget.h"
|
||||
#include "widget/timetarget/timetarget.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -158,8 +160,10 @@ public:
|
||||
return !dragging_.empty();
|
||||
}
|
||||
|
||||
void DragStart(T *initial_item, QMouseEvent *event)
|
||||
void DragStart(T *initial_item, QMouseEvent *event, TimeTargetObject *target = nullptr)
|
||||
{
|
||||
time_target_ = target;
|
||||
|
||||
initial_drag_item_ = initial_item;
|
||||
|
||||
dragging_.resize(selected_.size());
|
||||
@@ -170,6 +174,13 @@ public:
|
||||
snap_points_.resize(selected_.size());
|
||||
}
|
||||
|
||||
if (target) {
|
||||
time_targets_.resize(snap_points_.size());
|
||||
memset(time_targets_.data(), 0, time_targets_.size() * sizeof(Node*));
|
||||
} else {
|
||||
time_targets_.clear();
|
||||
}
|
||||
|
||||
for (size_t i=0; i<selected_.size(); i++) {
|
||||
T *obj = selected_.at(i);
|
||||
|
||||
@@ -177,9 +188,17 @@ public:
|
||||
dragging_[i] = obj->time().in();
|
||||
snap_points_[i] = obj->time().in();
|
||||
snap_points_[i+selected_.size()] = obj->time().out();
|
||||
|
||||
if (target) {
|
||||
time_targets_[i] = time_targets_[i+selected_.size()] = QtUtils::GetParentOfType<Node>(obj);
|
||||
}
|
||||
} else {
|
||||
dragging_[i] = obj->time();
|
||||
snap_points_[i] = obj->time();
|
||||
|
||||
if (target) {
|
||||
time_targets_[i] = QtUtils::GetParentOfType<Node>(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +207,18 @@ public:
|
||||
|
||||
void SnapPoints(rational *movement)
|
||||
{
|
||||
std::vector<rational> copy = snap_points_;
|
||||
|
||||
if (time_target_) {
|
||||
for (size_t i=0; i<copy.size(); i++) {
|
||||
if (Node *parent = time_targets_[i]) {
|
||||
copy[i] = time_target_->GetAdjustedTime(parent, time_target_->GetTimeTarget(), copy[i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Core::instance()->snapping() && view_->GetSnapService()) {
|
||||
view_->GetSnapService()->SnapPoint(snap_points_, movement, snap_mask_);
|
||||
view_->GetSnapService()->SnapPoint(copy, movement, snap_mask_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +316,11 @@ public:
|
||||
QToolTip::showText(QCursor::pos(), tip);
|
||||
}
|
||||
|
||||
void DragMove(QMouseEvent *event, TimeTargetObject *target)
|
||||
{
|
||||
return DragMove(event, QString(), target);
|
||||
}
|
||||
|
||||
void DragStop(MultiUndoCommand *command)
|
||||
{
|
||||
QToolTip::hideText();
|
||||
@@ -399,6 +433,7 @@ private:
|
||||
|
||||
std::vector<rational> dragging_;
|
||||
std::vector<rational> snap_points_;
|
||||
std::vector<Node*> time_targets_;
|
||||
|
||||
T *initial_drag_item_;
|
||||
|
||||
@@ -412,6 +447,8 @@ private:
|
||||
|
||||
TimeBasedWidget::SnapMask snap_mask_;
|
||||
|
||||
TimeTargetObject *time_target_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -865,9 +865,16 @@ bool TimeBasedWidget::SnapPoint(const std::vector<rational> &start_times, ration
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal key_scene_pt = TimeToScene(key->time());
|
||||
rational time = key->time();
|
||||
if (const TimeTargetObject *target = GetKeyframeTimeTarget()) {
|
||||
if (Node *parent = key->parent()) {
|
||||
time = target->GetAdjustedTime(parent, target->GetTimeTarget(), time, false);
|
||||
}
|
||||
}
|
||||
|
||||
AttemptSnap(potential_snaps, screen_pt, key_scene_pt, start_times, key->time());
|
||||
qreal key_scene_pt = TimeToScene(time);
|
||||
|
||||
AttemptSnap(potential_snaps, screen_pt, key_scene_pt, start_times, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "widget/resizablescrollbar/resizabletimelinescrollbar.h"
|
||||
#include "widget/timebased/timescaledobject.h"
|
||||
#include "widget/timelinewidget/view/timelineview.h"
|
||||
#include "widget/timetarget/timetarget.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -153,6 +154,7 @@ protected:
|
||||
|
||||
virtual const QVector<Block*> *GetSnapBlocks() const { return nullptr; }
|
||||
virtual const QVector<KeyframeViewInputConnection*> *GetSnapKeyframes() const { return nullptr; }
|
||||
virtual const TimeTargetObject *GetKeyframeTimeTarget() const { return nullptr; }
|
||||
virtual const std::vector<NodeKeyframe*> *GetSnapIgnoreKeyframes() const { return nullptr; }
|
||||
virtual const std::vector<TimelineMarker*> *GetSnapIgnoreMarkers() const { return nullptr; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user