mouse press handling fixed

This commit is contained in:
Uwe Rathmann 2023-07-31 15:06:41 +02:00
parent a7aef1a8a0
commit 849411ea97
3 changed files with 58 additions and 25 deletions

View File

@ -79,6 +79,17 @@ class Thumbnail : public QskPushButton
setStrutSizeHint( QskPushButton::Icon, -1, -1 );
}
#if 0
void mousePressEvent( QMouseEvent* event ) override
{
/*
rgnore events: to check if the pae gesture recoognizer of the scroll
area becomes active without timeout ( see QskScrollBox::mousePressEvent )
*/
event->setAccepted( false );
}
#endif
private:
QskGraphic thumbnailGraphic( const QColor& color,
int shape, const QSizeF& size ) const

View File

@ -362,6 +362,25 @@ void QskScrollBox::geometryChangeEvent( QskGeometryChangeEvent* event )
Inherited::geometryChangeEvent( event );
}
void QskScrollBox::mousePressEvent( QMouseEvent* event )
{
auto& recognizer = m_data->panRecognizer;
if ( recognizer.hasProcessedBefore( event ) )
{
if ( m_data->panRecognizerTimeout != 0 )
{
recognizer.abort();
recognizer.setTimeout( -1 );
recognizer.processEvent( this, event, false );
}
return;
}
return Inherited::mousePressEvent( event );
}
void QskScrollBox::gestureEvent( QskGestureEvent* event )
{
if ( event->gesture()->type() == QskGesture::Pan )
@ -458,6 +477,12 @@ bool QskScrollBox::gestureFilter( QQuickItem* item, QEvent* event )
return false;
}
auto& recognizer = m_data->panRecognizer;
recognizer.setTimeout( m_data->panRecognizerTimeout );
if ( event->type() == QEvent::MouseButtonPress )
{
/*
This code is a bit tricky as the filter is called in different situations:
@ -472,24 +497,19 @@ bool QskScrollBox::gestureFilter( QQuickItem* item, QEvent* event )
could be made the recognizer aborts and replays the mouse events, so
that the children can process them.
But if a child does not accept a mouse event it will be sent to
its parent. So we might finally receive the reposted events, but then
we can proceed as in b).
But if a child does not accept the mouse event it will be sent to
its parent, finally ending up here for a second time.
*/
auto& recognizer = m_data->panRecognizer;
if ( event->type() == QEvent::MouseButtonPress )
{
if ( ( item != this ) && ( recognizer.timeout() < 0 ) )
{
const auto mouseEvent = static_cast< QMouseEvent* >( event );
if ( recognizer.hasProcessedBefore( mouseEvent ) )
{
/*
Note that the recognizer will be restarted without timout if the
event ends up in in mousePressEvent ( = nobody else was interested )
*/
return false;
}
recognizer.setTimeout( ( item == this ) ? -1 : m_data->panRecognizerTimeout );
}
return recognizer.processEvent( item, event );

View File

@ -64,6 +64,8 @@ class QSK_EXPORT QskScrollBox : public QskControl
protected:
void geometryChangeEvent( QskGeometryChangeEvent* ) override;
void windowChangeEvent( QskWindowChangeEvent* ) override;
void mousePressEvent( QMouseEvent* ) override;
void gestureEvent( QskGestureEvent* ) override;
#ifndef QT_NO_WHEELEVENT