From 05d9b98dd7fa97277760df9da2e9b706fb05bf93 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 18 Apr 2019 16:13:49 +0200 Subject: [PATCH] pan gesture detection modified --- src/controls/QskPanGestureRecognizer.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/controls/QskPanGestureRecognizer.cpp b/src/controls/QskPanGestureRecognizer.cpp index 9a24342b..feef964d 100644 --- a/src/controls/QskPanGestureRecognizer.cpp +++ b/src/controls/QskPanGestureRecognizer.cpp @@ -7,6 +7,26 @@ #include #include +static inline bool qskIsInOrientation( + const QPointF& from, const QPointF& to, Qt::Orientations orientations ) +{ + if ( orientations == ( Qt::Horizontal | Qt::Vertical ) ) + return true; + + const qreal dx = std::fabs( to.x() - from.x() ); + const qreal dy = std::fabs( to.y() - from.y() ); + + const qreal ratio = 0.75; + + if ( orientations == Qt::Horizontal ) + return ( dx >= ratio * dy ); + + if ( orientations == Qt::Vertical ) + return ( dy >= ratio * dx ); + + return false; // should never happen +} + static inline qreal qskDistance( const QPointF& from, const QPointF& to, Qt::Orientations orientations ) { @@ -202,7 +222,8 @@ void QskPanGestureRecognizer::moveEvent( const QMouseEvent* event ) const qreal dist = qskDistance( m_data->origin, m_data->pos, m_data->orientations ); - if ( ( dist >= m_data->minDistance ) || ( -dist >= m_data->minDistance ) ) + if ( ( qAbs( dist ) >= m_data->minDistance ) && + qskIsInOrientation( m_data->origin, m_data->pos, m_data->orientations ) ) { accept(); started = true;