diff options
author | Janne Anttila <janne.anttila@digia.com> | 2009-08-11 06:11:20 (GMT) |
---|---|---|
committer | Janne Anttila <janne.anttila@digia.com> | 2009-08-11 06:11:20 (GMT) |
commit | 21acca0629c03e6c3cfdfb23441b2b0ac6313a59 (patch) | |
tree | f66d6468c639d536f40274dd8ced1267af981a67 /src/gui/kernel/qgesture.cpp | |
parent | 5b80fbad54eccfc79f38c4f24d6267834b23e742 (diff) | |
parent | 975b75bcda1570adc2aa0d0327c5445b25da1515 (diff) | |
download | Qt-21acca0629c03e6c3cfdfb23441b2b0ac6313a59.zip Qt-21acca0629c03e6c3cfdfb23441b2b0ac6313a59.tar.gz Qt-21acca0629c03e6c3cfdfb23441b2b0ac6313a59.tar.bz2 |
Merge branch 'master' of git@scm.dev.troll.no:qt/qt-s60-public
Diffstat (limited to 'src/gui/kernel/qgesture.cpp')
-rw-r--r-- | src/gui/kernel/qgesture.cpp | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index 32ac4f8..38e8851 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -97,7 +97,7 @@ private: This is a base class, to create a custom gesture type, you should subclass it and implement its pure virtual functions. - \sa QPanGesture, QTapAndHoldGesture + \sa QPanGesture */ /*! \fn bool QGesture::filterEvent(QEvent *event) @@ -197,11 +197,44 @@ Qt::GestureState QGesture::state() const } /*! - Sets this gesture's recognition state to \a state. + Sets this gesture's recognition state to \a state and emits appropriate + signals. + + This functions emits the signals according to the old state and the new + \a state, and it should be called after all the internal properties have been + initialized. + + \sa started, triggered, finished, cancelled */ -void QGesture::setState(Qt::GestureState state) +void QGesture::updateState(Qt::GestureState state) { - d_func()->state = state; + Q_D(QGesture); + if (d->state == state) { + if (state == Qt::GestureUpdated) + emit triggered(); + return; + } + const Qt::GestureState oldState = d->state; + d->state = state; + if (state != Qt::NoGesture && oldState > state) { + // comparing the state as ints: state should only be changed from + // started to (optionally) updated and to finished. + qWarning("QGesture::updateState: incorrect new state"); + return; + } + if (oldState == Qt::NoGesture) + emit started(); + if (state == Qt::GestureUpdated) + emit triggered(); + else if (state == Qt::GestureFinished) + emit finished(); + else if (state == Qt::NoGesture) + emit cancelled(); + + if (state == Qt::GestureFinished) { + // gesture is finished, so we reset the internal state. + d->state = Qt::NoGesture; + } } /*! @@ -238,14 +271,13 @@ QGraphicsItem* QGesture::graphicsItem() const Resets the internal state of the gesture. This function might be called by the filterEvent() implementation in a derived class, or by the user to - cancel a gesture. The base class implementation emits the cancelled() - signal if the state() of the gesture wasn't empty. + cancel a gesture. The base class implementation calls + updateState(Qt::NoGesture) which emits the cancelled() + signal if the state() of the gesture indicated it was active. */ void QGesture::reset() { - if (state() != Qt::NoGesture) - emit cancelled(); - setState(Qt::NoGesture); + updateState(Qt::NoGesture); } QT_END_NAMESPACE |