gestures: prevent deciding on a direction too eary
Doing that breaks when the input device has a very high resolution, which is the case with touchscreens for example. The minimum delta of 5 is an arbitrarily chosen value that can be changed if needed
This commit is contained in:
parent
cba443dbe3
commit
a4919786c6
1 changed files with 12 additions and 14 deletions
|
@ -199,30 +199,28 @@ void GestureRecognizer::updateSwipeGesture(const QSizeF &delta)
|
||||||
m_currentDelta += delta;
|
m_currentDelta += delta;
|
||||||
|
|
||||||
SwipeGesture::Direction direction; // Overall direction
|
SwipeGesture::Direction direction; // Overall direction
|
||||||
|
Axis swipeAxis;
|
||||||
|
|
||||||
// Pick an axis for gestures so horizontal ones don't change to vertical ones without lifting fingers
|
// Pick an axis for gestures so horizontal ones don't change to vertical ones without lifting fingers
|
||||||
if (m_currentSwipeAxis == Axis::None) {
|
if (m_currentSwipeAxis == Axis::None) {
|
||||||
if (std::abs(m_currentDelta.width()) >= std::abs(m_currentDelta.height())) {
|
if (std::abs(m_currentDelta.width()) >= std::abs(m_currentDelta.height())) {
|
||||||
// horizontal
|
swipeAxis = Axis::Horizontal;
|
||||||
direction = m_currentDelta.width() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
direction = m_currentDelta.width() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
||||||
} else if (std::abs(m_currentDelta.width()) < std::abs(m_currentDelta.height())) {
|
} else {
|
||||||
// vertical
|
swipeAxis = Axis::Vertical;
|
||||||
direction = m_currentDelta.height() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
direction = m_currentDelta.height() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
||||||
}
|
}
|
||||||
switch (direction) {
|
if (std::abs(m_currentDelta.width()) >= 5 || std::abs(m_currentDelta.height()) >= 5) {
|
||||||
case SwipeGesture::Direction::Up:
|
// only lock in a direction if the delta is big enough
|
||||||
case SwipeGesture::Direction::Down:
|
// to prevent accidentally choosing the wrong direction
|
||||||
m_currentSwipeAxis = Axis::Vertical;
|
m_currentSwipeAxis = swipeAxis;
|
||||||
break;
|
|
||||||
case SwipeGesture::Direction::Left:
|
|
||||||
case SwipeGesture::Direction::Right:
|
|
||||||
m_currentSwipeAxis = Axis::Horizontal;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
swipeAxis = m_currentSwipeAxis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the current swipe direction
|
// Find the current swipe direction
|
||||||
switch (m_currentSwipeAxis) {
|
switch (swipeAxis) {
|
||||||
case Axis::Vertical:
|
case Axis::Vertical:
|
||||||
direction = m_currentDelta.height() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
direction = m_currentDelta.height() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
||||||
break;
|
break;
|
||||||
|
@ -230,7 +228,7 @@ void GestureRecognizer::updateSwipeGesture(const QSizeF &delta)
|
||||||
direction = m_currentDelta.width() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
direction = m_currentDelta.width() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
Q_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eliminate wrong gestures (takes two iterations)
|
// Eliminate wrong gestures (takes two iterations)
|
||||||
|
|
Loading…
Reference in a new issue