on xenial help sign in
Add monitorOnly support to DDA
d1cc34eMichael Terry
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+36−4
@@ -194,6 +194,26 @@ void DirectionalDragArea::setImmediateRecognition(bool enabled)
194 }
194 }
195}
195}
196
196
197+bool DirectionalDragArea::monitorOnly() const
198+{
199+ return d->monitorOnly;
200+}
201+
202+void DirectionalDragArea::setMonitorOnly(bool monitorOnly)
203+{
204+ if (d->monitorOnly != monitorOnly) {
205+ d->monitorOnly = monitorOnly;
206+
207+ if (monitorOnly && d->status == DirectionalDragAreaPrivate::Undecided) {
208+ TouchRegistry::instance()->removeCandidateOwnerForTouch(d->touchId, this);
209+ // We still wanna know when it ends for keeping the composition time window up-to-date
210+ TouchRegistry::instance()->addTouchWatcher(d->touchId, this);
211+ }
212+
213+ Q_EMIT monitorOnlyChanged(monitorOnly);
214+ }
215+}
216+
197void DirectionalDragArea::removeTimeConstraints()
217void DirectionalDragArea::removeTimeConstraints()
198{
218{
199 d->setMaxTime(60 * 60 * 1000);
219 d->setMaxTime(60 * 60 * 1000);
@@ -260,7 +280,10 @@ void DirectionalDragAreaPrivate::unownedTouchEvent(UnownedTouchEvent *unownedTou
260 unownedTouchEvent_undecided(unownedTouchEvent);
280 unownedTouchEvent_undecided(unownedTouchEvent);
261 break;
281 break;
262 default: // Recognized:
282 default: // Recognized:
263− // do nothing
283+ if (monitorOnly) {
284+ // Treat unowned event as if we owned it, but we are really just watching it
285+ touchEvent_recognized(event);
286+ }
264 break;
287 break;
265 }
288 }
266
289
@@ -311,7 +334,9 @@ void DirectionalDragAreaPrivate::unownedTouchEvent_undecided(UnownedTouchEvent *
311 }
334 }
312
335
313 if (movedFarEnoughAlongGestureAxis()) {
336 if (movedFarEnoughAlongGestureAxis()) {
337+ if (!monitorOnly) {
314− TouchRegistry::instance()->requestTouchOwnership(touchId, q);
338+ TouchRegistry::instance()->requestTouchOwnership(touchId, q);
339+ }
315 setStatus(Recognized);
340 setStatus(Recognized);
316 setPublicPos(touchPoint->pos());
341 setPublicPos(touchPoint->pos());
317 setPublicScenePos(touchScenePos);
342 setPublicScenePos(touchScenePos);
@@ -411,12 +436,18 @@ void DirectionalDragAreaPrivate::touchEvent_absent(QTouchEvent *event)
411 if (recognitionIsDisabled()) {
436 if (recognitionIsDisabled()) {
412 // Behave like a dumb TouchArea
437 // Behave like a dumb TouchArea
413 ddaDebug("Gesture recognition is disabled. Requesting touch ownership immediately.");
438 ddaDebug("Gesture recognition is disabled. Requesting touch ownership immediately.");
439+ if (!monitorOnly) {
414− TouchRegistry::instance()->requestTouchOwnership(touchId, q);
440+ TouchRegistry::instance()->requestTouchOwnership(touchId, q);
441+ }
415 setStatus(Recognized);
442 setStatus(Recognized);
416 event->accept();
443 event->accept();
417 } else {
444 } else {
418 // just monitor the touch points for now.
445 // just monitor the touch points for now.
446+ if (monitorOnly) {
447+ watchPressedTouchPoints(touchPoints);
448+ } else {
419− TouchRegistry::instance()->addCandidateOwnerForTouch(touchId, q);
449+ TouchRegistry::instance()->addCandidateOwnerForTouch(touchId, q);
450+ }
420
451
421 setStatus(Undecided);
452 setStatus(Undecided);
422 // Let the item below have it. We will monitor it and grab it later if a gesture
453 // Let the item below have it. We will monitor it and grab it later if a gesture
@@ -884,5 +915,6 @@ DirectionalDragAreaPrivate::DirectionalDragAreaPrivate(DirectionalDragArea *q)
884 , recognitionTimer(nullptr)
915 , recognitionTimer(nullptr)
885 , timeSource(new RealTimeSource)
916 , timeSource(new RealTimeSource)
886 , activeTouches(timeSource)
917 , activeTouches(timeSource)
918+ , monitorOnly(false)
887{
919{
888}
920}
plugins/Ubuntu/Gestures/DirectionalDragArea.h+8
@@ -77,6 +77,10 @@ class UBUNTUGESTURESQML_EXPORT DirectionalDragArea : public QQuickItem {
77 WRITE setImmediateRecognition
77 WRITE setImmediateRecognition
78 NOTIFY immediateRecognitionChanged)
78 NOTIFY immediateRecognitionChanged)
79
79
80+ // Whether we are merely monitoring touch events (in which case, we don't
81+ // claim ownership of the touch).
82+ Q_PROPERTY(bool monitorOnly READ monitorOnly WRITE setMonitorOnly NOTIFY monitorOnlyChanged)
83+
80 Q_ENUMS(Direction)
84 Q_ENUMS(Direction)
81public:
85public:
82 DirectionalDragArea(QQuickItem *parent = 0);
86 DirectionalDragArea(QQuickItem *parent = 0);
@@ -100,6 +104,9 @@ public:
100 bool immediateRecognition() const;
104 bool immediateRecognition() const;
101 void setImmediateRecognition(bool enabled);
105 void setImmediateRecognition(bool enabled);
102
106
107+ bool monitorOnly() const;
108+ void setMonitorOnly(bool monitorOnly);
109+
103 bool event(QEvent *e) override;
110 bool event(QEvent *e) override;
104
111
105 /*
112 /*
@@ -123,6 +130,7 @@ Q_SIGNALS:
123 void touchSceneXChanged(qreal value);
130 void touchSceneXChanged(qreal value);
124 void touchSceneYChanged(qreal value);
131 void touchSceneYChanged(qreal value);
125 void immediateRecognitionChanged(bool value);
132 void immediateRecognitionChanged(bool value);
133+ void monitorOnlyChanged(bool value);
126
134
127protected:
135protected:
128 void touchEvent(QTouchEvent *event) override;
136 void touchEvent(QTouchEvent *event) override;
plugins/Ubuntu/Gestures/DirectionalDragArea_p.h+2
@@ -160,6 +160,8 @@ public:
160
160
161 ActiveTouchesInfo activeTouches;
161 ActiveTouchesInfo activeTouches;
162
162
163+ bool monitorOnly;
164+
163Q_SIGNALS:
165Q_SIGNALS:
164 void statusChanged(Status value);
166 void statusChanged(Status value);
165};
167};