on xenial help sign in
Add monitorOnly support to DDA
commitd1cc34e281e9005bda1443ae94249cf3b7d77a31 authorMichael Terry <michael.terry@canonical.com> dateFri 13 Nov 2015, 14:00 (11 years ago) parent45fca23
3 files changed+46−4
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+36−4 plugins/Ubuntu/Gestures/DirectionalDragArea.h+8 plugins/Ubuntu/Gestures/DirectionalDragArea_p.h+2
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+36−4
@@ -194,6 +194,26 @@ void DirectionalDragArea::setImmediateRecognition(bool enabled)
194194 }
195195}
196196
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+
197217void DirectionalDragArea::removeTimeConstraints()
198218{
199219 d->setMaxTime(60 * 60 * 1000);
@@ -260,7 +280,10 @@ void DirectionalDragAreaPrivate::unownedTouchEvent(UnownedTouchEvent *unownedTou
260280 unownedTouchEvent_undecided(unownedTouchEvent);
261281 break;
262282 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+ }
264287 break;
265288 }
266289
@@ -311,7 +334,9 @@ void DirectionalDragAreaPrivate::unownedTouchEvent_undecided(UnownedTouchEvent *
311334 }
312335
313336 if (movedFarEnoughAlongGestureAxis()) {
314− TouchRegistry::instance()->requestTouchOwnership(touchId, q);
337+ if (!monitorOnly) {
338+ TouchRegistry::instance()->requestTouchOwnership(touchId, q);
339+ }
315340 setStatus(Recognized);
316341 setPublicPos(touchPoint->pos());
317342 setPublicScenePos(touchScenePos);
@@ -411,12 +436,18 @@ void DirectionalDragAreaPrivate::touchEvent_absent(QTouchEvent *event)
411436 if (recognitionIsDisabled()) {
412437 // Behave like a dumb TouchArea
413438 ddaDebug("Gesture recognition is disabled. Requesting touch ownership immediately.");
414− TouchRegistry::instance()->requestTouchOwnership(touchId, q);
439+ if (!monitorOnly) {
440+ TouchRegistry::instance()->requestTouchOwnership(touchId, q);
441+ }
415442 setStatus(Recognized);
416443 event->accept();
417444 } else {
418445 // just monitor the touch points for now.
419− TouchRegistry::instance()->addCandidateOwnerForTouch(touchId, q);
446+ if (monitorOnly) {
447+ watchPressedTouchPoints(touchPoints);
448+ } else {
449+ TouchRegistry::instance()->addCandidateOwnerForTouch(touchId, q);
450+ }
420451
421452 setStatus(Undecided);
422453 // 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)
884915 , recognitionTimer(nullptr)
885916 , timeSource(new RealTimeSource)
886917 , activeTouches(timeSource)
918+ , monitorOnly(false)
887919{
888920}
plugins/Ubuntu/Gestures/DirectionalDragArea.h+8
@@ -77,6 +77,10 @@ class UBUNTUGESTURESQML_EXPORT DirectionalDragArea : public QQuickItem {
7777 WRITE setImmediateRecognition
7878 NOTIFY immediateRecognitionChanged)
7979
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+
8084 Q_ENUMS(Direction)
8185public:
8286 DirectionalDragArea(QQuickItem *parent = 0);
@@ -100,6 +104,9 @@ public:
100104 bool immediateRecognition() const;
101105 void setImmediateRecognition(bool enabled);
102106
107+ bool monitorOnly() const;
108+ void setMonitorOnly(bool monitorOnly);
109+
103110 bool event(QEvent *e) override;
104111
105112 /*
@@ -123,6 +130,7 @@ Q_SIGNALS:
123130 void touchSceneXChanged(qreal value);
124131 void touchSceneYChanged(qreal value);
125132 void immediateRecognitionChanged(bool value);
133+ void monitorOnlyChanged(bool value);
126134
127135protected:
128136 void touchEvent(QTouchEvent *event) override;
plugins/Ubuntu/Gestures/DirectionalDragArea_p.h+2
@@ -160,6 +160,8 @@ public:
160160
161161 ActiveTouchesInfo activeTouches;
162162
163+ bool monitorOnly;
164+
163165Q_SIGNALS:
164166 void statusChanged(Status value);
165167};