qskinny/src/controls/QskGestureRecognizer.h

105 lines
2.7 KiB
C
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 16:21:34 +00:00
*****************************************************************************/
#ifndef QSK_GESTURE_RECOGNIZER_H
#define QSK_GESTURE_RECOGNIZER_H
#include "QskGlobal.h"
2018-07-19 12:10:48 +00:00
#include <qobject.h>
2018-07-19 12:10:48 +00:00
#include <qnamespace.h>
2017-07-21 16:21:34 +00:00
#include <memory>
class QQuickItem;
class QEvent;
class QMouseEvent;
class QSK_EXPORT QskGestureRecognizer : public QObject
2017-07-21 16:21:34 +00:00
{
Q_OBJECT
Q_PROPERTY( State state READ state NOTIFY stateChanged )
Q_PROPERTY( QQuickItem* watchedItem READ watchedItem WRITE setWatchedItem )
Q_PROPERTY( Qt::MouseButtons acceptedMouseButtons
READ acceptedMouseButtons WRITE setAcceptedMouseButtons )
Q_PROPERTY( int timeout READ timeout WRITE setTimeout )
using Inherited = QObject;
2018-08-03 06:15:28 +00:00
public:
2017-07-21 16:21:34 +00:00
enum State
{
Idle,
Pending,
Accepted
};
Q_ENUM( State )
QskGestureRecognizer( QObject* parent = nullptr );
~QskGestureRecognizer() override;
bool eventFilter( QObject*, QEvent* ) override;
2017-07-21 16:21:34 +00:00
// the item where the gesture happens
2017-07-21 16:21:34 +00:00
void setWatchedItem( QQuickItem* );
QQuickItem* watchedItem() const;
// the item processing the gesture events
void setTargetItem( QQuickItem* );
QQuickItem* targetItem() const;
2017-07-21 16:21:34 +00:00
// Qt::NoButton means: all buttons accepted
void setAcceptedMouseButtons( Qt::MouseButtons );
Qt::MouseButtons acceptedMouseButtons() const;
void setRejectOnTimeout( bool );
bool rejectOnTimeout() const;
2017-07-21 16:21:34 +00:00
void setTimeout( int );
int timeout() const;
// timestamp, when the Idle state had been left
quint64 timestampStarted() const;
2017-07-21 16:21:34 +00:00
void reject();
void accept();
void abort();
State state() const;
virtual QRectF gestureRect() const;
Q_SIGNALS:
void stateChanged( State from, State to );
2017-07-21 16:21:34 +00:00
protected:
void timerEvent( QTimerEvent* ) override;
/*
This API works for single-touch gestures and multi-touch gestures,
that can be translated to single positions ( f.e 2 finger swipes ).
Once we support more complex inputs ( f.e pinch gesture ) we need to
make substantial adjustments here.
*/
virtual void processPress( const QPointF&, quint64 timestamp, bool isFinal );
virtual void processMove( const QPointF&, quint64 timestamp );
virtual void processRelease( const QPointF&, quint64 timestamp );
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
private:
bool maybeGesture( const QQuickItem*, const QEvent* );
bool processMouseEvent( const QQuickItem*, const QMouseEvent* );
2017-07-21 16:21:34 +00:00
void setState( State );
void reset();
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
#endif