Skip to content

Commit

Permalink
timebasedviewselectionmanager: scale/unscale when dragging too
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Mar 11, 2023
1 parent 9f4124b commit 3e47da7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
10 changes: 3 additions & 7 deletions app/widget/keyframeview/keyframeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ void KeyframeView::CatchUpScrollEvent()
{
super::CatchUpScrollEvent();

if (this->selection_manager_.IsRubberBanding()) {
this->selection_manager_.RubberBandMove(this->viewport()->mapFromGlobal(QCursor::pos()));
}
this->selection_manager_.ForceDragUpdate();
}

void KeyframeView::mousePressEvent(QMouseEvent *event)
Expand Down Expand Up @@ -296,7 +294,7 @@ void KeyframeView::mouseMoveEvent(QMouseEvent *event)
} else if (selection_manager_.IsDragging()) {
QString tip;
KeyframeDragMove(event, tip);
selection_manager_.DragMove(event, tip);
selection_manager_.DragMove(event->pos(), tip);
} else if (selection_manager_.IsRubberBanding()) {
selection_manager_.RubberBandMove(event->pos());
Redraw();
Expand Down Expand Up @@ -629,9 +627,7 @@ void KeyframeView::ShowKeyframePropertiesDialog()

void KeyframeView::UpdateRubberBandForScroll()
{
if (this->selection_manager_.IsRubberBanding()) {
this->selection_manager_.RubberBandMove(this->viewport()->mapFromGlobal(QCursor::pos()));
}
this->selection_manager_.ForceDragUpdate();
}

void KeyframeView::Redraw()
Expand Down
26 changes: 18 additions & 8 deletions app/widget/timebased/timebasedviewselectionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class TimeBasedViewSelectionManager
}
}

drag_mouse_start_ = view_->mapToScene(event->pos());
drag_mouse_start_ = view_->UnscalePoint(view_->mapToScene(event->pos()));
}

void SnapPoints(rational *movement)
Expand All @@ -233,9 +233,9 @@ class TimeBasedViewSelectionManager
}
}

void DragMove(QMouseEvent *event, const QString &tip_format = QString())
void DragMove(const QPoint &local_pos, const QString &tip_format = QString())
{
rational time_diff = view_->SceneToTimeNoGrid(view_->mapToScene(event->pos()).x() - drag_mouse_start_.x());
rational time_diff = view_->SceneToTimeNoGrid(view_->mapToScene(local_pos).x() - view_->ScalePoint(drag_mouse_start_).x());

// Snap points
rational presnap_time_diff = time_diff;
Expand Down Expand Up @@ -313,6 +313,7 @@ class TimeBasedViewSelectionManager
display_time, timebase_,
Core::instance()->GetTimecodeDisplay(), false));

last_used_tip_format_ = tip_format;
if (!tip_format.isEmpty()) {
tip = tip_format.arg(tip);
}
Expand All @@ -321,11 +322,6 @@ class TimeBasedViewSelectionManager
QToolTip::showText(QCursor::pos(), tip);
}

void DragMove(QMouseEvent *event, TimeTargetObject *target)
{
return DragMove(event, QString(), target);
}

void DragStop(MultiUndoCommand *command)
{
QToolTip::hideText();
Expand Down Expand Up @@ -388,6 +384,18 @@ class TimeBasedViewSelectionManager
return rubberband_;
}

void ForceDragUpdate()
{
if (IsRubberBanding() || IsDragging()) {
QPoint local_pos = view_->viewport()->mapFromGlobal(QCursor::pos());
if (IsRubberBanding()) {
RubberBandMove(local_pos);
} else {
DragMove(local_pos, last_used_tip_format_);
}
}
}

private:
class SetTimeCommand : public UndoCommand
{
Expand Down Expand Up @@ -455,6 +463,8 @@ class TimeBasedViewSelectionManager

TimeTargetObject *time_target_;

QString last_used_tip_format_;

};

}
Expand Down
6 changes: 2 additions & 4 deletions app/widget/timeruler/seekablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void SeekableWidget::mouseMoveEvent(QMouseEvent *event)
selection_manager_.RubberBandMove(event->pos());
viewport()->update();
} else if (selection_manager_.IsDragging()) {
selection_manager_.DragMove(event);
selection_manager_.DragMove(event->pos());
} else if (dragging_) {
QPointF scene = mapToScene(event->pos());
if (resize_item_) {
Expand Down Expand Up @@ -422,9 +422,7 @@ void SeekableWidget::CatchUpScrollEvent()
{
super::CatchUpScrollEvent();

if (this->selection_manager_.IsRubberBanding()) {
this->selection_manager_.RubberBandMove(this->viewport()->mapFromGlobal(QCursor::pos()));
}
this->selection_manager_.ForceDragUpdate();
}

void SeekableWidget::DrawPlayhead(QPainter *p, int x, int y)
Expand Down

0 comments on commit 3e47da7

Please sign in to comment.