2024-03-20 03:11:35 +00:00
|
|
|
#pragma once
|
2014-02-04 13:35:42 +00:00
|
|
|
|
2024-03-20 03:11:35 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
#include <QGestureRecognizer>
|
|
|
|
#include <QGesture>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QAction>
|
2014-02-04 13:35:42 +00:00
|
|
|
|
|
|
|
namespace Gestures {
|
|
|
|
|
|
|
|
enum GestureResult {
|
|
|
|
NOT_HANLDED,
|
|
|
|
SWIPE_LEFT,
|
|
|
|
SWIPE_RIGHT,
|
|
|
|
SWIPE_UP,
|
|
|
|
SWIPE_DOWN,
|
|
|
|
ZOOM_IN,
|
|
|
|
ZOOM_OUT
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Qt::GestureType GDPinchGestureType;
|
|
|
|
extern Qt::GestureType GDSwipeGestureType;
|
|
|
|
|
|
|
|
void registerRecognizers();
|
|
|
|
|
|
|
|
void unregisterRecognizers();
|
|
|
|
|
|
|
|
bool isFewTouchPointsPresented();
|
|
|
|
|
|
|
|
class GDPinchGestureRecognizer;
|
|
|
|
class GDPinchGesture: public QGesture
|
|
|
|
{
|
|
|
|
public:
|
2019-04-22 16:50:06 +00:00
|
|
|
GDPinchGesture( QObject * parent );
|
2014-02-04 13:35:42 +00:00
|
|
|
|
|
|
|
bool isScaleChanged() const
|
|
|
|
{
|
|
|
|
return scaleChanged;
|
|
|
|
}
|
|
|
|
QPointF const & getCenterPoint() const
|
|
|
|
{
|
|
|
|
return centerPoint;
|
|
|
|
}
|
|
|
|
qreal getTotalScaleFactor() const
|
|
|
|
{
|
|
|
|
return totalScaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QPointF startCenterPoint;
|
|
|
|
QPointF lastCenterPoint;
|
|
|
|
QPointF centerPoint;
|
|
|
|
|
|
|
|
qreal lastScaleFactor;
|
|
|
|
qreal scaleFactor;
|
|
|
|
qreal totalScaleFactor;
|
|
|
|
|
|
|
|
bool isNewSequence;
|
|
|
|
QPointF startPosition[ 2 ];
|
|
|
|
bool scaleChanged;
|
|
|
|
|
|
|
|
friend class GDPinchGestureRecognizer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GDSwipeGestureRecognizer;
|
|
|
|
class GDSwipeGesture: public QGesture
|
|
|
|
{
|
|
|
|
public:
|
2019-04-22 16:50:06 +00:00
|
|
|
GDSwipeGesture( QObject * parent );
|
2014-02-04 13:35:42 +00:00
|
|
|
QSwipeGesture::SwipeDirection getHorizDirection() const
|
|
|
|
{
|
|
|
|
return horizDirection;
|
|
|
|
}
|
|
|
|
QSwipeGesture::SwipeDirection getVertDirection() const
|
|
|
|
{
|
|
|
|
return vertDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QSwipeGesture::SwipeDirection vertDirection;
|
|
|
|
QSwipeGesture::SwipeDirection horizDirection;
|
|
|
|
QPoint lastPositions[ 2 ];
|
|
|
|
bool started;
|
|
|
|
|
|
|
|
friend class GDSwipeGestureRecognizer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GDPinchGestureRecognizer: public QGestureRecognizer
|
|
|
|
{
|
|
|
|
public:
|
2014-05-11 15:53:39 +00:00
|
|
|
static const qreal OUT_SCALE_LIMIT;
|
|
|
|
static const qreal IN_SCALE_LIMIT;
|
2014-02-04 13:35:42 +00:00
|
|
|
|
|
|
|
GDPinchGestureRecognizer() {}
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2014-02-04 13:35:42 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
virtual QGesture * create( QObject * pTarget );
|
|
|
|
virtual QGestureRecognizer::Result recognize( QGesture * pGesture, QObject * pWatched, QEvent * pEvent );
|
|
|
|
void reset( QGesture * pGesture );
|
|
|
|
};
|
|
|
|
|
|
|
|
class GDSwipeGestureRecognizer: public QGestureRecognizer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GDSwipeGestureRecognizer() {}
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2014-02-04 13:35:42 +00:00
|
|
|
private:
|
2014-02-10 14:49:44 +00:00
|
|
|
static const int MOVE_X_TRESHOLD = 100;
|
|
|
|
static const int MOVE_Y_TRESHOLD = 50;
|
2014-02-04 13:35:42 +00:00
|
|
|
|
|
|
|
virtual QGesture * create( QObject * pTarget );
|
|
|
|
virtual QGestureRecognizer::Result recognize( QGesture * pGesture, QObject * pWatched, QEvent * pEvent );
|
|
|
|
void reset( QGesture * pGesture );
|
|
|
|
qreal computeAngle( int dx, int dy );
|
|
|
|
};
|
|
|
|
|
|
|
|
bool handleGestureEvent( QObject * obj, QEvent * event, GestureResult & result, QPoint & point );
|
|
|
|
|
|
|
|
} // namespace Gestures
|
|
|
|
|
2024-03-20 03:11:35 +00:00
|
|
|
|
|
|
|
#endif
|