@@ -36,7 +36,7 @@
3636using namespace UbuntuGestures;
3737
3838#if DIRECTIONALDRAGAREA_DEBUG
39−#define DDA_DEBUG(msg) qDebug("[DDA] " msg)
39+#define ddaDebug(params) qDebug().nospace() << "[DDA(" << qPrintable(objectName()) << ")] " << params
4040#include "DebugHelpers.h"
4141
4242namespace {
@@ -53,7 +53,7 @@ const char *statusToString(DirectionalDragArea::Status status)
5353
5454} // namespace {
5555#else // DIRECTIONALDRAGAREA_DEBUG
56−#define DDA_DEBUG(msg) do{}while(0)
56+#define ddaDebug(params) ((void)0)
5757#endif // DIRECTIONALDRAGAREA_DEBUG
5858
5959
@@ -253,7 +253,7 @@ void DirectionalDragArea::touchOwnershipEvent(TouchOwnershipEvent *event)
253253 if (event->gained()) {
254254 QVector<int> ids;
255255 ids.append(event->touchId());
256− DDA_DEBUG("grabbing touch");
256+ ddaDebug("grabbing touch");
257257 grabTouchPoints(ids);
258258
259259 // 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)
265265 if (window()) {
266266 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(window());
267267 if (windowPrivate->touchMouseId == event->touchId() && window()->mouseGrabberItem()) {
268− DDA_DEBUG("removing mouse grabber");
268+ ddaDebug("removing mouse grabber");
269269 window()->mouseGrabberItem()->ungrabMouse();
270270 }
271271 }
@@ -283,11 +283,7 @@ void DirectionalDragArea::unownedTouchEvent(UnownedTouchEvent *unownedTouchEvent
283283
284284 Q_ASSERT(!event->touchPointStates().testFlag(Qt::TouchPointPressed));
285285
286− #if DIRECTIONALDRAGAREA_DEBUG
287− // TODO Consider using qCDebug() when available (Qt 5.2)
288− qDebug() << "[DDA] Unowned" << m_timeSource->msecsSinceReference()
289− << qPrintable(touchEventToString(event));
290− #endif
286+ ddaDebug("Unowned " << m_timeSource->msecsSinceReference() << " " << qPrintable(touchEventToString(event)));
291287
292288 switch (m_status) {
293289 case WaitingForTouch:
@@ -322,7 +318,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
322318
323319 if (touchPoint->state() == Qt::TouchPointReleased) {
324320 // touch has ended before recognition concluded
325− DDA_DEBUG("Touch has ended before recognition concluded");
321+ ddaDebug("Touch has ended before recognition concluded");
326322 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
327323 emitSignalIfTapped();
328324 setStatus(WaitingForTouch);
@@ -335,7 +331,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
335331 updateVelocityCalculator(touchScenePos);
336332
337333 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.");
339335 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
340336 // We still wanna know when it ends for keeping the composition time window up-to-date
341337 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
@@ -344,7 +340,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
344340 }
345341
346342 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.");
348344 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
349345 // We still wanna know when it ends for keeping the composition time window up-to-date
350346 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
@@ -358,7 +354,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
358354 if (isWithinTouchCompositionWindow()) {
359355 // There's still time for some new touch to appear and ruin our party as it would be combined
360356 // 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.");
362358 return;
363359 }
364360
@@ -366,7 +362,7 @@ void DirectionalDragArea::unownedTouchEvent_undecided(UnownedTouchEvent *unowned
366362 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
367363 setStatus(Recognized);
368364 } else {
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.");
370366 }
371367}
372368
@@ -375,11 +371,7 @@ void DirectionalDragArea::touchEvent(QTouchEvent *event)
375371 // TODO: Consider when more than one touch starts in the same event (although it's not possible
376372 // with Mir's android-input). Have to track them all. Consider it a plus/bonus.
377373
378− #if DIRECTIONALDRAGAREA_DEBUG
379− // TODO Consider using qCDebug() when available (Qt 5.2)
380− qDebug() << "[DDA]" << m_timeSource->msecsSinceReference()
381− << qPrintable(touchEventToString(event));
382− #endif
374+ ddaDebug(m_timeSource->msecsSinceReference() << " " << qPrintable(touchEventToString(event)));
383375
384376 if (!isEnabled() || !isVisible()) {
385377 QQuickItem::touchEvent(event);
@@ -416,9 +408,7 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
416408 if (isWithinTouchCompositionWindow()) {
417409 // too close to the last touch start. So we consider them as starting roughly at the same time.
418410 // 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.");
421− #endif
411+ ddaDebug("A new touch point came in but we're still within time composition window. Ignoring it.");
422412 allGood = false;
423413 }
424414
@@ -456,6 +446,7 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
456446
457447 if (recognitionIsDisabled()) {
458448 // Behave like a dumb TouchArea
449+ ddaDebug("Gesture recognition is disabled. Requesting touch ownership immediately.");
459450 TouchRegistry::instance()->requestTouchOwnership(m_touchId, this);
460451 setStatus(Recognized);
461452 event->accept();
@@ -487,7 +478,7 @@ void DirectionalDragArea::touchEvent_undecided(QTouchEvent *event)
487478
488479 if (event->touchPointStates().testFlag(Qt::TouchPointPressed) && isWithinTouchCompositionWindow()) {
489480 // multi-finger drags are not accepted
490− DDA_DEBUG("Multi-finger drags are not accepted");
481+ ddaDebug("Multi-finger drags are not accepted");
491482
492483 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
493484 // We still wanna know when it ends for keeping the composition time window up-to-date
@@ -581,12 +572,16 @@ bool DirectionalDragArea::pointInsideAllowedArea() const
581572
582573bool DirectionalDragArea::movingInRightDirection() const
583574{
584− QPointF movementVector(m_dampedScenePos.x() - m_previousDampedScenePos.x(),
585− m_dampedScenePos.y() - m_previousDampedScenePos.y());
575+ if (m_direction == Direction::Horizontal) {
576+ return true;
577+ } else {
578+ QPointF movementVector(m_dampedScenePos.x() - m_previousDampedScenePos.x(),
579+ m_dampedScenePos.y() - m_previousDampedScenePos.y());
586580
587− qreal scalarProjection = projectOntoDirectionVector(movementVector);
581+ qreal scalarProjection = projectOntoDirectionVector(movementVector);
588582
589− return scalarProjection >= 0.;
583+ return scalarProjection >= 0.;
584+ }
590585}
591586
592587bool DirectionalDragArea::movedFarEnough(const QPointF &point) const
@@ -614,7 +609,7 @@ void DirectionalDragArea::checkSpeed()
614609 qreal minSpeedMsecs = m_minSpeed / 1000.0;
615610
616611 if (speed < minSpeedMsecs) {
617− DDA_DEBUG("Rejecting gesture because it's below minimum speed.");
612+ ddaDebug("Rejecting gesture because it's below minimum speed.");
618613 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
619614 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
620615 setStatus(WaitingForTouch);
@@ -625,7 +620,7 @@ void DirectionalDragArea::checkSpeed()
625620 m_silenceTime += m_recognitionTimer->interval();
626621
627622 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.");
629624 TouchRegistry::instance()->removeCandidateOwnerForTouch(m_touchId, this);
630625 TouchRegistry::instance()->addTouchWatcher(m_touchId, this);
631626 setStatus(WaitingForTouch);
@@ -646,7 +641,7 @@ void DirectionalDragArea::giveUpIfDisabledOrInvisible()
646641 }
647642
648643 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");
650645 setStatus(WaitingForTouch);
651646 }
652647 }
@@ -666,9 +661,7 @@ void DirectionalDragArea::setStatus(DirectionalDragArea::Status newStatus)
666661 m_status = newStatus;
667662 Q_EMIT statusChanged(m_status);
668663
669− #if DIRECTIONALDRAGAREA_DEBUG
670− qDebug() << "[DDA]" << statusToString(oldStatus) << "->" << statusToString(newStatus);
671− #endif
664+ ddaDebug(statusToString(oldStatus) << " -> " << statusToString(newStatus));
672665
673666 switch (newStatus) {
674667 case WaitingForTouch:
@@ -875,7 +868,7 @@ void DirectionalDragArea::updateSceneDirectionVector()
875868 localDirection.rx() = -1.;
876869 localDirection.ry() = 0.;
877870 break;
878− default: // Direction::Rightwards:
871+ default: // Direction::Rightwards || Direction.Horizontal
879872 localDirection.rx() = 1.;
880873 localDirection.ry() = 0.;
881874 break;
@@ -891,6 +884,3 @@ qreal DirectionalDragArea::projectOntoDirectionVector(const QPointF &sceneVector
891884 return sceneVector.x() * m_sceneDirectionVector.x() +
892885 sceneVector.y() * m_sceneDirectionVector.y();
893886}
894−
895−// Because we are defining a new QObject-based class (RecognitionTimer) here.
896−#include "DirectionalDragArea.moc"