diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-09-26 13:40:50 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-09-30 16:16:51 +0200 |
commit | bd09405792ba3b3552a9e31e515a406c38b8ddc1 (patch) | |
tree | 031a312b52d7d0a52185a59314b4499dd7662482 | |
parent | ed3fc4ea474c751c891c76279db5e14c048033ca (diff) |
Add debug output for QGestureEvent and QGesture classes.
Task-number: QTBUG-15768
Task-number: QTBUG-40461
Change-Id: I3fe29f71ddf39c76efaca02d2b70494378d147dc
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r-- | examples/widgets/gestures/imagegestures/imagewidget.cpp | 4 | ||||
-rw-r--r-- | src/widgets/kernel/qgesture.cpp | 77 | ||||
-rw-r--r-- | src/widgets/kernel/qgesture.h | 5 |
3 files changed, 83 insertions, 3 deletions
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 57c2af4502..81783f211d 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -108,7 +108,7 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) //! [gesture event handler] bool ImageWidget::gestureEvent(QGestureEvent *event) { - qCDebug(lcExample) << "gestureEvent():" << event->gestures().size(); + qCDebug(lcExample) << "gestureEvent():" << event; if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) swipeTriggered(static_cast<QSwipeGesture *>(swipe)); else if (QGesture *pan = event->gesture(Qt::PanGesture)) @@ -132,7 +132,7 @@ void ImageWidget::panTriggered(QPanGesture *gesture) } #endif QPointF delta = gesture->delta(); - qCDebug(lcExample) << "panTriggered():" << delta; + qCDebug(lcExample) << "panTriggered():" << gesture; horizontalOffset += delta.x(); verticalOffset += delta.y(); update(); diff --git a/src/widgets/kernel/qgesture.cpp b/src/widgets/kernel/qgesture.cpp index 2b8f04ccdf..72faedf24e 100644 --- a/src/widgets/kernel/qgesture.cpp +++ b/src/widgets/kernel/qgesture.cpp @@ -36,6 +36,7 @@ #include "private/qstandardgestures_p.h" #include "qgraphicsview.h" +#include <QtCore/QDebug> #ifndef QT_NO_GESTURES QT_BEGIN_NAMESPACE @@ -1124,7 +1125,81 @@ QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const \sa QEvent::ignore() */ -#endif +#endif // Q_NO_USING_KEYWORD + +#ifndef QT_NO_DEBUG_STREAM + +static void formatGestureHeader(QDebug d, const char *className, const QGesture *gesture) +{ + d << className << "(state=" << gesture->state(); + if (gesture->hasHotSpot()) + d << ",hotSpot=" << gesture->hotSpot(); +} + +Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGesture *gesture) +{ + QDebugStateSaver saver(d); + d.nospace(); + switch (gesture->gestureType()) { + case Qt::TapGesture: + formatGestureHeader(d, "QTapGesture", gesture); + d << ",position=" << static_cast<const QTapGesture*>(gesture)->position() << ')'; + break; + case Qt::TapAndHoldGesture: { + const QTapAndHoldGesture *tap = static_cast<const QTapAndHoldGesture*>(gesture); + formatGestureHeader(d, "QTapAndHoldGesture", tap); + d << ",position=" << tap->position() << ",timeout=" << tap->timeout() << ')'; + } + break; + case Qt::PanGesture: { + const QPanGesture *pan = static_cast<const QPanGesture*>(gesture); + formatGestureHeader(d, "QPanGesture", pan); + d << ",lastOffset=" << pan->lastOffset() << ",offset=" << pan->offset() + << ",acceleration=" << pan->acceleration() + << ",delta=" << pan->delta() << ')'; + } + break; + case Qt::PinchGesture: { + const QPinchGesture *pinch = static_cast<const QPinchGesture*>(gesture); + formatGestureHeader(d, "QPinchGesture", pinch); + d << ",totalChangeFlags=" << pinch->totalChangeFlags() + << ",changeFlags=" << pinch->changeFlags() + << ",startCenterPoint=" << pinch->startCenterPoint() + << ",lastCenterPoint=" << pinch->lastCenterPoint() + << ",centerPoint=" << pinch->centerPoint() + << ",totalScaleFactor=" << pinch->totalScaleFactor() + << ",lastScaleFactor=" << pinch->lastScaleFactor() + << ",scaleFactor=" << pinch->scaleFactor() + << ",totalRotationAngle=" << pinch->totalRotationAngle() + << ",lastRotationAngle=" << pinch->lastRotationAngle() + << ",rotationAngle=" << pinch->rotationAngle() << ')'; + } + break; + case Qt::SwipeGesture: { + const QSwipeGesture *swipe = static_cast<const QSwipeGesture*>(gesture); + formatGestureHeader(d, "QSwipeGesture", swipe); + d << ",horizontalDirection=" << swipe->horizontalDirection() + << ",verticalDirection=" << swipe->verticalDirection() + << ",swipeAngle=" << swipe->swipeAngle() << ')'; + } + break; + default: + formatGestureHeader(d, "Custom gesture", gesture); + d << ",type=" << gesture->gestureType() << ')'; + break; + } + return d; +} + +Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGestureEvent *gestureEvent) +{ + QDebugStateSaver saver(d); + d.nospace(); + d << "QGestureEvent(" << gestureEvent->gestures() << ')'; + return d; +} + +#endif // !QT_NO_DEBUG_STREAM QT_END_NAMESPACE diff --git a/src/widgets/kernel/qgesture.h b/src/widgets/kernel/qgesture.h index 9e3ee64c87..70b1faf735 100644 --- a/src/widgets/kernel/qgesture.h +++ b/src/widgets/kernel/qgesture.h @@ -315,6 +315,11 @@ private: friend class QGestureManager; }; +# ifndef QT_NO_DEBUG_STREAM +Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGesture *); +Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGestureEvent *); +# endif + QT_END_NAMESPACE Q_DECLARE_METATYPE(QGesture::GestureCancelPolicy) |