timebasedviews: only drag playhead when there's no item underneath the cursor

This commit is contained in:
itsmattkc
2021-01-24 09:36:05 +11:00
parent 62bab2ec01
commit eb132d93de
4 changed files with 32 additions and 19 deletions
+3 -3
View File
@@ -113,7 +113,9 @@ KeyframeViewItem *KeyframeViewBase::AddKeyframeInternal(NodeKeyframe* key)
void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
{
if (HandPress(event) || PlayheadPress(event)) {
QGraphicsItem* item_under_cursor = itemAt(event->pos());
if (HandPress(event) || (!item_under_cursor && PlayheadPress(event))) {
return;
}
@@ -123,8 +125,6 @@ void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
QGraphicsView::mousePressEvent(event);
if (active_tool_ == Tool::kPointer) {
QGraphicsItem* item_under_cursor = itemAt(event->pos());
if (item_under_cursor) {
drag_start_ = event->pos();
+1 -11
View File
@@ -1441,17 +1441,7 @@ void TimelineWidget::SetSelections(const TimelineWidgetSelections &s)
Block *TimelineWidget::GetItemAtScenePos(const TimelineCoordinate& coord)
{
Track* track = GetTrackFromReference(coord.GetTrack());
foreach (Block* b, added_blocks_) {
if (b->in() <= coord.GetFrame()
&& b->out() > coord.GetFrame()
&& b->track() == track) {
return b;
}
}
return nullptr;
return views_.at(coord.GetTrack().type())->view()->GetItemAtScenePos(coord.GetFrame(), coord.GetTrack().index());
}
struct SnapData {
@@ -55,23 +55,29 @@ TimelineView::TimelineView(Qt::Alignment vertical_alignment, QWidget *parent) :
void TimelineView::mousePressEvent(QMouseEvent *event)
{
if (HandPress(event) || PlayheadPress(event)) {
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event);
if (HandPress(event)
|| (!GetItemAtScenePos(timeline_event.GetFrame(), timeline_event.GetTrack().index()) && PlayheadPress(event))) {
// Let the parent handle this
return;
}
if (dragMode() != GetDefaultDragMode()) {
// Use default behavior when hand dragging for instance
TimeBasedView::mousePressEvent(event);
return;
}
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event);
emit MousePressed(&timeline_event);
}
void TimelineView::mouseMoveEvent(QMouseEvent *event)
{
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event);
if (HandMove(event) || PlayheadMove(event)) {
// Let the parent handle this
return;
@@ -82,8 +88,6 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event)
return;
}
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event);
emit MouseMoved(&timeline_event);
}
@@ -560,6 +564,23 @@ int TimelineView::SceneToTrack(double y)
return track;
}
Block *TimelineView::GetItemAtScenePos(const rational &time, int track_index) const
{
if (connected_track_list_) {
Track* track = connected_track_list_->GetTrackAt(track_index);
if (track) {
foreach (Block* b, track->Blocks()) {
if (b->in() <= time && b->out() > time) {
return b;
}
}
}
}
return nullptr;
}
void TimelineView::UserSetTime(const int64_t &time)
{
SetTime(time);
@@ -68,6 +68,8 @@ public:
int SceneToTrack(double y);
Block* GetItemAtScenePos(const rational& time, int track_index) const;
signals:
void MousePressed(TimelineViewMouseEvent* event);
void MouseMoved(TimelineViewMouseEvent* event);