diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 12 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 128 | ||||
-rw-r--r-- | src/gui/kernel/qgesture.cpp | 37 | ||||
-rw-r--r-- | src/gui/kernel/qgesture.h | 8 | ||||
-rw-r--r-- | src/gui/kernel/qgesture_p.h | 5 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 126 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures_p.h | 5 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_win.cpp | 23 |
9 files changed, 201 insertions, 147 deletions
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 7a27756..e839617 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -249,6 +249,17 @@ typedef struct tagGESTURECONFIG #endif // WM_GESTURE +#if defined(Q_WS_WINCE_WM) && defined(QT_WINCE_GESTURES) +#undef GID_ZOOM +#define GID_ZOOM 0xf000 +#undef GID_ROTATE +#define GID_ROTATE 0xf001 +#undef GID_TWOFINGERTAP +#define GID_TWOFINGERTAP 0xf002 +#undef GID_ROLLOVER +#define GID_ROLLOVER 0xf003 +#endif + #endif // Q_WS_WIN class QPanGesture; @@ -536,6 +547,7 @@ public: PtrBeginPanningFeedback BeginPanningFeedback; PtrUpdatePanningFeedback UpdatePanningFeedback; PtrEndPanningFeedback EndPanningFeedback; + QWidget *gestureWidget; #endif #ifdef QT_RX71_MULTITOUCH diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 7d9e6ea..12cd879 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -452,7 +452,7 @@ public: bool translateConfigEvent(const MSG &msg); bool translateCloseEvent(const MSG &msg); bool translateTabletEvent(const MSG &msg, PACKET *localPacketBuf, int numPackets); - bool translateGestureEvent(const MSG &msg); + bool translateGestureEvent(const MSG &msg, const GESTUREINFO &gi); void repolishStyle(QStyle &style); inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); } inline void hideChildren(bool spontaneous) { d_func()->hideChildren(spontaneous); } @@ -848,6 +848,7 @@ void qt_init(QApplicationPrivate *priv, int) (PtrEndPanningFeedback)QLibrary::resolve(QLatin1String("uxtheme"), "EndPanningFeedback"); #endif + priv->gestureWidget = 0; } /***************************************************************************** @@ -2513,10 +2514,38 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam } result = false; break; - case WM_GESTURE: - widget->translateGestureEvent(msg); + case WM_GESTURE: { + GESTUREINFO gi; + memset(&gi, 0, sizeof(GESTUREINFO)); + gi.cbSize = sizeof(GESTUREINFO); + + QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); + BOOL bResult = false; + if (qAppPriv->GetGestureInfo) + bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi); + if (bResult) { + if (gi.dwID == GID_BEGIN) { + // find the alien widget for the gesture position. + // This might not be accurate as the position is the center + // point of two fingers for multi-finger gestures. + QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y); + QWidget *w = widget->childAt(widget->mapFromGlobal(pt)); + qAppPriv->gestureWidget = w ? w : widget; + } + if (qAppPriv->gestureWidget) + static_cast<QETWidget*>(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi); + if (qAppPriv->CloseGestureInfoHandle) + qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); + if (gi.dwID == GID_END) + qAppPriv->gestureWidget = 0; + } else { + DWORD dwErr = GetLastError(); + if (dwErr > 0) + qWarning() << "translateGestureEvent: error = " << dwErr; + } result = true; break; + } default: result = false; // event was not processed break; @@ -3725,69 +3754,42 @@ bool QETWidget::translateCloseEvent(const MSG &) return d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); } -bool QETWidget::translateGestureEvent(const MSG &msg) +bool QETWidget::translateGestureEvent(const MSG &, const GESTUREINFO &gi) { - GESTUREINFO gi; - memset(&gi, 0, sizeof(GESTUREINFO)); - gi.cbSize = sizeof(GESTUREINFO); + const QPoint widgetPos = QPoint(gi.ptsLocation.x, gi.ptsLocation.y); + QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos); + if (alienWidget && alienWidget->internalWinId()) + alienWidget = 0; + QWidget *widget = alienWidget ? alienWidget : this; - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); -#if defined(Q_WS_WINCE_WM) && defined(QT_WINCE_GESTURES) -#undef GID_ZOOM -#define GID_ZOOM 0xf000 -#undef GID_ROTATE -#define GID_ROTATE 0xf001 -#undef GID_TWOFINGERTAP -#define GID_TWOFINGERTAP 0xf002 -#undef GID_ROLLOVER -#define GID_ROLLOVER 0xf003 -#endif - BOOL bResult = false; - if (qAppPriv->GetGestureInfo) - bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi); - - if (bResult) { - const QPoint widgetPos = QPoint(gi.ptsLocation.x, gi.ptsLocation.y); - QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos); - if (alienWidget && alienWidget->internalWinId()) - alienWidget = 0; - QWidget *widget = alienWidget ? alienWidget : this; - - QNativeGestureEvent event; - event.sequenceId = gi.dwSequenceID; - event.position = QPoint(gi.ptsLocation.x, gi.ptsLocation.y); - event.argument = gi.ullArguments; - - switch (gi.dwID) { - case GID_BEGIN: - event.gestureType = QNativeGestureEvent::GestureBegin; - break; - case GID_END: - event.gestureType = QNativeGestureEvent::GestureEnd; - break; - case GID_ZOOM: - event.gestureType = QNativeGestureEvent::Zoom; - break; - case GID_PAN: - event.gestureType = QNativeGestureEvent::Pan; - break; - case GID_ROTATE: - event.gestureType = QNativeGestureEvent::Rotate; - break; - case GID_TWOFINGERTAP: - case GID_ROLLOVER: - default: - break; - } - if (qAppPriv->CloseGestureInfoHandle) - qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); - if (event.gestureType != QNativeGestureEvent::None) - qt_sendSpontaneousEvent(widget, &event); - } else { - DWORD dwErr = GetLastError(); - if (dwErr > 0) - qWarning() << "translateGestureEvent: error = " << dwErr; + QNativeGestureEvent event; + event.sequenceId = gi.dwSequenceID; + event.position = QPoint(gi.ptsLocation.x, gi.ptsLocation.y); + event.argument = gi.ullArguments; + + switch (gi.dwID) { + case GID_BEGIN: + event.gestureType = QNativeGestureEvent::GestureBegin; + break; + case GID_END: + event.gestureType = QNativeGestureEvent::GestureEnd; + break; + case GID_ZOOM: + event.gestureType = QNativeGestureEvent::Zoom; + break; + case GID_PAN: + event.gestureType = QNativeGestureEvent::Pan; + break; + case GID_ROTATE: + event.gestureType = QNativeGestureEvent::Rotate; + break; + case GID_TWOFINGERTAP: + case GID_ROLLOVER: + default: + break; } + if (event.gestureType != QNativeGestureEvent::None) + qt_sendSpontaneousEvent(widget, &event); return true; } diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index 79dcae1..eeb6528 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -149,20 +149,18 @@ private: \sa setGraphicsItem() */ -QGesture::QGesture(QObject *parent) +QGesture::QGesture(QObject *gestureTarget, QObject *parent) : QObject(*new QGesturePrivate, parent) { - if (parent) - parent->installEventFilter(this); + setGestureTarget(gestureTarget); } /*! \internal */ -QGesture::QGesture(QGesturePrivate &dd, QObject *parent) +QGesture::QGesture(QGesturePrivate &dd, QObject *gestureTarget, QObject *parent) : QObject(dd, parent) { - if (parent) - parent->installEventFilter(this); + setGestureTarget(gestureTarget); } /*! @@ -172,6 +170,33 @@ QGesture::~QGesture() { } +/*! + \property QGesture::gestureTarget + + Gesture target is the object that the gesture will observe for events. + Typically this means that the gesture installs an event filter on the + target object. +*/ +void QGesture::setGestureTarget(QObject *object) +{ + d_func()->setupGestureTarget(object); +} + +QObject* QGesture::gestureTarget() const +{ + return d_func()->gestureTarget; +} + +void QGesturePrivate::setupGestureTarget(QObject *object) +{ + Q_Q(QGesture); + if (gestureTarget) + gestureTarget->removeEventFilter(q); + if (object) + object->installEventFilter(q); + gestureTarget = object; +} + /*! \internal */ bool QGesture::eventFilter(QObject *receiver, QEvent *event) diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h index ee28ea4..1d2fa6d 100644 --- a/src/gui/kernel/qgesture.h +++ b/src/gui/kernel/qgesture.h @@ -63,20 +63,24 @@ class Q_GUI_EXPORT QGesture : public QObject Q_DECLARE_PRIVATE(QGesture) Q_PROPERTY(Qt::GestureState state READ state) + Q_PROPERTY(QObject* gestureTarget READ gestureTarget WRITE setGestureTarget) public: - explicit QGesture(QObject *parent = 0); + explicit QGesture(QObject *gestureTarget = 0, QObject *parent = 0); ~QGesture(); virtual bool filterEvent(QEvent *event) = 0; + void setGestureTarget(QObject *object); + QObject* gestureTarget() const; + void setGraphicsItem(QGraphicsItem *); QGraphicsItem *graphicsItem() const; Qt::GestureState state() const; protected: - QGesture(QGesturePrivate &dd, QObject *parent); + QGesture(QGesturePrivate &dd, QObject *gestureTarget, QObject *parent); bool eventFilter(QObject*, QEvent*); virtual void reset(); diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 37f3146..f584713 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -69,11 +69,14 @@ class QGesturePrivate : public QObjectPrivate public: QGesturePrivate() - : graphicsItem(0), eventFilterProxyGraphicsItem(0), state(Qt::NoGesture) + : gestureTarget(0), graphicsItem(0), eventFilterProxyGraphicsItem(0), + state(Qt::NoGesture) { } + virtual void setupGestureTarget(QObject *o); + QPointer<QObject> gestureTarget; QGraphicsItem *graphicsItem; QGraphicsItem *eventFilterProxyGraphicsItem; diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 10689ba..d798d32 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -69,42 +69,35 @@ QWidgetPrivate *qt_widget_private(QWidget *widget); On some platform like Windows it's necessary to provide a non-null widget as \a parent to get native gesture support. */ -QPanGesture::QPanGesture(QWidget *parent) - : QGesture(*new QPanGesturePrivate, parent) +QPanGesture::QPanGesture(QWidget *gestureTarget, QObject *parent) + : QGesture(*new QPanGesturePrivate, gestureTarget, parent) { - if (parent) { - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - qAppPriv->widgetGestures[parent].pan = this; -#ifdef Q_WS_WIN - qt_widget_private(parent)->winSetupGestures(); -#endif - } } -/*! \internal */ -bool QPanGesture::event(QEvent *event) +void QPanGesturePrivate::setupGestureTarget(QObject *newGestureTarget) { - switch (event->type()) { - case QEvent::ParentAboutToChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) { - QApplicationPrivate::instance()->widgetGestures[w].pan = 0; + Q_Q(QPanGesture); + if (gestureTarget && gestureTarget->isWidgetType()) { + QWidget *w = static_cast<QWidget*>(gestureTarget.data()); + QApplicationPrivate::instance()->widgetGestures[w].pan = 0; #ifdef Q_WS_WIN - qt_widget_private(w)->winSetupGestures(); + qt_widget_private(w)->winSetupGestures(); #endif - } - break; - case QEvent::ParentChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) { - QApplicationPrivate::instance()->widgetGestures[w].pan = this; + } + + if (newGestureTarget && newGestureTarget->isWidgetType()) { + QWidget *w = static_cast<QWidget*>(newGestureTarget); + QApplicationPrivate::instance()->widgetGestures[w].pan = q; #ifdef Q_WS_WIN - qt_widget_private(w)->winSetupGestures(); + qt_widget_private(w)->winSetupGestures(); #endif - } - break; - default: - break; } + QGesturePrivate::setupGestureTarget(newGestureTarget); +} +/*! \internal */ +bool QPanGesture::event(QEvent *event) +{ #if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA) Q_D(QPanGesture); if (event->type() == QEvent::Timer) { @@ -179,27 +172,29 @@ bool QPanGesture::filterEvent(QEvent *event) d->lastOffset = d->totalOffset = QSize(); } else if (event->type() == QEvent::TouchEnd) { if (state() != Qt::NoGesture) { - if (!ev->touchPoints().isEmpty()) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - const QPoint pos = p.pos().toPoint(); - const QPoint lastPos = p.lastPos().toPoint(); - const QPoint startPos = p.startPos().toPoint(); - d->lastOffset = QSize(pos.x() - lastPos.x(), pos.y() - lastPos.y()); - d->totalOffset = QSize(pos.x() - startPos.x(), pos.y() - startPos.y()); + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + d->lastOffset = + QSize(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), + p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; + d->totalOffset += d->lastOffset; } updateState(Qt::GestureFinished); } reset(); } else if (event->type() == QEvent::TouchUpdate) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - const QPoint pos = p.pos().toPoint(); - const QPoint lastPos = p.lastPos().toPoint(); - const QPoint startPos = p.startPos().toPoint(); - d->lastOffset = QSize(pos.x() - lastPos.x(), pos.y() - lastPos.y()); - d->totalOffset = QSize(pos.x() - startPos.x(), pos.y() - startPos.y()); - if (d->totalOffset.width() > 10 || d->totalOffset.height() > 10 || - d->totalOffset.width() < -10 || d->totalOffset.height() < -10) { - updateState(Qt::GestureUpdated); + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + d->lastOffset = + QSize(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), + p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; + d->totalOffset += d->lastOffset; + if (d->totalOffset.width() > 10 || d->totalOffset.height() > 10 || + d->totalOffset.width() < -10 || d->totalOffset.height() < -10) { + updateState(Qt::GestureUpdated); + } } } #ifdef Q_OS_MAC @@ -287,41 +282,35 @@ QSize QPanGesture::lastOffset() const On some platform like Windows it's necessary to provide a non-null widget as \a parent to get native gesture support. */ -QPinchGesture::QPinchGesture(QWidget *parent) - : QGesture(*new QPinchGesturePrivate, parent) +QPinchGesture::QPinchGesture(QWidget *gestureTarget, QObject *parent) + : QGesture(*new QPinchGesturePrivate, gestureTarget, parent) { - if (parent) { - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - qAppPriv->widgetGestures[parent].pinch = this; -#ifdef Q_WS_WIN - qt_widget_private(parent)->winSetupGestures(); -#endif - } } -/*! \internal */ -bool QPinchGesture::event(QEvent *event) +void QPinchGesturePrivate::setupGestureTarget(QObject *newGestureTarget) { - switch (event->type()) { - case QEvent::ParentAboutToChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) { - QApplicationPrivate::instance()->widgetGestures[w].pinch = 0; + Q_Q(QPinchGesture); + if (gestureTarget && gestureTarget->isWidgetType()) { + QWidget *w = static_cast<QWidget*>(gestureTarget.data()); + QApplicationPrivate::instance()->widgetGestures[w].pinch = 0; #ifdef Q_WS_WIN - qt_widget_private(w)->winSetupGestures(); + qt_widget_private(w)->winSetupGestures(); #endif - } - break; - case QEvent::ParentChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) { - QApplicationPrivate::instance()->widgetGestures[w].pinch = this; + } + + if (newGestureTarget && newGestureTarget->isWidgetType()) { + QWidget *w = static_cast<QWidget*>(newGestureTarget); + QApplicationPrivate::instance()->widgetGestures[w].pinch = q; #ifdef Q_WS_WIN - qt_widget_private(w)->winSetupGestures(); + qt_widget_private(w)->winSetupGestures(); #endif - } - break; - default: - break; } + QGesturePrivate::setupGestureTarget(newGestureTarget); +} + +/*! \internal */ +bool QPinchGesture::event(QEvent *event) +{ return QObject::event(event); } @@ -399,6 +388,7 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) return QGesture::eventFilter(receiver, event); } + /*! \internal */ bool QPinchGesture::filterEvent(QEvent *event) { diff --git a/src/gui/kernel/qstandardgestures.h b/src/gui/kernel/qstandardgestures.h index 8b5421b..0eb9d92 100644 --- a/src/gui/kernel/qstandardgestures.h +++ b/src/gui/kernel/qstandardgestures.h @@ -63,7 +63,7 @@ class Q_GUI_EXPORT QPanGesture : public QGesture Q_PROPERTY(QSize lastOffset READ lastOffset) public: - QPanGesture(QWidget *parent); + QPanGesture(QWidget *gestureTarget, QObject *parent = 0); bool filterEvent(QEvent *event); @@ -97,7 +97,7 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture Q_PROPERTY(QPoint centerPoint READ centerPoint) public: - QPinchGesture(QWidget *parent); + QPinchGesture(QWidget *gestureTarget, QObject *parent = 0); bool filterEvent(QEvent *event); void reset(); diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index c52d16b..5fbcc5d 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -76,6 +76,8 @@ public: #endif } + void setupGestureTarget(QObject *o); + QSize totalOffset; QSize lastOffset; QPoint lastPosition; @@ -98,6 +100,9 @@ public: #endif { } + + void setupGestureTarget(QObject *o); + qreal scaleFactor; qreal lastScaleFactor; qreal rotationAngle; diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 3d618fe..4fc37b1 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -2070,11 +2070,21 @@ void QWidgetPrivate::winSetupGestures() bool needh = false; bool needv = false; bool singleFingerPanEnabled = false; - QStandardGestures gestures = qAppPriv->widgetGestures[q]; + QApplicationPrivate::WidgetStandardGesturesMap::const_iterator it = + qAppPriv->widgetGestures.find(q); + if (it == qAppPriv->widgetGestures.end()) + return; + const QStandardGestures &gestures = it.value(); WId winid = 0; if (QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea*>(q)) { - winid = asa->viewport()->winId(); + winid = asa->viewport()->internalWinId(); + if (!winid) { + QWidget *nativeParent = asa->viewport()->nativeParentWidget(); + if (!nativeParent) + return; + winid = nativeParent->internalWinId(); + } QScrollBar *hbar = asa->horizontalScrollBar(); QScrollBar *vbar = asa->verticalScrollBar(); Qt::ScrollBarPolicy hbarpolicy = asa->horizontalScrollBarPolicy(); @@ -2085,9 +2095,13 @@ void QWidgetPrivate::winSetupGestures() (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum())); singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled; } else { - winid = q->winId(); + winid = q->internalWinId(); + if (!winid) { + if (QWidget *nativeParent = q->nativeParentWidget()) + winid = nativeParent->internalWinId(); + } } - if (qAppPriv->SetGestureConfig) { + if (winid && qAppPriv->SetGestureConfig) { GESTURECONFIG gc[3]; memset(gc, 0, sizeof(gc)); gc[0].dwID = GID_PAN; @@ -2116,7 +2130,6 @@ void QWidgetPrivate::winSetupGestures() else gc[2].dwBlock = GC_ROTATE; - Q_ASSERT(winid); qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0])); } } |