@@ -36,7 +36,7 @@
36using namespace UbuntuGestures;
36using namespace UbuntuGestures;
38#if DIRECTIONALDRAGAREA_DEBUG
38#if DIRECTIONALDRAGAREA_DEBUG
39−#define DDA_DEBUG(msg) qDebug("[DDA] " msg)
39+#define ddaDebug(params) qDebug().nospace() << "[DDA(" << qPrintable(objectName()) << ")] " << params
40#include "DebugHelpers.h"
40#include "DebugHelpers.h"
42namespace {
42namespace {
@@ -53,7 +53,7 @@ const char *statusToString(DirectionalDragArea::Status status)
54} // namespace {
54} // namespace {
55#else // DIRECTIONALDRAGAREA_DEBUG
55#else // DIRECTIONALDRAGAREA_DEBUG
56−#define DDA_DEBUG(msg) do{}while(0)
56+#define ddaDebug(params) ((void)0)
57#endif // DIRECTIONALDRAGAREA_DEBUG
57#endif // DIRECTIONALDRAGAREA_DEBUG
@@ -253,7 +253,7 @@ void DirectionalDragArea::touchOwnershipEvent(TouchOwnershipEvent *event)
253 if (event->gained()) {
253 if (event->gained()) {
254 QVector<int> ids;
254 QVector<int> ids;
255 ids.append(event->touchId());
255 ids.append(event->touchId());
256− DDA_DEBUG("grabbing touch");
256+ ddaDebug("grabbing touch");
257 grabTouchPoints(ids);
257 grabTouchPoints(ids);
259 // Work around for Qt bug. If we grab a touch that is being used for mouse pointer
259 // Work around for Qt bug. If we grab a touch that is being used for mouse pointer
@@ -265,7 +265,7 @@ void DirectionalDragArea::touchOwnershipEvent(TouchOwnershipEvent *event)
265 if (window()) {
265 if (window()) {
266 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(window());
266 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(window());
267 if (windowPrivate->touchMouseId == event->touchId() && window()->mouseGrabberItem()) {
267 if (windowPrivate->touchMouseId == event->touchId() && window()->mouseGrabberItem()) {
268− DDA_DEBUG("removing mouse grabber");
268+ ddaDebug("removing mouse grabber");
269 window()->mouseGrabberItem()->ungrabMouse();
269 window()->mouseGrabberItem()->ungrabMouse();
@@ -283,11 +283,7 @@ void DirectionalDragArea::unownedTouchEvent(UnownedTouchEvent *unownedTouchEvent
284 Q_ASSERT(!event->touchPointStates().testFlag(Qt::TouchPointPressed));
284 Q_ASSERT(!event->touchPointStates().testFlag(Qt::TouchPointPressed));
286− #if DIRECTIONALDRAGAREA_DEBUG
287− // TODO Consider using qCDebug() when available (Qt 5.2)
288− qDebug() << "[DDA] Unowned" << m_timeSource->msecsSinceReference()
286+ ddaDebug("Unowned " << m_timeSource->msecsSinceReference() << " " << qPrintable(touchEventToString(event)));
289− << qPrintable(touchEventToString(event));
292 switch (m_status) {
288 switch (m_status) {
293 case WaitingForTouch:
289 case WaitingForTouch:
@@ -322,7 +318,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
323 if (touchPoint->state() == Qt::TouchPointReleased) {
319 if (touchPoint->state() == Qt::TouchPointReleased) {
324 // touch has ended before recognition concluded
320 // touch has ended before recognition concluded
325− DDA_DEBUG("Touch has ended before recognition concluded");
321+ ddaDebug("Touch has ended before recognition concluded");
326 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
322 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
327 emitSignalIfTapped();
323 emitSignalIfTapped();
328 setStatus(WaitingForTouch);
324 setStatus(WaitingForTouch);
@@ -335,7 +331,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
335 updateVelocityCalculator(touchScenePos);
331 updateVelocityCalculator(touchScenePos);
337 if (!pointInsideAllowedArea()) {
333 if (!pointInsideAllowedArea()) {
338− DDA_DEBUG("Rejecting gesture because touch point is outside allowed area.");
334+ ddaDebug("Rejecting gesture because touch point is outside allowed area.");
339 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
335 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
340 // We still wanna know when it ends for keeping the composition time window up-to-date
336 // We still wanna know when it ends for keeping the composition time window up-to-date
341 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
337 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
@@ -344,7 +340,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
346 if (!movingInRightDirection()) {
342 if (!movingInRightDirection()) {
347− DDA_DEBUG("Rejecting gesture because touch point is moving in the wrong direction.");
343+ ddaDebug("Rejecting gesture because touch point is moving in the wrong direction.");
348 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
344 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
349 // We still wanna know when it ends for keeping the composition time window up-to-date
345 // We still wanna know when it ends for keeping the composition time window up-to-date
350 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
346 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
@@ -358,7 +354,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
358 if (isWithinTouchCompositionWindow()) {
354 if (isWithinTouchCompositionWindow()) {
359 // There's still time for some new touch to appear and ruin our party as it would be combined
355 // There's still time for some new touch to appear and ruin our party as it would be combined
360 // with our m_touchId one and therefore deny the possibility of a single-finger gesture.
356 // with our m_touchId one and therefore deny the possibility of a single-finger gesture.
361− DDA_DEBUG("Sill within composition window. Let's wait more.");
357+ ddaDebug("Sill within composition window. Let's wait more.");
@@ -366,7 +362,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
366 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
362 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
367 setStatus(Recognized);
363 setStatus(Recognized);
369− DDA_DEBUG("Didn't move far enough yet. Let's wait more.");
365+ ddaDebug("Didn't move far enough yet. Let's wait more.");
@@ -375,11 +371,7 @@ void DirectionalDragArea::touchEvent(QTouchEvent *event)
375 // TODO: Consider when more than one touch starts in the same event (although it's not possible
371 // TODO: Consider when more than one touch starts in the same event (although it's not possible
376 // with Mir's android-input). Have to track them all. Consider it a plus/bonus.
372 // with Mir's android-input). Have to track them all. Consider it a plus/bonus.
378− #if DIRECTIONALDRAGAREA_DEBUG
379− // TODO Consider using qCDebug() when available (Qt 5.2)
380− qDebug() << "[DDA]" << m_timeSource->msecsSinceReference()
381− << qPrintable(touchEventToString(event));
374+ ddaDebug(m_timeSource->msecsSinceReference() << " " << qPrintable(touchEventToString(event)));
384 if (!isEnabled() || !isVisible()) {
376 if (!isEnabled() || !isVisible()) {
385 QQuickItem::touchEvent(event);
377 QQuickItem::touchEvent(event);
@@ -416,9 +408,7 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
416 if (isWithinTouchCompositionWindow()) {
408 if (isWithinTouchCompositionWindow()) {
417 // too close to the last touch start. So we consider them as starting roughly at the same time.
409 // too close to the last touch start. So we consider them as starting roughly at the same time.
418 // Can't be a single-touch gesture.
410 // Can't be a single-touch gesture.
419− #if DIRECTIONALDRAGAREA_DEBUG
420− qDebug("[DDA] A new touch point came in but we're still within time composition window. Ignoring it.");
411+ ddaDebug("A new touch point came in but we're still within time composition window. Ignoring it.");
422 allGood = false;
412 allGood = false;
@@ -456,6 +446,7 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
457 if (recognitionIsDisabled()) {
447 if (recognitionIsDisabled()) {
458 // Behave like a dumb TouchArea
448 // Behave like a dumb TouchArea
449+ ddaDebug("Gesture recognition is disabled. Requesting touch ownership immediately.");
459 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
450 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
460 setStatus(Recognized);
451 setStatus(Recognized);
461 event->accept();
452 event->accept();
@@ -487,7 +478,7 @@ void DirectionalDragArea::touchEvent_undecided(QTouchEvent *event)
488 if (event->touchPointStates().testFlag(Qt::TouchPointPressed) && isWithinTouchCompositionWindow()) {
479 if (event->touchPointStates().testFlag(Qt::TouchPointPressed) && isWithinTouchCompositionWindow()) {
489 // multi-finger drags are not accepted
480 // multi-finger drags are not accepted
490− DDA_DEBUG("Multi-finger drags are not accepted");
481+ ddaDebug("Multi-finger drags are not accepted");
492 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
483 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
493 // We still wanna know when it ends for keeping the composition time window up-to-date
484 // We still wanna know when it ends for keeping the composition time window up-to-date
@@ -581,12 +572,16 @@ bool DirectionalDragArea::pointInsideAllowedArea() const
582bool DirectionalDragArea::movingInRightDirection() const
573bool DirectionalDragArea::movingInRightDirection() const
575+ if (m_direction == Direction::Horizontal) {
584− QPointF movementVector(m_dampedScenePos.x() - m_previousDampedScenePos.x(),
578+ QPointF movementVector(m_dampedScenePos.x() - m_previousDampedScenePos.x(),
585− m_dampedScenePos.y() - m_previousDampedScenePos.y());
579+ m_dampedScenePos.y() - m_previousDampedScenePos.y());
587− qreal scalarProjection = projectOntoDirectionVector(movementVector);
581+ qreal scalarProjection = projectOntoDirectionVector(movementVector);
589− return scalarProjection >= 0.;
583+ return scalarProjection >= 0.;
592bool DirectionalDragArea::movedFarEnough(const QPointF &point) const
587bool DirectionalDragArea::movedFarEnough(const QPointF &point) const
@@ -614,7 +609,7 @@ void DirectionalDragArea::checkSpeed()
614 qreal minSpeedMsecs = m_minSpeed / 1000.0;
609 qreal minSpeedMsecs = m_minSpeed / 1000.0;
616 if (speed < minSpeedMsecs) {
611 if (speed < minSpeedMsecs) {
617− DDA_DEBUG("Rejecting gesture because it's below minimum speed.");
612+ ddaDebug("Rejecting gesture because it's below minimum speed.");
618 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
613 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
619 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
614 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
620 setStatus(WaitingForTouch);
615 setStatus(WaitingForTouch);
@@ -625,7 +620,7 @@ void DirectionalDragArea::checkSpeed()
625 m_silenceTime += m_recognitionTimer->interval();
620 m_silenceTime += m_recognitionTimer->interval();
627 if (m_silenceTime > m_maxSilenceTime) {
622 if (m_silenceTime > m_maxSilenceTime) {
628− DDA_DEBUG("Rejecting gesture because its silence time has been exceeded.");
623+ ddaDebug("Rejecting gesture because its silence time has been exceeded.");
629 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
624 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
630 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
625 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
631 setStatus(WaitingForTouch);
626 setStatus(WaitingForTouch);
@@ -646,7 +641,7 @@ void DirectionalDragArea::giveUpIfDisabledOrInvisible()
648 if (m_status != WaitingForTouch) {
643 if (m_status != WaitingForTouch) {
649− DDA_DEBUG("Resetting status because got disabled or made invisible");
644+ ddaDebug("Resetting status because got disabled or made invisible");
650 setStatus(WaitingForTouch);
645 setStatus(WaitingForTouch);
@@ -666,9 +661,7 @@ void DirectionalDragArea::setStatus(DirectionalDragArea::Status newStatus)
666 m_status = newStatus;
661 m_status = newStatus;
667 Q_EMIT statusChanged(m_status);
662 Q_EMIT statusChanged(m_status);
669− #if DIRECTIONALDRAGAREA_DEBUG
670− qDebug() << "[DDA]" << statusToString(oldStatus) << "->" << statusToString(newStatus);
664+ ddaDebug(statusToString(oldStatus) << " -> " << statusToString(newStatus));
673 switch (newStatus) {
666 switch (newStatus) {
674 case WaitingForTouch:
667 case WaitingForTouch:
@@ -875,7 +868,7 @@ void DirectionalDragArea::updateSceneDirectionVector()
875 localDirection.rx() = -1.;
868 localDirection.rx() = -1.;
876 localDirection.ry() = 0.;
869 localDirection.ry() = 0.;
878− default: // Direction::Rightwards:
871+ default: // Direction::Rightwards || Direction.Horizontal
879 localDirection.rx() = 1.;
872 localDirection.rx() = 1.;
880 localDirection.ry() = 0.;
873 localDirection.ry() = 0.;
@@ -891,6 +884,3 @@ qreal DirectionalDragArea::projectOntoDirectionVector(const QPointF &sceneVector
891 return sceneVector.x() * m_sceneDirectionVector.x() +
884 return sceneVector.x() * m_sceneDirectionVector.x() +
892 sceneVector.y() * m_sceneDirectionVector.y();
885 sceneVector.y() * m_sceneDirectionVector.y();
895−// Because we are defining a new QObject-based class (RecognitionTimer) here.
896−#include "DirectionalDragArea.moc"