summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qapplication.cpp10
-rw-r--r--src/gui/kernel/qdirectionrecognizer.cpp34
-rw-r--r--src/gui/kernel/qdirectionrecognizer_p.h26
-rw-r--r--src/gui/kernel/qevent.cpp64
-rw-r--r--src/gui/kernel/qgesture.cpp124
-rw-r--r--src/gui/kernel/qgesture.h29
-rw-r--r--src/gui/kernel/qgesture_p.h4
-rw-r--r--src/gui/kernel/qgesturerecognizer.cpp79
-rw-r--r--src/gui/kernel/qgesturerecognizer.h54
-rw-r--r--src/gui/kernel/qgesturestandardrecognizers.cpp55
-rw-r--r--src/gui/kernel/qgesturestandardrecognizers_p.h4
-rw-r--r--src/gui/kernel/qwidget.cpp20
-rw-r--r--src/gui/kernel/qwidget.h2
13 files changed, 304 insertions, 201 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index efe1b13..bcc25b9 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -5088,11 +5088,21 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
return true;
}
+/*!
+ Adds custom gesture \a recognizer object.
+
+ \sa Qt::AA_EnableGestures, QGestureEvent
+*/
void QApplication::addGestureRecognizer(QGestureRecognizer *recognizer)
{
gestureManager()->addRecognizer(recognizer);
}
+/*!
+ Removes custom gesture \a recognizer object.
+
+ \sa Qt::AA_EnableGestures, QGestureEvent
+*/
void QApplication::removeGestureRecognizer(QGestureRecognizer *recognizer)
{
gestureManager()->removeRecognizer(recognizer);
diff --git a/src/gui/kernel/qdirectionrecognizer.cpp b/src/gui/kernel/qdirectionrecognizer.cpp
index 37b64e7..2896523 100644
--- a/src/gui/kernel/qdirectionrecognizer.cpp
+++ b/src/gui/kernel/qdirectionrecognizer.cpp
@@ -64,22 +64,22 @@ Direction QDirectionSimpleRecognizer::addPosition(const QPoint &pos)
}
int dx = pos.x() - lastPoint.x();
int dy = pos.y() - lastPoint.y();
- Direction::DirectionType direction = Direction::None;
+ Qt::DirectionType direction = Qt::NoDirection;
if (dx < 0) {
if (-1*dx >= SIZE/2)
- direction = Direction::Left;
+ direction = Qt::LeftDirection;
} else {
if (dx >= SIZE/2)
- direction = Direction::Right;
+ direction = Qt::RightDirection;
}
if (dy < 0) {
if (-1*dy >= SIZE/2)
- direction = Direction::Up;
+ direction = Qt::UpDirection;
} else {
if (dy >= SIZE/2)
- direction = Direction::Down;
+ direction = Qt::DownDirection;
}
- if (direction == Direction::None)
+ if (direction == Qt::NoDirection)
return Direction();
lastPoint = pos;
@@ -123,7 +123,7 @@ Direction QDirectionDiagonalRecognizer::addPosition(const QPoint &pos)
if (distance < SIZE/2)
return Direction();
- Direction::DirectionType direction = Direction::None;
+ Qt::DirectionType direction = Qt::NoDirection;
double angle = atan(1.0*qAbs(lastPoint.y() - pos.y())/qAbs(pos.x() - lastPoint.x())) * 180. / M_PI;
if (dx < 0 && dy <= 0) {
angle = 180 - angle;
@@ -135,25 +135,25 @@ Direction QDirectionDiagonalRecognizer::addPosition(const QPoint &pos)
if (angle < 0)
angle += 360;
if (angle <= 20)
- direction = Direction::Right;
+ direction = Qt::RightDirection;
else if (angle <= 65)
- direction = Direction::RightUp;
+ direction = Qt::RightUpDirection;
else if (angle <= 110)
- direction = Direction::Up;
+ direction = Qt::UpDirection;
else if (angle <= 155)
- direction = Direction::LeftUp;
+ direction = Qt::LeftUpDirection;
else if (angle <= 200)
- direction = Direction::Left;
+ direction = Qt::LeftDirection;
else if (angle <= 245)
- direction = Direction::LeftDown;
+ direction = Qt::LeftDownDirection;
else if (angle <= 290)
- direction = Direction::Down;
+ direction = Qt::DownDirection;
else if (angle <= 335)
- direction = Direction::RightDown;
+ direction = Qt::RightDownDirection;
else
- direction = Direction::Right;
+ direction = Qt::RightDirection;
- if (direction == Direction::None)
+ if (direction == Qt::NoDirection)
return Direction();
lastPoint = pos;
diff --git a/src/gui/kernel/qdirectionrecognizer_p.h b/src/gui/kernel/qdirectionrecognizer_p.h
index 6390990..ca3d1c1 100644
--- a/src/gui/kernel/qdirectionrecognizer_p.h
+++ b/src/gui/kernel/qdirectionrecognizer_p.h
@@ -60,32 +60,16 @@ QT_BEGIN_NAMESPACE
struct Direction
{
- enum DirectionType
- {
- None = 0,
- LeftDown = 1,
- DownLeft = LeftDown,
- Down = 2,
- RightDown = 3,
- DownRight = RightDown,
- Left = 4,
- Right = 6,
- LeftUp = 7,
- UpLeft = LeftUp,
- Up = 8,
- RightUp = 9,
- UpRight = RightUp
- };
- DirectionType direction;
+ Qt::DirectionType direction;
QPoint point;
- Direction(DirectionType dir, const QPoint &pt)
+ Direction(Qt::DirectionType dir, const QPoint &pt)
: direction(dir), point(pt) { }
Direction()
- : direction(None) { }
+ : direction(Qt::NoDirection) { }
- inline bool isEmpty() const { return direction == None; }
- inline bool isNull() const { return direction == None; }
+ inline bool isEmpty() const { return direction == Qt::NoDirection; }
+ inline bool isNull() const { return direction == Qt::NoDirection; }
};
typedef QList<Direction> DirectionList;
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 5761939..3ce2517 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3519,42 +3519,19 @@ QMenubarUpdatedEvent::QMenubarUpdatedEvent(QMenuBar * const menuBar)
gesture recognition.
The QGestureEvent class contains a list of gestures that are being
- executed right now (QGestureEvent::gestureTypes()) and a list of
- gestures that are cancelled (the gesture might be cancelled
- because the window lost focus, or because of timeout, etc).
+ executed right now (\l{QGestureEvent::}{gestureTypes()}) and a
+ list of gestures that are cancelled (the gesture might be
+ cancelled because the window lost focus, or because of timeout,
+ etc).
\sa QGesture
*/
-/*! \fn bool QGestureEvent::contains(const Qt::GestureType &type) const
-
- Checks if the gesture event contains gesture of specific \a type.
-*/
-
-/*! \fn QList<Qt::GestureType> QGestureEvent::gestureTypes() const
-
- Returns a list of gesture names that the event contains.
-*/
-
-/*! \fn const QGesture* QGestureEvent::gesture(const Qt::GestureType &type) const
-
- Returns extended information about a gesture of specific \a type.
-*/
-
-/*! \fn QList<QSharedPointer<QGesture> > QGestureEvent::gestures() const
-
- Returns extended information about all triggered gestures.
-*/
-
-/*! \fn QSet<Qt::GestureType> QGestureEvent::cancelledGestures() const
-
- Returns a set of gesture names that used to be executed, but got
- cancelled (i.e. they were not finished properly).
+/*!
+ Creates new QGestureEvent containing a list of \a gestures that
+ are being executed and a list of gesture that were cancelled (\a
+ cancelledGestures).
*/
-
-
-
-
QGestureEvent::QGestureEvent(const QList<QGesture*> &gestures,
const QSet<QString> &cancelledGestures)
: QEvent(QEvent::Gesture), m_cancelledGestures(cancelledGestures)
@@ -3570,40 +3547,65 @@ QGestureEvent::QGestureEvent(const QGestureEvent &event, const QPoint &offset)
//### use offset!
}
+/*!
+ Destroys the QGestureEvent object.
+*/
QGestureEvent::~QGestureEvent()
{
}
+/*!
+ Checks if the gesture event contains gesture of specific \a type.
+*/
bool QGestureEvent::contains(Qt::GestureType type) const
{
return contains(qt_getStandardGestureTypeName(type));
}
+/*!
+ Checks if the gesture event contains gesture of specific \a type.
+*/
bool QGestureEvent::contains(const QString &type) const
{
return gesture(type) != 0;
}
+/*!
+ Returns a list of gesture names that this event contains.
+*/
QList<QString> QGestureEvent::gestureTypes() const
{
return m_gestures.keys();
}
+/*!
+ Returns extended information about a gesture of specific \a type.
+*/
const QGesture* QGestureEvent::gesture(Qt::GestureType type) const
{
return gesture(qt_getStandardGestureTypeName(type));
}
+/*!
+ Returns extended information about a gesture of specific \a type.
+*/
const QGesture* QGestureEvent::gesture(const QString &type) const
{
return m_gestures.value(type, QSharedPointer<QGesture>()).data();
}
+/*!
+ Returns extended information about all gestures in the event.
+*/
QList<QSharedPointer<QGesture> > QGestureEvent::gestures() const
{
return m_gestures.values();
}
+/*!
+ Returns a set of gesture names that used to be executed, but were
+ cancelled (i.e. they were not finished properly).
+*/
QSet<QString> QGestureEvent::cancelledGestures() const
{
return m_cancelledGestures;
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp
index b2d357c..b2bb859 100644
--- a/src/gui/kernel/qgesture.cpp
+++ b/src/gui/kernel/qgesture.cpp
@@ -46,11 +46,58 @@ QT_BEGIN_NAMESPACE
QString qt_getStandardGestureTypeName(Qt::GestureType type);
+/*!
+ \class QGesture
+
+ \brief The QGesture class represents a gesture, containing all
+ properties that describe a gesture.
+
+ The widget receives a QGestureEvent with a list of QGesture
+ objects that represent gestures that are occuring on it. The class
+ has a list of properties that can be queried by the user to get
+ some gesture-specific arguments (i.e. position of the tap in the
+ DoubleTap gesture).
+
+ When creating custom gesture recognizers, they might add new
+ properties to the gesture object, or custom gesture developers
+ might subclass the QGesture objects to provide some extended
+ information. However, if the gesture developer wants to add a new
+ property to the gesture object that describe coordinate (like a
+ QPoint or QRect), it is required to subclass the QGesture and
+ re-implement the \l{QGesture::}{translate} function to make sure
+ the coordinates are translated properly when the gesture event is
+ propagated to parent widgets.
+
+ \sa QGestureEvent, QGestureRecognizer
+*/
+
+/*!
+ Creates a new gesture object of type \a type in a \a state and
+ marks it as a child of \a parent.
+
+ Usually QGesture objects should only be contructed by the
+ QGestureRecognizer classes.
+*/
QGesture::QGesture(QObject *parent, const QString &type, Qt::GestureState state)
: QObject(*new QGesturePrivate, parent), gestureType_(type), gestureState_(state)
{
}
+/*!
+ Creates a new gesture object of type \a type in a \a state and
+ marks it as a child of \a parent.
+
+ This constructor also fills some basic information about the
+ gesture like a \a startPos which describes the start point of the
+ gesture, \a lastPos - last point where the gesture happened, \a
+ pos - a current point, \a rect - a bounding rect of the gesture,
+ \a hotSpot - a center point of the gesture, \a startTime - a time
+ when the gesture has started, \a duration - how long the gesture
+ is going on.
+
+ Usually QGesture objects should only be contructed by the
+ QGestureRecognizer classes.
+*/
QGesture::QGesture(QObject *parent, const QString &type, const QPoint &startPos,
const QPoint &lastPos, const QPoint &pos, const QRect &rect,
const QPoint &hotSpot, const QDateTime &startTime,
@@ -60,51 +107,105 @@ QGesture::QGesture(QObject *parent, const QString &type, const QPoint &startPos,
d_func()->init(startPos, lastPos, pos, rect, hotSpot, startTime, duration);
}
+/*! \internal
+*/
QGesture::QGesture(QGesturePrivate &dd, QObject *parent, const QString &type,
Qt::GestureState state)
: QObject(dd, parent), gestureType_(type), gestureState_(state)
{
}
+/*!
+ Destroys the gesture object.
+*/
QGesture::~QGesture()
{
}
+/*!
+ Translates the internal gesture properties that represent
+ coordinates by \a offset.
+
+ Custom gesture recognizer developer have to re-implement this
+ function if they want to store custom properties that represent
+ coordinates.
+*/
+void QGesture::translate(const QPoint &offset)
+{
+ Q_D(QGesture);
+ d->rect.translate(offset);
+ d->hotSpot += offset;
+ d->startPos += offset;
+ d->lastPos += offset;
+ d->pos += offset;
+}
+
+/*!
+ Returns a bounding rect of a gesture.
+*/
QRect QGesture::rect() const
{
return d_func()->rect;
}
+/*!
+ Returns a center point of a gesture.
+*/
QPoint QGesture::hotSpot() const
{
return d_func()->hotSpot;
}
+/*!
+ Returns a time when the gesture has started.
+*/
QDateTime QGesture::startTime() const
{
return d_func()->startTime;
}
+/*!
+ Returns a duration time of a gesture.
+*/
uint QGesture::duration() const
{
return d_func()->duration;
}
+/*!
+ Returns the start position of the pointer.
+*/
QPoint QGesture::startPos() const
{
return d_func()->startPos;
}
+/*!
+ Returns the last recorded position of the pointer.
+*/
QPoint QGesture::lastPos() const
{
return d_func()->lastPos;
}
+/*!
+ Returns the position of the pointer.
+*/
QPoint QGesture::pos() const
{
return d_func()->pos;
}
+/*!
+ \class QPannableGesture
+
+ \brief The QPannableGesture class represents a Pan gesture,
+ providing additional information related to panning.
+
+ This class is provided for convenience, panning direction
+ information is also contained in the QGesture object in it's
+ properties.
+*/
QPannableGesture::QPannableGesture(QObject *parent, const QPoint &startPos,
const QPoint &lastPos, const QPoint &pos, const QRect &rect,
const QPoint &hotSpot, const QDateTime &startTime,
@@ -114,24 +215,31 @@ QPannableGesture::QPannableGesture(QObject *parent, const QPoint &startPos,
{
Q_D(QPannableGesture);
d->init(startPos, lastPos, pos, rect, hotSpot, startTime, duration);
- d->lastDirection = QPannableGesture::None;
- d->direction = QPannableGesture::None;
+ setProperty("lastDirection", QVariant::fromValue(Qt::NoDirection));
+ setProperty("direction", QVariant::fromValue(Qt::NoDirection));
}
+/*!
+ Destroys the QPannableGesture object.
+*/
QPannableGesture::~QPannableGesture()
{
}
-QPannableGesture::DirectionType QPannableGesture::lastDirection() const
+/*!
+ Returns the last recorded direction of panning.
+*/
+Qt::DirectionType QPannableGesture::lastDirection() const
{
- Q_D(const QPannableGesture);
- return d->lastDirection;
+ return qVariantValue<Qt::DirectionType>(property("lastDirection"));
}
-QPannableGesture::DirectionType QPannableGesture::direction() const
+/*!
+ Returns the current direction of panning.
+*/
+Qt::DirectionType QPannableGesture::direction() const
{
- Q_D(const QPannableGesture);
- return d->direction;
+ return qVariantValue<Qt::DirectionType>(property("direction"));
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h
index 8bd312b..b2999d7 100644
--- a/src/gui/kernel/qgesture.h
+++ b/src/gui/kernel/qgesture.h
@@ -48,6 +48,7 @@
#include "qpoint.h"
#include "qrect.h"
#include "qsharedpointer.h"
+#include "qmetatype.h"
QT_BEGIN_HEADER
@@ -93,7 +94,7 @@ public:
protected:
QGesture(QGesturePrivate &dd, QObject *parent, const QString &type, Qt::GestureState state);
- //### virtual void translateCoordinates(const QPoint &offset);
+ virtual void translate(const QPoint &offset);
private:
QString gestureType_;
@@ -107,36 +108,18 @@ class Q_GUI_EXPORT QPannableGesture : public QGesture
Q_DECLARE_PRIVATE(QPannableGesture)
public:
- enum DirectionType
- {
- None = 0,
- LeftDown = 1,
- DownLeft = LeftDown,
- Down = 2,
- RightDown = 3,
- DownRight = RightDown,
- Left = 4,
- Right = 6,
- LeftUp = 7,
- UpLeft = LeftUp,
- Up = 8,
- RightUp = 9,
- UpRight = RightUp
- };
-
-public:
QPannableGesture(QObject *parent, const QPoint &startPos,
const QPoint &lastPos, const QPoint &pos, const QRect &rect,
const QPoint &hotSpot, const QDateTime &startTime,
uint duration, Qt::GestureState state);
~QPannableGesture();
- DirectionType lastDirection() const;
- DirectionType direction() const;
-
- friend class QGestureRecognizerPan;
+ Qt::DirectionType lastDirection() const;
+ Qt::DirectionType direction() const;
};
+Q_DECLARE_METATYPE(Qt::DirectionType)
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h
index 8a76186..028a622 100644
--- a/src/gui/kernel/qgesture_p.h
+++ b/src/gui/kernel/qgesture_p.h
@@ -94,10 +94,6 @@ public:
class QPannableGesturePrivate : public QGesturePrivate
{
Q_DECLARE_PUBLIC(QPannableGesture)
-
-public:
- QPannableGesture::DirectionType lastDirection;
- QPannableGesture::DirectionType direction;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp
index 9a00138..7791ad7 100644
--- a/src/gui/kernel/qgesturerecognizer.cpp
+++ b/src/gui/kernel/qgesturerecognizer.cpp
@@ -49,17 +49,96 @@ QT_BEGIN_NAMESPACE
QString qt_getStandardGestureTypeName(Qt::GestureType gestureType);
+/*!
+ \class QGestureRecognizer
+
+ \brief The QGestureRecognizer class is the base class for
+ implementing custom gestures.
+
+ This is a base class, to create a custom gesture type, you should
+ subclass it and implement its pure virtual functions.
+
+ Usually gesture recognizer implements state machine, storing its
+ state internally in the recognizer object. The recognizer receives
+ input events through the \l{QGestureRecognizer::}{filterEvent()}
+ virtual function and decides whether the parsed event should
+ change the state of the recognizer - i.e. if the event starts or
+ ends a gesture or if it isn't related to gesture at all.
+*/
+
+/*!
+ \enum QGestureRecognizer::Result
+
+ This enum type defines the state of the gesture recognizer.
+
+ \value NotGesture Not a gesture.
+
+ \value GestureStarted The long-term gesture has started. When the
+ recognizer is in started state, a gesture event containing
+ QGesture objects returned by the
+ \l{QGestureRecognizer::}{getGesture()} will be sent to a widget.
+
+ \value GestureFinished A gesture has ended. The gesture event will
+ be sent to a widget.
+
+ \value MaybeGesture Gesture hasn't started yet, but it might start
+ soon after next events are received by the recognizer. That means
+ that gesture manager shouldn't reset() the internal state of the
+ gesture recognizer.
+*/
+
+/*! \fn QGestureRecognizer::Result QGestureRecognizer::filterEvent(const QEvent *event)
+
+ This is a pure virtual function that needs to be implemented in
+ subclasses.
+
+ Parses input \a event and returns the result, which specifies if
+ the event sequence is a gesture or not.
+*/
+
+/*! \fn QGesture* QGestureRecognizer::getGesture()
+
+ Returns a gesture object that will be send to the widget. This
+ function is called when the gesture recognizer changed its state
+ to QGestureRecognizer::GestureStarted or
+ QGestureRecognizer::GestureFinished.
+
+ The gesture object is owned by the recognizer itself.
+*/
+
+/*! \fn void QGestureRecognizer::reset()
+
+ Resets the internal state of the gesture recognizer.
+*/
+
+/*! \fn void QGestureRecognizer::stateChanged(QGestureRecognizer::Result result)
+
+ The gesture recognizer might emit the stateChanged() signal when
+ the gesture state changes asynchronously, i.e. without any event
+ being filtered through filterEvent().
+*/
+
QGestureRecognizerPrivate::QGestureRecognizerPrivate()
: gestureType(Qt::UnknownGesture)
{
}
+/*!
+ Creates a new gesture recognizer object that handles gestures of
+ the specific \a type.
+
+ \sa QApplication::addGestureRecognizer(),
+ QApplication::removeGestureRecognizer(),
+*/
QGestureRecognizer::QGestureRecognizer(const QString &type)
: QObject(*new QGestureRecognizerPrivate, 0)
{
d_func()->customGestureType = type;
}
+/*!
+ Returns the name of the gesture that is handled by the recognizer.
+*/
QString QGestureRecognizer::gestureType() const
{
Q_D(const QGestureRecognizer);
diff --git a/src/gui/kernel/qgesturerecognizer.h b/src/gui/kernel/qgesturerecognizer.h
index c0d4f5e..9ffdb0d 100644
--- a/src/gui/kernel/qgesturerecognizer.h
+++ b/src/gui/kernel/qgesturerecognizer.h
@@ -48,58 +48,6 @@
QT_BEGIN_NAMESPACE
-/*!
- \class QGestureRecognizer
-
- \brief The base class for implementing custom gestures.
-
- This is a base class, to create a custom gesture type, you should
- subclass it and implement pure virtual functions.
-
- Usually gesture recognizer implements state machine, storing its
- state internally in the recognizer object. The recognizer receives
- input events through the QGestureRecognizer::filterEvent() virtual
- function and decides whether the parsed event should change the
- state of the recognizer - i.e. if the event starts or ends a
- gesture or if it isn't related to gesture at all.
-*/
-
-/*! \fn QString gestureType() const
-
- Returns the name of the gesture that is handled by the recognizer.
-*/
-
-/*! \fn Result filterEvent(const QEvent *event)
-
- This is a pure virtual function that need to be implemented in
- subclasses.
-
- Parses input \a events and returns the result, saying if the event
- sequence is a gesture or not.
-*/
-
-/*! \fn QGesture* getGesture()
-
- Creates a new gesture object that will be send to the widget. This
- function is called when the gesture recognizer returned a
- QGestureRecognizer::GestureStarted or
- QGestureRecognizer::GestureFinished state.
-
- Created gesture object is owned by the caller.
- */
-
-/*! \fn void reset()
-
- Resets the internal state of the gesture recognizer.
-*/
-
-/*! \fn void stateChanged(QGestureRecognizer::Result result)
-
- The gesture recognizer might emit the signal when the gesture
- state changes asynchronously, i.e. without any event being
- received.
-*/
-
class QGesture;
class QGestureRecognizerPrivate;
class Q_GUI_EXPORT QGestureRecognizer : public QObject
@@ -120,7 +68,7 @@ public:
QString gestureType() const;
- virtual Result filterEvent(const QEvent* event) = 0;
+ virtual QGestureRecognizer::Result filterEvent(const QEvent* event) = 0;
virtual QGesture* getGesture() = 0;
virtual void reset() = 0;
diff --git a/src/gui/kernel/qgesturestandardrecognizers.cpp b/src/gui/kernel/qgesturestandardrecognizers.cpp
index 718bdfd..82a0a6f 100644
--- a/src/gui/kernel/qgesturestandardrecognizers.cpp
+++ b/src/gui/kernel/qgesturestandardrecognizers.cpp
@@ -80,17 +80,19 @@ QString qt_getStandardGestureTypeName(Qt::GestureType gestureType)
QGestureRecognizerPan::QGestureRecognizerPan()
: QGestureRecognizer(QString()), mousePressed(false), gestureFinished(false),
- lastDirection(Direction::None), currentDirection(Direction::None)
+ lastDirection(Qt::NoDirection), currentDirection(Qt::NoDirection)
{
Q_D(QGestureRecognizer);
d->gestureType = Qt::PanGesture;
+
+ qRegisterMetaType<Qt::DirectionType>();
}
QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress) {
const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
- if (currentDirection != Direction::None) {
+ if (currentDirection != Qt::NoDirection) {
DEBUG() << "Pan: MouseButtonPress: fail. another press during pan";
reset();
return QGestureRecognizer::NotGesture;
@@ -100,7 +102,7 @@ QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *even
pressedPos = lastPos = currentPos = ev->pos();
return QGestureRecognizer::MaybeGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
- if (mousePressed && currentDirection != Direction::None) {
+ if (mousePressed && currentDirection != Qt::NoDirection) {
DEBUG() << "Pan: MouseButtonRelease: pan detected";
gestureFinished = true;
const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
@@ -117,19 +119,19 @@ QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *even
const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
lastPos = currentPos;
currentPos = ev->pos();
- Direction::DirectionType direction =
+ Qt::DirectionType direction =
simpleRecognizer.addPosition(ev->pos()).direction;
DEBUG() << "Pan: MouseMove: simplerecognizer result = " << direction;
QGestureRecognizer::Result result = QGestureRecognizer::NotGesture;
- if (currentDirection == Direction::None) {
- if (direction == Direction::None)
+ if (currentDirection == Qt::NoDirection) {
+ if (direction == Qt::NoDirection)
result = QGestureRecognizer::MaybeGesture;
else
result = QGestureRecognizer::GestureStarted;
} else {
result = QGestureRecognizer::GestureStarted;
}
- if (direction != Direction::None) {
+ if (direction != Qt::NoDirection) {
if (currentDirection != direction)
lastDirection = currentDirection;
currentDirection = direction;
@@ -139,37 +141,16 @@ QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *even
return QGestureRecognizer::NotGesture;
}
-static inline QPannableGesture::DirectionType convertPanningDirection(const Direction::DirectionType direction)
-{
- switch (direction) {
- case Direction::Left:
- return QPannableGesture::Left;
- case Direction::Right:
- return QPannableGesture::Right;
- case Direction::Up:
- return QPannableGesture::Up;
- case Direction::Down:
- return QPannableGesture::Down;
- default:
- break;
- }
- return QPannableGesture::None;
-}
-
QGesture* QGestureRecognizerPan::getGesture()
{
- QPannableGesture::DirectionType dir = convertPanningDirection(currentDirection);
- QPannableGesture::DirectionType lastDir = convertPanningDirection(lastDirection);
- if (dir == QPannableGesture::None)
+ if (currentDirection == Qt::NoDirection)
return 0;
- QPannableGesture *g =
- new QPannableGesture(this,
- pressedPos, lastPos, currentPos,
- QRect(), pressedPos, QDateTime(), 0,
- gestureFinished ? Qt::GestureFinished : Qt::GestureStarted);
- QPannableGesturePrivate *d = g->d_func();
- d->lastDirection = lastDir;
- d->direction = dir;
+ QGesture *g = new QGesture(this, qt_getStandardGestureTypeName(Qt::PanGesture),
+ pressedPos, lastPos, currentPos,
+ QRect(), pressedPos, QDateTime(), 0,
+ gestureFinished ? Qt::GestureFinished : Qt::GestureStarted);
+ g->setProperty("lastDirection", QVariant::fromValue(lastDirection));
+ g->setProperty("direction", QVariant::fromValue(currentDirection));
return g;
}
@@ -177,8 +158,8 @@ QGesture* QGestureRecognizerPan::getGesture()
void QGestureRecognizerPan::reset()
{
mousePressed = false;
- lastDirection = Direction::None;
- currentDirection = Direction::None;
+ lastDirection = Qt::NoDirection;
+ currentDirection = Qt::NoDirection;
gestureFinished = false;
diagonalRecognizer.reset();
simpleRecognizer.reset();
diff --git a/src/gui/kernel/qgesturestandardrecognizers_p.h b/src/gui/kernel/qgesturestandardrecognizers_p.h
index 75a206a..8f1361f 100644
--- a/src/gui/kernel/qgesturestandardrecognizers_p.h
+++ b/src/gui/kernel/qgesturestandardrecognizers_p.h
@@ -80,8 +80,8 @@ private:
QPoint currentPos;
bool mousePressed;
bool gestureFinished;
- Direction::DirectionType lastDirection;
- Direction::DirectionType currentDirection;
+ Qt::DirectionType lastDirection;
+ Qt::DirectionType currentDirection;
QDirectionDiagonalRecognizer diagonalRecognizer;
QDirectionSimpleRecognizer simpleRecognizer;
};
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 2f794f4..d37f360 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -11031,8 +11031,9 @@ QWindowSurface *QWidget::windowSurface() const
Subscribes the widget to the specified \a gesture type.
Returns the id of the gesture.
-*/
+ \sa grabGesture(), releaseGesture(), setGestureEnabled()
+*/
int QWidget::grabGesture(const QString &gesture)
{
Q_D(QWidget);
@@ -11053,16 +11054,19 @@ int QWidgetPrivate::grabGesture(int id)
Subscribes the widget to the specified \a gesture type.
Returns the id of the gesture.
-*/
+ \sa grabGesture(), releaseGesture(), setGestureEnabled()
+*/
int QWidget::grabGesture(Qt::GestureType gesture)
{
return grabGesture(qt_getStandardGestureTypeName(gesture));
}
/*!
- Unsubscribes the widget from a gesture, which is specified by its
- \a id.
+ Unsubscribes the widget from a gesture, which is specified by the
+ \a gestureId.
+
+ \sa grabGesture(),setGestureEnabled()
*/
void QWidget::releaseGesture(int gestureId)
{
@@ -11075,6 +11079,14 @@ void QWidget::releaseGesture(int gestureId)
}
}
+/*!
+ If \a enable is true, the gesture with the given \a gestureId is
+ enabled; otherwise the gesture is disabled.
+
+ The id of the gesture is returned by the grabGesture().
+
+ \sa grabGesture(), releaseGesture()
+*/
void setGestureEnabled(int gestureId, bool enable)
{
//###
diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h
index a76c50a..6324782 100644
--- a/src/gui/kernel/qwidget.h
+++ b/src/gui/kernel/qwidget.h
@@ -616,7 +616,7 @@ public:
int grabGesture(const QString &gesture);
int grabGesture(Qt::GestureType gesture);
void releaseGesture(int gestureId);
- void setGestureEnabled(int gestureId, bool enable);
+ void setGestureEnabled(int gestureId, bool enable = true);
Q_SIGNALS:
void customContextMenuRequested(const QPoint &pos);