qskinny/src/controls/QskGesture.h

149 lines
2.9 KiB
C
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_GESTURE_H
#define QSK_GESTURE_H
#include "QskGlobal.h"
2018-07-19 14:10:48 +02:00
#include <qmetatype.h>
2018-08-03 08:15:28 +02:00
#include <qpoint.h>
2017-07-21 18:21:34 +02:00
class QSK_EXPORT QskGesture
{
Q_GADGET
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
enum Type
{
NoType = -1,
Tap,
TapAndHold,
Pan,
#if 0
// TODO
Pinch,
#endif
Swipe,
CustomType = 16
};
Q_ENUM( Type )
enum State
{
NoGesture,
Started,
Updated,
Finished,
Canceled
};
Q_ENUM( State )
virtual ~QskGesture();
Type type() const { return m_type; }
void setState( State );
inline State state() const { return m_state; }
2018-08-03 08:15:28 +02:00
protected:
2017-07-21 18:21:34 +02:00
QskGesture( Type type );
const Type m_type;
State m_state;
};
class QSK_EXPORT QskTapGesture : public QskGesture
{
using Inherited = QskGesture;
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
QskTapGesture();
2018-07-31 17:32:25 +02:00
~QskTapGesture() override;
2017-07-21 18:21:34 +02:00
void setPosition( const QPointF& pos );
inline QPointF position() const { return m_position; }
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
QPointF m_position;
};
class QSK_EXPORT QskTapAndHoldGesture : public QskGesture
{
using Inherited = QskGesture;
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
QskTapAndHoldGesture();
2018-07-31 17:32:25 +02:00
~QskTapAndHoldGesture() override;
2017-07-21 18:21:34 +02:00
void setPosition( const QPointF& pos );
inline QPointF position() const { return m_position; }
void setTimeout( int msecs );
inline int timeout() const { return m_timeout; }
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
QPointF m_position;
int m_timeout;
};
2019-05-09 19:11:25 +02:00
class QSK_EXPORT QskPanGesture : public QskGesture
2017-07-21 18:21:34 +02:00
{
using Inherited = QskGesture;
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
QskPanGesture();
2018-07-31 17:32:25 +02:00
~QskPanGesture() override;
2017-07-21 18:21:34 +02:00
void setVelocity( qreal );
inline qreal velocity() const { return m_velocity; }
void setOrigin( const QPointF& );
inline const QPointF& origin() const { return m_origin; }
void setLastPosition( const QPointF& );
inline QPointF lastPosition() const { return m_lastPosition; }
void setPosition( const QPointF& );
inline const QPointF& position() const { return m_position; }
void setAngle( qreal degrees );
inline qreal angle() const { return m_angle; }
inline QPointF delta() const { return m_position - m_lastPosition; }
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
qreal m_angle;
qreal m_velocity;
QPointF m_origin;
QPointF m_lastPosition;
QPointF m_position;
};
2019-05-09 19:11:25 +02:00
class QSK_EXPORT QskSwipeGesture : public QskGesture
2017-07-21 18:21:34 +02:00
{
using Inherited = QskGesture;
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
QskSwipeGesture();
2018-07-31 17:32:25 +02:00
~QskSwipeGesture() override;
2017-07-21 18:21:34 +02:00
void setVelocity( qreal velocity );
inline qreal velocity() const { return m_velocity; }
void setAngle( qreal angle );
inline qreal angle() const;
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
qreal m_velocity;
qreal m_angle;
};
#endif