Skip to content

Commit

Permalink
QskGestureRecognizer improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Oct 11, 2023
1 parent 2e980f0 commit 208865b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 8 additions & 4 deletions examples/gallery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
}
Expand Down
9 changes: 3 additions & 6 deletions src/controls/QskGestureRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/controls/QskGestureRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions src/controls/QskScrollBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}
Expand Down

0 comments on commit 208865b

Please sign in to comment.