summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qstandardgestures.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-08-04 07:43:14 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-08-04 08:01:10 (GMT)
commitc96ed4426db7ae3287ee88b0ac7ffd2bd5070310 (patch)
treee3b72cb4531f4e24b1705fb4afe65784d098defb /src/gui/kernel/qstandardgestures.cpp
parent1f0ea657d33b6851c1f3cb4becd77c63d4b720d8 (diff)
downloadQt-c96ed4426db7ae3287ee88b0ac7ffd2bd5070310.zip
Qt-c96ed4426db7ae3287ee88b0ac7ffd2bd5070310.tar.gz
Qt-c96ed4426db7ae3287ee88b0ac7ffd2bd5070310.tar.bz2
Add support for pan gesture on mac (carbon and cocoa)
Diffstat (limited to 'src/gui/kernel/qstandardgestures.cpp')
-rw-r--r--src/gui/kernel/qstandardgestures.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index c8b11c5..1a88429 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -73,11 +73,17 @@ QPanGesture::QPanGesture(QWidget *parent)
qAppPriv->widgetGestures[parent].pan = this;
}
#endif
+
+#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA)
+ d_func()->panFinishedTimer = 0;
+#endif
}
/*! \internal */
bool QPanGesture::event(QEvent *event)
{
+ Q_D(QPanGesture);
+
#ifdef Q_WS_WIN
QApplicationPrivate* getQApplicationPrivateInternal();
switch (event->type()) {
@@ -93,6 +99,21 @@ bool QPanGesture::event(QEvent *event)
break;
}
#endif
+
+#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA)
+ if (event->type() == QEvent::Timer) {
+ const QTimerEvent *te = static_cast<QTimerEvent *>(event);
+ if (te->timerId() == d->panFinishedTimer) {
+ killTimer(d->panFinishedTimer);
+ d->panFinishedTimer = 0;
+ d->lastOffset = QSize(0, 0);
+ setState(Qt::GestureFinished);
+ emit triggered();
+ setState(Qt::NoGesture);
+ }
+ }
+#endif
+
return QObject::event(event);
}
@@ -133,6 +154,36 @@ bool QPanGesture::filterEvent(QEvent *event)
emit triggered();
}
}
+#ifdef Q_OS_MAC
+ else if (event->type() == QEvent::Wheel) {
+ // On Mac, there is really no native panning gesture. Instead, a two
+ // finger pan is delivered as mouse wheel events. Otoh, on Windows, you
+ // either get mouse wheel events or pan events. We have decided to make this
+ // the Qt behaviour as well, meaning that on Mac, wheel
+ // events will be masked away when listening for pan events.
+#ifndef QT_MAC_USE_COCOA
+ // In Carbon we receive neither touch-, nor pan gesture events.
+ // So we create pan gestures by converting wheel events. After all, this
+ // is how things are supposed to work on mac in the first place.
+ const QWheelEvent *wev = static_cast<const QWheelEvent*>(event);
+ int offset = wev->delta() / -120;
+ d->lastOffset = wev->orientation() == Qt::Horizontal ? QSize(offset, 0) : QSize(0, offset);
+
+ if (state() == Qt::NoGesture) {
+ setState(Qt::GestureStarted);
+ d->totalOffset = d->lastOffset;
+ } else {
+ setState(Qt::GestureUpdated);
+ d->totalOffset += d->lastOffset;
+ }
+
+ killTimer(d->panFinishedTimer);
+ d->panFinishedTimer = startTimer(200);
+ emit triggered();
+#endif
+ return true;
+ }
+#endif
return false;
}
@@ -150,8 +201,13 @@ void QPanGesture::reset()
*/
QSize QPanGesture::totalOffset() const
{
+#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA)
+ Q_D(const QPanGesture);
+ return d->totalOffset;
+#else
QPoint pt = pos() - startPos();
return QSize(pt.x(), pt.y());
+#endif
}
/*!
@@ -162,8 +218,13 @@ QSize QPanGesture::totalOffset() const
*/
QSize QPanGesture::lastOffset() const
{
+#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA)
+ Q_D(const QPanGesture);
+ return d->lastOffset;
+#else
QPoint pt = pos() - lastPos();
return QSize(pt.x(), pt.y());
+#endif
}
/*!
@@ -252,3 +313,6 @@ void QTapAndHoldGesture::reset()
}
QT_END_NAMESPACE
+
+#include "moc_qstandardgestures.cpp"
+