From 208865ba8d15e1216f053f06945c19ea37295eb4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 11 Oct 2023 09:18:09 +0200 Subject: [PATCH] QskGestureRecognizer improvements --- examples/gallery/main.cpp | 12 ++++++++---- src/controls/QskGestureRecognizer.cpp | 9 +++------ src/controls/QskGestureRecognizer.h | 3 ++- src/controls/QskScrollBox.cpp | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index b074c299b..f0916df07 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -229,19 +229,17 @@ namespace } { - auto drawer = new Drawer( parentItem() ); - drawer->setEdge( Qt::RightEdge ); - auto burger = new QskPushButton( "≡", this ); burger->setEmphasis( QskPushButton::LowEmphasis ); connect( burger, &QskPushButton::clicked, - drawer, &QskPopup::open ); + this, &Header::drawerRequested ); } } Q_SIGNALS: void enabledToggled( bool ); + void drawerRequested(); }; class MainView : public QskMainView @@ -264,6 +262,12 @@ namespace connect( header, &Header::enabledToggled, tabView, &TabView::setPagesEnabled ); + auto drawer = new Drawer( this ); + drawer->setEdge( Qt::RightEdge ); + + connect( header, &Header::drawerRequested, + drawer, &QskPopup::open ); + setHeader( header ); setBody( tabView ); } diff --git a/src/controls/QskGestureRecognizer.cpp b/src/controls/QskGestureRecognizer.cpp index b383730c9..099307ab7 100644 --- a/src/controls/QskGestureRecognizer.cpp +++ b/src/controls/QskGestureRecognizer.cpp @@ -142,12 +142,9 @@ Qt::MouseButtons QskGestureRecognizer::acceptedMouseButtons() const return m_data->buttons; } -QRectF QskGestureRecognizer::gestureRect() const +bool QskGestureRecognizer::isAcceptedPos( const QPointF& pos ) const { - if ( m_data->watchedItem ) - return qskItemRect( m_data->watchedItem ); - - return QRectF( 0.0, 0.0, -1.0, -1.0 ); + return m_data->watchedItem && m_data->watchedItem->contains( pos ); } void QskGestureRecognizer::setRejectOnTimeout( bool on ) @@ -313,7 +310,7 @@ bool QskGestureRecognizer::processMouseEvent( if ( event->type() == QEvent::MouseButtonPress ) { - if ( !gestureRect().contains( pos ) ) + if ( !isAcceptedPos( pos ) ) return false; if ( m_data->state != Idle ) diff --git a/src/controls/QskGestureRecognizer.h b/src/controls/QskGestureRecognizer.h index b34cd012d..c4ac00dc3 100644 --- a/src/controls/QskGestureRecognizer.h +++ b/src/controls/QskGestureRecognizer.h @@ -22,6 +22,7 @@ class QSK_EXPORT QskGestureRecognizer : public QObject Q_PROPERTY( State state READ state NOTIFY stateChanged ) Q_PROPERTY( QQuickItem* watchedItem READ watchedItem WRITE setWatchedItem ) + Q_PROPERTY( QQuickItem* targetItem READ targetItem WRITE setTargetItem ) Q_PROPERTY( Qt::MouseButtons acceptedMouseButtons READ acceptedMouseButtons WRITE setAcceptedMouseButtons ) @@ -72,7 +73,7 @@ class QSK_EXPORT QskGestureRecognizer : public QObject State state() const; - virtual QRectF gestureRect() const; + virtual bool isAcceptedPos( const QPointF& ) const; Q_SIGNALS: void stateChanged( State from, State to ); diff --git a/src/controls/QskScrollBox.cpp b/src/controls/QskScrollBox.cpp index a23048426..a975baedc 100644 --- a/src/controls/QskScrollBox.cpp +++ b/src/controls/QskScrollBox.cpp @@ -136,15 +136,15 @@ namespace setOrientations( Qt::Horizontal | Qt::Vertical ); } - QRectF gestureRect() const override + bool isAcceptedPos( const QPointF& pos ) const override { if ( auto scrollBox = qobject_cast< const QskScrollBox* >( watchedItem() ) ) { if ( qskIsScrollable( scrollBox, orientations() ) ) - return scrollBox->viewContentsRect(); + return scrollBox->viewContentsRect().contains( pos ); } - return QRectF( 0.0, 0.0, -1.0, -1.0 ); // empty + return false; } }; }