summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qgesture.cpp
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-08-05 14:25:08 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-08-06 09:56:44 (GMT)
commit1a97230e908193c9a260ae68635301c0e9f9f8de (patch)
tree21480e205039bb9ff3095609c0f13218027d13e1 /src/gui/kernel/qgesture.cpp
parentd90f1e4ff7a077daf59f5f035cf6744fe732f843 (diff)
downloadQt-1a97230e908193c9a260ae68635301c0e9f9f8de.zip
Qt-1a97230e908193c9a260ae68635301c0e9f9f8de.tar.gz
Qt-1a97230e908193c9a260ae68635301c0e9f9f8de.tar.bz2
Changed setting state in a QGesture
Instead of having a protected setter for the state and forcing the application developer to emit signals manually (which leads to misunderstanding - i.e. if the started() signal should be emitted only once, or of the triggered() signal should be emitted before the finished() signal, etc). So I've added an protected updateState(state) function that sets the internal state and emits appropriate signals depending on the old and new states. Reviewed-by: Volker Hilsheimer Reviewed-by: Richard Moe Gustavsen
Diffstat (limited to 'src/gui/kernel/qgesture.cpp')
-rw-r--r--src/gui/kernel/qgesture.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp
index 8075ad9..38e8851 100644
--- a/src/gui/kernel/qgesture.cpp
+++ b/src/gui/kernel/qgesture.cpp
@@ -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