diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-03-19 16:02:15 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-05-11 14:51:41 (GMT) |
commit | c24887401cf7e22825263e8b50d37ef704a2f90d (patch) | |
tree | f6ef4169d7c730d95012aa2b587c85222172d74b | |
parent | 05767badad6408438c6dcffa29318f681522a55a (diff) | |
download | Qt-c24887401cf7e22825263e8b50d37ef704a2f90d.zip Qt-c24887401cf7e22825263e8b50d37ef704a2f90d.tar.gz Qt-c24887401cf7e22825263e8b50d37ef704a2f90d.tar.bz2 |
Gesture recognizer don;t create new QGesture object every time
anymore, but just fill data on a single qgesture object.
-rw-r--r-- | src/gui/kernel/qgesture.cpp | 61 | ||||
-rw-r--r-- | src/gui/kernel/qgesture.h | 19 | ||||
-rw-r--r-- | src/gui/kernel/qgesture_p.h | 7 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager.cpp | 3 | ||||
-rw-r--r-- | src/gui/kernel/qgesturestandardrecognizers.cpp | 52 | ||||
-rw-r--r-- | src/gui/kernel/qgesturestandardrecognizers_p.h | 4 |
6 files changed, 106 insertions, 40 deletions
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index 76101f2..ccda805 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -71,16 +71,6 @@ QString qt_getStandardGestureTypeName(Qt::GestureType type); \sa QGestureEvent, QGestureRecognizer */ -/*! \fn QString QGesture::gestureType() const - - Returns the type of the gesture. -*/ - -/*! \fn Qt::GestureState QGesture::state() const - - Returns the current state of the gesture. -*/ - /*! Creates a new gesture object of type \a type in a \a state and marks it as a child of \a parent. @@ -89,8 +79,11 @@ QString qt_getStandardGestureTypeName(Qt::GestureType type); QGestureRecognizer classes. */ QGesture::QGesture(QObject *parent, const QString &type, Qt::GestureState state) - : QObject(*new QGesturePrivate, parent), gestureType_(type), gestureState_(state) + : QObject(*new QGesturePrivate, parent) { + Q_D(QGesture); + d->type = type; + d->state = state; } /*! @@ -112,17 +105,23 @@ 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, uint duration, Qt::GestureState state) - : QObject(*new QGesturePrivate, parent), gestureType_(type), gestureState_(state) + : QObject(*new QGesturePrivate, parent) { - d_func()->init(startPos, lastPos, pos, rect, hotSpot, startTime, duration); + Q_D(QGesture); + d->type = type; + d->state = state; + d->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) + : QObject(dd, parent) { + Q_D(QGesture); + d->type = type; + d->state = state; } /*! @@ -133,6 +132,23 @@ QGesture::~QGesture() } /*! + Returns the type of the gesture. +*/ +QString QGesture::gestureType() const +{ + return d_func()->type; +} + + +/*! + Returns the current state of the gesture. +*/ +Qt::GestureState QGesture::state() const +{ + return d_func()->state; +} + +/*! Translates the internal gesture properties that represent coordinates by \a offset. @@ -231,6 +247,19 @@ QPoint QGesture::pos() const properties. */ +/*! \internal +*/ +QPanningGesture::QPanningGesture(QObject *parent) + : QGesture(parent, qt_getStandardGestureTypeName(Qt::PanGesture)) +{ +} + +/*! \internal +*/ +QPanningGesture::~QPanningGesture() +{ +} + /*! \property QPanningGesture::lastDirection @@ -238,7 +267,7 @@ QPoint QGesture::pos() const */ Qt::DirectionType QPanningGesture::lastDirection() const { - return qVariantValue<Qt::DirectionType>(property("lastDirection")); + return d_func()->lastDirection; } /*! @@ -248,7 +277,7 @@ Qt::DirectionType QPanningGesture::lastDirection() const */ Qt::DirectionType QPanningGesture::direction() const { - return qVariantValue<Qt::DirectionType>(property("direction")); + return d_func()->direction; } QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h index d4b2165..9f58f7a 100644 --- a/src/gui/kernel/qgesture.h +++ b/src/gui/kernel/qgesture.h @@ -61,6 +61,9 @@ class Q_GUI_EXPORT QGesture : public QObject Q_OBJECT Q_DECLARE_PRIVATE(QGesture) + Q_PROPERTY(QString gestureType READ gestureType) + Q_PROPERTY(Qt::GestureState state READ state) + Q_PROPERTY(QRect rect READ rect) Q_PROPERTY(QPoint hotSpot READ hotSpot) Q_PROPERTY(QDateTime startTime READ startTime) @@ -79,8 +82,8 @@ public: uint duration, Qt::GestureState state); virtual ~QGesture(); - inline QString gestureType() const { return gestureType_; } - inline Qt::GestureState state() const { return gestureState_; } + QString gestureType() const; + Qt::GestureState state() const; QRect rect() const; QPoint hotSpot() const; @@ -96,8 +99,9 @@ protected: virtual void translate(const QPoint &offset); private: - QString gestureType_; - Qt::GestureState gestureState_; + friend class QGestureRecognizerPan; + friend class QDoubleTapGestureRecognizer; + friend class QTapAndHoldGestureRecognizer; }; class QPanningGesturePrivate; @@ -112,9 +116,16 @@ class Q_GUI_EXPORT QPanningGesture : public QGesture public: Qt::DirectionType lastDirection() const; Qt::DirectionType direction() const; + +private: + QPanningGesture(QObject *parent = 0); + ~QPanningGesture(); + + friend class QGestureRecognizerPan; }; Q_DECLARE_METATYPE(Qt::DirectionType) +Q_DECLARE_METATYPE(Qt::GestureState) QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 24350d4..cf4e760 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -82,6 +82,9 @@ public: this->pos = pos; } + QString type; + Qt::GestureState state; + QRect rect; QPoint hotSpot; QDateTime startTime; @@ -94,6 +97,10 @@ public: class QPanningGesturePrivate : public QGesturePrivate { Q_DECLARE_PUBLIC(QPanningGesture) + +public: + Qt::DirectionType lastDirection; + Qt::DirectionType direction; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 753d712..97f73b2 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -67,6 +67,9 @@ static const unsigned int maximumGestureRecognitionTimeout = 2000; QGestureManager::QGestureManager(QObject *parent) : QObject(parent), targetWidget(0), state(NotGesture) { + qRegisterMetaType<Qt::DirectionType>(); + qRegisterMetaType<Qt::GestureState>(); + recognizers << new QDoubleTapGestureRecognizer(); recognizers << new QTapAndHoldGestureRecognizer(); recognizers << new QGestureRecognizerPan(); diff --git a/src/gui/kernel/qgesturestandardrecognizers.cpp b/src/gui/kernel/qgesturestandardrecognizers.cpp index 82a0a6f..0fa5201 100644 --- a/src/gui/kernel/qgesturestandardrecognizers.cpp +++ b/src/gui/kernel/qgesturestandardrecognizers.cpp @@ -79,13 +79,12 @@ QString qt_getStandardGestureTypeName(Qt::GestureType gestureType) // QGestureRecognizerPan::QGestureRecognizerPan() - : QGestureRecognizer(QString()), mousePressed(false), gestureFinished(false), + : QGestureRecognizer(QString()), + mousePressed(false), gestureFinished(false), lastDirection(Qt::NoDirection), currentDirection(Qt::NoDirection) { Q_D(QGestureRecognizer); d->gestureType = Qt::PanGesture; - - qRegisterMetaType<Qt::DirectionType>(); } QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *event) @@ -145,14 +144,16 @@ QGesture* QGestureRecognizerPan::getGesture() { if (currentDirection == Qt::NoDirection) return 0; - 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)); + QPanningGesturePrivate *d = gesture.d_func(); + d->startPos = pressedPos; + d->lastPos = lastPos; + d->pos = currentPos; + d->hotSpot = pressedPos; + d->state = gestureFinished ? Qt::GestureFinished : Qt::GestureStarted; + d->lastDirection = lastDirection; + d->direction = currentDirection; - return g; + return &gesture; } void QGestureRecognizerPan::reset() @@ -177,7 +178,8 @@ void QGestureRecognizerPan::internalReset() // QDoubleTapGestureRecognizer // QDoubleTapGestureRecognizer::QDoubleTapGestureRecognizer() - : QGestureRecognizer(QString()) + : QGestureRecognizer(QString()), + gesture(0, qt_getStandardGestureTypeName(Qt::DoubleTapGesture)) { Q_D(QGestureRecognizer); d->gestureType = Qt::DoubleTapGesture; @@ -207,9 +209,13 @@ QGestureRecognizer::Result QDoubleTapGestureRecognizer::filterEvent(const QEvent QGesture* QDoubleTapGestureRecognizer::getGesture() { - return new QGesture(this, qt_getStandardGestureTypeName(Qt::DoubleTapGesture), - pressedPosition, pressedPosition, pressedPosition, - QRect(), pressedPosition, QDateTime(), 0, Qt::GestureFinished); + QGesturePrivate *d = gesture.d_func(); + d->startPos = pressedPosition; + d->lastPos = pressedPosition; + d->pos = pressedPosition; + d->hotSpot = pressedPosition; + d->state = Qt::GestureFinished; + return &gesture; } void QDoubleTapGestureRecognizer::reset() @@ -224,7 +230,8 @@ const int QTapAndHoldGestureRecognizer::iterationCount = 40; const int QTapAndHoldGestureRecognizer::iterationTimeout = 50; QTapAndHoldGestureRecognizer::QTapAndHoldGestureRecognizer() - : QGestureRecognizer(QString()), iteration(0) + : QGestureRecognizer(QString()), iteration(0), + gesture(0, qt_getStandardGestureTypeName(Qt::TapAndHoldGesture)) { Q_D(QGestureRecognizer); d->gestureType = Qt::TapAndHoldGesture; @@ -266,11 +273,16 @@ void QTapAndHoldGestureRecognizer::timerEvent(QTimerEvent *event) QGesture* QTapAndHoldGestureRecognizer::getGesture() { - return new QGesture(this, qt_getStandardGestureTypeName(Qt::TapAndHoldGesture), - pressedPosition, pressedPosition, pressedPosition, - QRect(), pressedPosition, QDateTime(), 0, - iteration >= QTapAndHoldGestureRecognizer::iterationCount ? - Qt::GestureFinished : Qt::GestureStarted); + QGesturePrivate *d = gesture.d_func(); + d->startPos = pressedPosition; + d->lastPos = pressedPosition; + d->pos = pressedPosition; + d->hotSpot = pressedPosition; + if (iteration >= QTapAndHoldGestureRecognizer::iterationCount) + d->state = Qt::GestureFinished; + else + d->state = Qt::GestureStarted; + return &gesture; } void QTapAndHoldGestureRecognizer::reset() diff --git a/src/gui/kernel/qgesturestandardrecognizers_p.h b/src/gui/kernel/qgesturestandardrecognizers_p.h index 8f1361f..5163bd6 100644 --- a/src/gui/kernel/qgesturestandardrecognizers_p.h +++ b/src/gui/kernel/qgesturestandardrecognizers_p.h @@ -75,6 +75,8 @@ public: private: void internalReset(); + QPanningGesture gesture; + QPoint pressedPos; QPoint lastPos; QPoint currentPos; @@ -97,6 +99,7 @@ public: void reset(); private: + QGesture gesture; QPoint pressedPosition; }; @@ -114,6 +117,7 @@ protected: void timerEvent(QTimerEvent *event); private: + QGesture gesture; QPoint pressedPosition; QBasicTimer timer; int iteration; |