summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-02-26 16:18:33 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-05-11 13:38:55 (GMT)
commitaa4334b77702d99d4aa3da853dd66104eb4a8123 (patch)
tree2657a323cade43b263186719327a6ac16df9b43d
parenta3d8cfb1ee89e0600add864db53d67552820b95a (diff)
downloadQt-aa4334b77702d99d4aa3da853dd66104eb4a8123.zip
Qt-aa4334b77702d99d4aa3da853dd66104eb4a8123.tar.gz
Qt-aa4334b77702d99d4aa3da853dd66104eb4a8123.tar.bz2
Fixed lastDirection in the Pan gesture.
-rw-r--r--examples/gestures/graphicsview/main.cpp2
-rw-r--r--src/gui/kernel/qgesturestandardrecognizers.cpp48
-rw-r--r--src/gui/kernel/qgesturestandardrecognizers_p.h1
3 files changed, 33 insertions, 18 deletions
diff --git a/examples/gestures/graphicsview/main.cpp b/examples/gestures/graphicsview/main.cpp
index a0236ef..250da06 100644
--- a/examples/gestures/graphicsview/main.cpp
+++ b/examples/gestures/graphicsview/main.cpp
@@ -53,7 +53,7 @@ protected:
{
if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event);
- if (const QGesture *g = ge->gesture(Qt::Pan)) {
+ if (const QPannableGesture *g = dynamic_cast<const QPannableGesture*>(ge->gesture(Qt::Pan))) {
QPoint pt = g->pos() - g->lastPos();
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - pt.x());
verticalScrollBar()->setValue(verticalScrollBar()->value() - pt.y());
diff --git a/src/gui/kernel/qgesturestandardrecognizers.cpp b/src/gui/kernel/qgesturestandardrecognizers.cpp
index 3a2fa1d..504786a 100644
--- a/src/gui/kernel/qgesturestandardrecognizers.cpp
+++ b/src/gui/kernel/qgesturestandardrecognizers.cpp
@@ -178,7 +178,7 @@ void QGestureRecognizerMouseTwoButtons::clear()
QGestureRecognizerPan::QGestureRecognizerPan()
: QGestureRecognizer(Qt::Pan), mousePressed(false), gestureFinished(false),
- lastDirection(Direction::None)
+ lastDirection(Direction::None), currentDirection(Direction::None)
{
}
@@ -202,7 +202,7 @@ QGestureRecognizer::Result QGestureRecognizerPan::recognize(const QList<QEvent*>
for(int i = 0; i < events.count(); ++i) {
QMouseEvent *event = events.at(i);
if (event->type() == QEvent::MouseButtonPress) {
- if (lastDirection != Direction::None) {
+ if (currentDirection != Direction::None) {
DEBUG() << "Pan: MouseButtonPress: fail. another press during pan";
result = QGestureRecognizer::NotGesture;
reset();
@@ -213,7 +213,7 @@ QGestureRecognizer::Result QGestureRecognizerPan::recognize(const QList<QEvent*>
mousePressed = true;
pressedPos = lastPos = currentPos = event->pos();
} else if (event->type() == QEvent::MouseButtonRelease) {
- if (mousePressed && lastDirection != Direction::None) {
+ if (mousePressed && currentDirection != Direction::None) {
DEBUG() << "Pan: MouseButtonRelease: pan detected";
result = QGestureRecognizer::GestureFinished;
gestureFinished = true;
@@ -233,7 +233,7 @@ QGestureRecognizer::Result QGestureRecognizerPan::recognize(const QList<QEvent*>
Direction::DirectionType direction =
simpleRecognizer.addPosition(event->pos()).direction;
DEBUG() << "Pan: MouseMove: simplerecognizer result = " << direction;
- if (lastDirection == Direction::None) {
+ if (currentDirection == Direction::None) {
if (direction == Direction::None)
result = QGestureRecognizer::MaybeGesture;
else
@@ -241,32 +241,45 @@ QGestureRecognizer::Result QGestureRecognizerPan::recognize(const QList<QEvent*>
} else {
result = QGestureRecognizer::GestureStarted;
}
- if (direction != Direction::None)
- lastDirection = direction;
+ if (direction != Direction::None) {
+ if (currentDirection != direction)
+ lastDirection = currentDirection;
+ currentDirection = direction;
+ }
}
}
return result;
}
+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::makeEvent() const
{
- QPannableGesture::DirectionType dir = QPannableGesture::None;
- if (lastDirection == Direction::Left)
- dir = QPannableGesture::Left;
- else if (lastDirection == Direction::Right)
- dir = QPannableGesture::Right;
- else if (lastDirection == Direction::Up)
- dir = QPannableGesture::Up;
- else if (lastDirection == Direction::Down)
- dir = QPannableGesture::Down;
- else
+ QPannableGesture::DirectionType dir = convertPanningDirection(currentDirection);
+ QPannableGesture::DirectionType lastDir = convertPanningDirection(lastDirection);
+ if (dir == QPannableGesture::None)
return 0;
QPannableGesture *g =
new QPannableGesture(Qt::Pan, pressedPos, lastPos, currentPos,
QRect(), pressedPos, QDateTime(), 0,
gestureFinished ? Qt::GestureFinished : Qt::GestureStarted);
QPannableGesturePrivate *d = (QPannableGesturePrivate*)g->d;
- d->lastDirection = dir; ///###
+ d->lastDirection = lastDir;
d->direction = dir;
return g;
@@ -276,6 +289,7 @@ void QGestureRecognizerPan::reset()
{
mousePressed = false;
lastDirection = Direction::None;
+ currentDirection = Direction::None;
gestureFinished = false;
diagonalRecognizer.reset();
simpleRecognizer.reset();
diff --git a/src/gui/kernel/qgesturestandardrecognizers_p.h b/src/gui/kernel/qgesturestandardrecognizers_p.h
index 3b314e7..567cf65 100644
--- a/src/gui/kernel/qgesturestandardrecognizers_p.h
+++ b/src/gui/kernel/qgesturestandardrecognizers_p.h
@@ -101,6 +101,7 @@ private:
bool mousePressed;
bool gestureFinished;
Direction::DirectionType lastDirection;
+ Direction::DirectionType currentDirection;
QDirectionDiagonalRecognizer diagonalRecognizer;
QDirectionSimpleRecognizer simpleRecognizer;
};