Merge lp:~dandrader/unity8/floatingFlickable into lp:unity8

Proposed by Daniel d'Andrada on 2015-04-17
Status: Merged
Approved by: Michael Zanetti on 2015-04-27
Approved revision: 1735
Merged at revision: 1779
Proposed branch: lp:~dandrader/unity8/floatingFlickable
Merge into: lp:unity8
Prerequisite: lp:~dandrader/unity8/ddaImprovements
Diff against target: 712 lines (+520/-32)
13 files modified
plugins/Ubuntu/Gestures/CMakeLists.txt (+1/-0)
plugins/Ubuntu/Gestures/Direction.cpp (+6/-3)
plugins/Ubuntu/Gestures/Direction.h (+3/-2)
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp (+3/-2)
plugins/Ubuntu/Gestures/FloatingFlickable.cpp (+150/-0)
plugins/Ubuntu/Gestures/FloatingFlickable.h (+86/-0)
plugins/Ubuntu/Gestures/plugin.cpp (+3/-1)
tests/plugins/Ubuntu/Gestures/CMakeLists.txt (+2/-1)
tests/plugins/Ubuntu/Gestures/TestItem.cpp (+30/-0)
tests/plugins/Ubuntu/Gestures/TestItem.h (+33/-0)
tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp (+122/-0)
tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml (+80/-0)
tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp (+1/-23)
To merge this branch: bzr merge lp:~dandrader/unity8/floatingFlickable
Reviewer Review Type Date Requested Status
Michael Zanetti (community) 2015-04-17 Approve on 2015-04-27
PS Jenkins bot continuous-integration Needs Fixing on 2015-04-24
Unity Team 2015-04-17 Pending
Review via email: mp+256668@code.launchpad.net

Commit Message

Introducing FloatingFlickable

Description of the Change

* Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~dandrader/unity8/ddaImprovements/+merge/255896 is a prerequisite

* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes

* Did you make sure that your branch does not contain spurious tags?
Yes

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
Not applicable

* If you changed the UI, has there been a design review?
Not applicable

To post a comment you must log in.
Michael Zanetti (mzanetti) wrote :

289+ Q_PROPERTY(Direction::Type direction READ direction WRITE setDirection NOTIFY directionChanged)

Would it make sense to keep the upstream Flickable api? Just a thought. Not insisting on this if it makes the code internally more complicated.

===

279+ A Flickable that doesn't require the item being flicked to be its child.

Should be made more clear. Also the regular flickable doesn't require the items to be childs. The main point of this is, that the items can still have mouse interaction with this one, even though they are not direct childs of the Flickable. In other words, this one is transparent to input unless it really detected a flick.

===
507+ // We shouldn't need the three lines below, but a compiz/unity7

Is this still valid or just coped from some other gesture component? IIRC it's been ages ago we were suffering from that (1.5 years or so). Is this still about the same regression?

===

Otherwise looks good. Using it in the desktop-spread and it works great.

review: Needs Information
Daniel d'Andrada (dandrader) wrote :

> 289+ Q_PROPERTY(Direction::Type direction READ direction WRITE setDirection
> NOTIFY directionChanged)
>
> Would it make sense to keep the upstream Flickable api? Just a thought. Not
> insisting on this if it makes the code internally more complicated.

I considered that, but Flickable's direction enum has more options, like vertical_and_horizontal and automatic, that DirectionalDragArea doesn't support and actually doesn't make sense for a DDA.

So all options from Flickable's direction enum I would have to drop the use of a DDA and write the touch handling from scratch for the FloatingFlickable. Totally doable but I rather avoid all this work unless we are planning those use those modes.

1733. By Daniel d'Andrada on 2015-04-24

Merge trunk

[ CI Train Bot ]
* New rebuild forced.
[ Daniel d'Andrada ]
* Tapping home key shows unity8-dash home added:
  plugins/Utils/ElapsedTimer.h plugins/Utils/HomeKeyWatcher.cpp
  plugins/Utils/HomeKeyWatcher.h plugins/Utils/Timer.cpp
  plugins/Utils/Timer.h tests/plugins/Utils/homekeywatchertest.cpp
[ Michał Sawicz ]
* Tapping home key shows unity8-dash home added:
  plugins/Utils/ElapsedTimer.h plugins/Utils/HomeKeyWatcher.cpp
  plugins/Utils/HomeKeyWatcher.h plugins/Utils/Timer.cpp
  plugins/Utils/Timer.h tests/plugins/Utils/homekeywatchertest.cpp
[ Albert Astals Cid ]
* Compile with Qt 5.5 (LP: #1437238)
* Different way of top aligning labels when the other one in the row
  is multiline (LP: #1442085)
* make pot_file
[ Andrea Cimitan ]
* Set sourceSize for DashBackground.qml Image
[ CI Train Bot ]
* New rebuild forced.
* Resync trunk. added: po/sk.po
[ Daniel d'Andrada ]
* Move handling of command line options to a separate class
* Refactor tst_PhysicalKeysMapper.qml
[ Leo Arias ]
* For autopilot tests, use the device simulation scenarios from the
  toolkit.
[ Leonardo Arias Fonseca ]
* For autopilot tests, use the device simulation scenarios from the
  toolkit.
[ Michael Zanetti ]
* Make sure dnd mode is ended properly when drag gesture is cancelled
  (LP: #1444949)
[ Michał Sawicz ]
* Fix flake8 warnings (LP: #1444170)
* Move mock indicator service to unity8-fake-env, as it's a binary-
  dependent package.
[ Nick Dedekind ]
* Use asynchronous dbus requests for property updates. (LP: #1436982)

1734. By Daniel d'Andrada on 2015-04-24

Improve documentation

Daniel d'Andrada (dandrader) wrote :

> 279+ A Flickable that doesn't require the item being flicked to be its
> child.
>
> Should be made more clear. Also the regular flickable doesn't require the
> items to be childs. The main point of this is, that the items can still have
> mouse interaction with this one, even though they are not direct childs of the
> Flickable. In other words, this one is transparent to input unless it really
> detected a flick.

Fixed

>
> ===
> 507+ // We shouldn't need the three lines below, but a compiz/unity7
>
> Is this still valid or just coped from some other gesture component? IIRC it's
> been ages ago we were suffering from that (1.5 years or so). Is this still
> about the same regression?
>

I don't know, I just copied it from tst_DirectionalDragArea. So yes, it's about the same regression.

1735. By Daniel d'Andrada on 2015-04-24

Removing unneeded workaround

Daniel d'Andrada (dandrader) wrote :

> >
> > ===
> > 507+ // We shouldn't need the three lines below, but a compiz/unity7
> >
> > Is this still valid or just coped from some other gesture component? IIRC
> it's
> > been ages ago we were suffering from that (1.5 years or so). Is this still
> > about the same regression?
> >
>
> I don't know, I just copied it from tst_DirectionalDragArea. So yes, it's
> about the same regression.

Ok, removed it.

Michael Zanetti (mzanetti) wrote :

Bad tags in this branch.

review: Needs Fixing
Daniel d'Andrada (dandrader) wrote :

On 27/04/15 07:40, Michael Zanetti wrote:
> Review: Needs Fixing
>
> Bad tags in this branch.
Fixed.

Michael Zanetti (mzanetti) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?

yes. using it in desktop-stage

 * Did CI run pass? If not, please explain why.

unrelated AP test failures

 * Did you make sure that the branch does not contain spurious tags?

y

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Ubuntu/Gestures/CMakeLists.txt'
2--- plugins/Ubuntu/Gestures/CMakeLists.txt 2015-04-24 15:23:24 +0000
3+++ plugins/Ubuntu/Gestures/CMakeLists.txt 2015-04-24 15:23:25 +0000
4@@ -7,6 +7,7 @@
5 Damper.cpp
6 Direction.cpp
7 DirectionalDragArea.cpp
8+ FloatingFlickable.cpp
9 PressedOutsideNotifier.cpp
10 TouchDispatcher.cpp
11 TouchGate.cpp
12
13=== modified file 'plugins/Ubuntu/Gestures/Direction.cpp'
14--- plugins/Ubuntu/Gestures/Direction.cpp 2014-12-05 17:06:36 +0000
15+++ plugins/Ubuntu/Gestures/Direction.cpp 2015-04-24 15:23:25 +0000
16@@ -1,5 +1,5 @@
17 /*
18- * Copyright (C) 2013 Canonical, Ltd.
19+ * Copyright (C) 2013,2015 Canonical, Ltd.
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23@@ -25,12 +25,15 @@
24
25 bool Direction::isVertical(Direction::Type type)
26 {
27- return type == Direction::Upwards || type == Direction::Downwards;
28+ return type == Direction::Upwards
29+ || type == Direction::Downwards
30+ || type == Direction::Vertical;
31 }
32
33 bool Direction::isPositive(Direction::Type type)
34 {
35 return type == Rightwards
36 || type == Downwards
37- || type == Horizontal;
38+ || type == Horizontal
39+ || type == Vertical;
40 }
41
42=== modified file 'plugins/Ubuntu/Gestures/Direction.h'
43--- plugins/Ubuntu/Gestures/Direction.h 2014-12-05 17:06:36 +0000
44+++ plugins/Ubuntu/Gestures/Direction.h 2015-04-24 15:23:25 +0000
45@@ -1,5 +1,5 @@
46 /*
47- * Copyright (C) 2013 Canonical, Ltd.
48+ * Copyright (C) 2013,2015 Canonical, Ltd.
49 *
50 * This program is free software; you can redistribute it and/or modify
51 * it under the terms of the GNU General Public License as published by
52@@ -34,7 +34,8 @@
53 Leftwards, // Along the negative direction of the X axis
54 Downwards, // Along the positive direction of the Y axis
55 Upwards, // Along the negative direction of the Y axis
56- Horizontal // Along the X axis, in any direction
57+ Horizontal, // Along the X axis, in any direction
58+ Vertical // Along the Y axis, in any direction
59 };
60
61 Q_INVOKABLE static bool isHorizontal(Direction::Type type);
62
63=== modified file 'plugins/Ubuntu/Gestures/DirectionalDragArea.cpp'
64--- plugins/Ubuntu/Gestures/DirectionalDragArea.cpp 2015-04-24 15:23:24 +0000
65+++ plugins/Ubuntu/Gestures/DirectionalDragArea.cpp 2015-04-24 15:23:25 +0000
66@@ -506,7 +506,7 @@
67
68 bool DirectionalDragAreaPrivate::movingInRightDirection() const
69 {
70- if (direction == Direction::Horizontal) {
71+ if (direction == Direction::Horizontal || direction == Direction::Vertical) {
72 return true;
73 } else {
74 QPointF movementVector(dampedScenePos.x() - previousDampedScenePos.x(),
75@@ -532,7 +532,7 @@
76 ddaDebug(" movedFarEnoughAlongGestureAxis: scalarProjection=" << scalarProjection
77 << ", distanceThreshold=" << distanceThreshold);
78
79- if (direction == Direction::Horizontal) {
80+ if (direction == Direction::Horizontal || direction == Direction::Vertical) {
81 return qAbs(scalarProjection) > distanceThreshold;
82 } else {
83 return scalarProjection > distanceThreshold;
84@@ -843,6 +843,7 @@
85 localDirection.ry() = -1.;
86 break;
87 case Direction::Downwards:
88+ case Direction::Vertical:
89 localDirection.rx() = 0.;
90 localDirection.ry() = 1;
91 break;
92
93=== added file 'plugins/Ubuntu/Gestures/FloatingFlickable.cpp'
94--- plugins/Ubuntu/Gestures/FloatingFlickable.cpp 1970-01-01 00:00:00 +0000
95+++ plugins/Ubuntu/Gestures/FloatingFlickable.cpp 2015-04-24 15:23:25 +0000
96@@ -0,0 +1,150 @@
97+/*
98+ * Copyright (C) 2015 Canonical, Ltd.
99+ *
100+ * This program is free software; you can redistribute it and/or modify
101+ * it under the terms of the GNU General Public License as published by
102+ * the Free Software Foundation; version 3.
103+ *
104+ * This program is distributed in the hope that it will be useful,
105+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
106+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107+ * GNU General Public License for more details.
108+ *
109+ * You should have received a copy of the GNU General Public License
110+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
111+ */
112+
113+#include "FloatingFlickable.h"
114+
115+#include <private/qquickflickable_p.h>
116+#include "DirectionalDragArea.h"
117+
118+#include <QDebug>
119+
120+FloatingFlickable::FloatingFlickable(QQuickItem *parent)
121+ : QQuickItem(parent)
122+ , m_mousePressed(false)
123+{
124+ m_dragArea = new DirectionalDragArea(this);
125+ m_dragArea->setWidth(width());
126+ m_dragArea->setHeight(height());
127+ m_dragArea->setDirection(Direction::Horizontal);
128+ connect(m_dragArea, &DirectionalDragArea::touchXChanged,
129+ this, &FloatingFlickable::onDragAreaTouchPosChanged);
130+ connect(m_dragArea, &DirectionalDragArea::touchYChanged,
131+ this, &FloatingFlickable::onDragAreaTouchPosChanged);
132+ connect(m_dragArea, &DirectionalDragArea::draggingChanged,
133+ this, &FloatingFlickable::onDragAreaDraggingChanged);
134+ connect(m_dragArea, &DirectionalDragArea::directionChanged, this, &FloatingFlickable::directionChanged);
135+
136+ m_flickable = new QQuickFlickable(this);
137+ m_flickable->setEnabled(false);
138+ m_flickable->setWidth(width());
139+ m_flickable->setHeight(height());
140+ connect(m_flickable, &QQuickFlickable::contentWidthChanged, this, &FloatingFlickable::contentWidthChanged);
141+ connect(m_flickable, &QQuickFlickable::contentHeightChanged, this, &FloatingFlickable::contentHeightChanged);
142+ connect(m_flickable, &QQuickFlickable::contentXChanged, this, &FloatingFlickable::contentXChanged);
143+ connect(m_flickable, &QQuickFlickable::contentYChanged, this, &FloatingFlickable::contentYChanged);
144+
145+ connect(this, &QQuickItem::widthChanged, this, &FloatingFlickable::updateChildrenWidth);
146+ connect(this, &QQuickItem::heightChanged, this, &FloatingFlickable::updateChildrenHeight);
147+}
148+
149+qreal FloatingFlickable::contentWidth() const
150+{
151+ return m_flickable->contentWidth();
152+}
153+
154+void FloatingFlickable::setContentWidth(qreal contentWidth)
155+{
156+ m_flickable->setContentWidth(contentWidth);
157+}
158+
159+qreal FloatingFlickable::contentHeight() const
160+{
161+ return m_flickable->contentHeight();
162+}
163+
164+void FloatingFlickable::setContentHeight(qreal contentHeight)
165+{
166+ m_flickable->setContentHeight(contentHeight);
167+}
168+
169+qreal FloatingFlickable::contentX() const
170+{
171+ return m_flickable->contentX();
172+}
173+
174+void FloatingFlickable::setContentX(qreal contentX)
175+{
176+ m_flickable->setContentX(contentX);
177+}
178+
179+qreal FloatingFlickable::contentY() const
180+{
181+ return m_flickable->contentY();
182+}
183+
184+void FloatingFlickable::setContentY(qreal contentY)
185+{
186+ m_flickable->setContentY(contentY);
187+}
188+
189+Direction::Type FloatingFlickable::direction() const
190+{
191+ return m_dragArea->direction();
192+}
193+
194+void FloatingFlickable::setDirection(Direction::Type direction)
195+{
196+ m_dragArea->setDirection(direction);
197+ if (Direction::isHorizontal(direction)) {
198+ m_flickable->setFlickableDirection(QQuickFlickable::HorizontalFlick);
199+ } else {
200+ m_flickable->setFlickableDirection(QQuickFlickable::VerticalFlick);
201+ }
202+}
203+
204+void FloatingFlickable::updateChildrenWidth()
205+{
206+ m_dragArea->setWidth(width());
207+ m_flickable->setWidth(width());
208+}
209+
210+void FloatingFlickable::updateChildrenHeight()
211+{
212+ m_dragArea->setHeight(height());
213+ m_flickable->setHeight(height());
214+}
215+
216+void FloatingFlickable::onDragAreaTouchPosChanged(qreal)
217+{
218+ if (m_mousePressed) {
219+ QMouseEvent mouseEvent(QEvent::MouseMove,
220+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
221+ Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
222+
223+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
224+
225+ }
226+}
227+
228+void FloatingFlickable::onDragAreaDraggingChanged(bool dragging)
229+{
230+ if (dragging && !m_mousePressed) {
231+ QMouseEvent mouseEvent(QEvent::MouseButtonPress,
232+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
233+ Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
234+
235+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
236+ m_mousePressed = true;
237+
238+ } else if (!dragging && m_mousePressed) {
239+ QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
240+ QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
241+ Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
242+
243+ QCoreApplication::sendEvent(m_flickable, &mouseEvent);
244+ m_mousePressed = false;
245+ }
246+}
247
248=== added file 'plugins/Ubuntu/Gestures/FloatingFlickable.h'
249--- plugins/Ubuntu/Gestures/FloatingFlickable.h 1970-01-01 00:00:00 +0000
250+++ plugins/Ubuntu/Gestures/FloatingFlickable.h 2015-04-24 15:23:25 +0000
251@@ -0,0 +1,86 @@
252+/*
253+ * Copyright (C) 2015 Canonical, Ltd.
254+ *
255+ * This program is free software; you can redistribute it and/or modify
256+ * it under the terms of the GNU General Public License as published by
257+ * the Free Software Foundation; version 3.
258+ *
259+ * This program is distributed in the hope that it will be useful,
260+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
261+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262+ * GNU General Public License for more details.
263+ *
264+ * You should have received a copy of the GNU General Public License
265+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
266+ */
267+
268+#ifndef FLOATING_FLICKABLE_H
269+#define FLOATING_FLICKABLE_H
270+
271+#include <QQuickItem>
272+#include "UbuntuGesturesQmlGlobal.h"
273+#include "Direction.h"
274+
275+class DirectionalDragArea;
276+class QQuickFlickable;
277+
278+/*
279+ A Flickable that can be put in front of the item to be flicked and
280+ still have the item-to-be-flicked receive input events that are not flicks.
281+
282+ Ie, it's a Flickable that, input-wise, is transparent to non-flick gestures.
283+
284+ With a regular Flickable you would have to make the item-to-be-flicked a child
285+ of Flicakble to achieve the same result. FloatingFlickable has no such requirement
286+ or limitation.
287+ */
288+class UBUNTUGESTURESQML_EXPORT FloatingFlickable : public QQuickItem {
289+ Q_OBJECT
290+
291+ Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
292+ Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
293+ Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
294+ Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
295+
296+ Q_PROPERTY(Direction::Type direction READ direction WRITE setDirection NOTIFY directionChanged)
297+
298+Q_SIGNALS:
299+ void contentWidthChanged();
300+ void contentHeightChanged();
301+ void contentXChanged();
302+ void contentYChanged();
303+ void directionChanged();
304+
305+public:
306+ FloatingFlickable(QQuickItem *parent = nullptr);
307+
308+ qreal contentWidth() const;
309+ void setContentWidth(qreal contentWidth);
310+
311+ qreal contentHeight() const;
312+ void setContentHeight(qreal contentHeight);
313+
314+ qreal contentX() const;
315+ void setContentX(qreal contentX);
316+
317+ qreal contentY() const;
318+ void setContentY(qreal contentY);
319+
320+ Direction::Type direction() const;
321+ void setDirection(Direction::Type);
322+
323+private Q_SLOTS:
324+ void updateChildrenWidth();
325+ void updateChildrenHeight();
326+ void onDragAreaTouchPosChanged(qreal);
327+ void onDragAreaDraggingChanged(bool value);
328+
329+private:
330+ DirectionalDragArea *m_dragArea;
331+ QQuickFlickable *m_flickable;
332+ bool m_mousePressed;
333+
334+ friend class tst_FloatingFlickable;
335+};
336+
337+#endif // FLOATING_FLICKABLE_H
338
339=== modified file 'plugins/Ubuntu/Gestures/plugin.cpp'
340--- plugins/Ubuntu/Gestures/plugin.cpp 2014-10-01 13:20:32 +0000
341+++ plugins/Ubuntu/Gestures/plugin.cpp 2015-04-24 15:23:25 +0000
342@@ -1,5 +1,5 @@
343 /*
344- * Copyright (C) 2013 Canonical, Ltd.
345+ * Copyright (C) 2013,2015 Canonical, Ltd.
346 *
347 * This program is free software; you can redistribute it and/or modify
348 * it under the terms of the GNU General Public License as published by
349@@ -18,6 +18,7 @@
350 #include "AxisVelocityCalculator.h"
351 #include "Direction.h"
352 #include "DirectionalDragArea.h"
353+#include "FloatingFlickable.h"
354 #include "PressedOutsideNotifier.h"
355 #include "TouchGate.h"
356
357@@ -34,6 +35,7 @@
358 qmlRegisterSingletonType<Direction>(uri, 0, 1, "Direction", directionSingleton);
359 qmlRegisterType<DirectionalDragArea>(uri, 0, 1, "DirectionalDragArea");
360 qmlRegisterType<AxisVelocityCalculator>(uri, 0, 1, "AxisVelocityCalculator");
361+ qmlRegisterType<FloatingFlickable>(uri, 0, 1, "FloatingFlickable");
362 qmlRegisterType<PressedOutsideNotifier>(uri, 0, 1, "PressedOutsideNotifier");
363 qmlRegisterType<TouchGate>(uri, 0, 1, "TouchGate");
364 }
365
366=== modified file 'tests/plugins/Ubuntu/Gestures/CMakeLists.txt'
367--- tests/plugins/Ubuntu/Gestures/CMakeLists.txt 2015-04-24 15:23:24 +0000
368+++ tests/plugins/Ubuntu/Gestures/CMakeLists.txt 2015-04-24 15:23:25 +0000
369@@ -22,7 +22,7 @@
370 add_definitions(-DTESTS_UTILS_MODULES_DIR="${CMAKE_BINARY_DIR}/tests/utils/modules")
371
372 macro(add_gesture_ui_test CLASSNAME)
373- add_executable(${CLASSNAME}TestExec tst_${CLASSNAME}.cpp GestureTest.cpp)
374+ add_executable(${CLASSNAME}TestExec tst_${CLASSNAME}.cpp GestureTest.cpp TestItem.cpp)
375 qt5_use_modules(${CLASSNAME}TestExec Test Core Qml Gui Quick)
376 target_link_libraries(${CLASSNAME}TestExec UbuntuGesturesQml UbuntuGestures)
377
378@@ -46,6 +46,7 @@
379 endmacro(add_gesture_test)
380
381 add_gesture_ui_test(DirectionalDragArea)
382+add_gesture_ui_test(FloatingFlickable)
383 add_gesture_ui_test(PressedOutsideNotifier)
384 add_gesture_ui_test(TouchDispatcher)
385 add_gesture_ui_test(TouchGate)
386
387=== added file 'tests/plugins/Ubuntu/Gestures/TestItem.cpp'
388--- tests/plugins/Ubuntu/Gestures/TestItem.cpp 1970-01-01 00:00:00 +0000
389+++ tests/plugins/Ubuntu/Gestures/TestItem.cpp 2015-04-24 15:23:25 +0000
390@@ -0,0 +1,30 @@
391+/*
392+ * Copyright (C) 2015 Canonical, Ltd.
393+ *
394+ * This program is free software; you can redistribute it and/or modify
395+ * it under the terms of the GNU General Public License as published by
396+ * the Free Software Foundation; version 3.
397+ *
398+ * This program is distributed in the hope that it will be useful,
399+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
400+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
401+ * GNU General Public License for more details.
402+ *
403+ * You should have received a copy of the GNU General Public License
404+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
405+ */
406+
407+#include "TestItem.h"
408+
409+#include <QTouchEvent>
410+
411+void TestItem::touchEvent(QTouchEvent *event)
412+{
413+ QTouchEvent *clonedEvent = new QTouchEvent(event->type(),
414+ event->device(),
415+ event->modifiers(),
416+ event->touchPointStates(),
417+ event->touchPoints());
418+
419+ touchEventsReceived.append(QSharedPointer<QTouchEvent>(clonedEvent));
420+}
421
422=== added file 'tests/plugins/Ubuntu/Gestures/TestItem.h'
423--- tests/plugins/Ubuntu/Gestures/TestItem.h 1970-01-01 00:00:00 +0000
424+++ tests/plugins/Ubuntu/Gestures/TestItem.h 2015-04-24 15:23:25 +0000
425@@ -0,0 +1,33 @@
426+/*
427+ * Copyright (C) 2015 Canonical, Ltd.
428+ *
429+ * This program is free software; you can redistribute it and/or modify
430+ * it under the terms of the GNU General Public License as published by
431+ * the Free Software Foundation; version 3.
432+ *
433+ * This program is distributed in the hope that it will be useful,
434+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
435+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
436+ * GNU General Public License for more details.
437+ *
438+ * You should have received a copy of the GNU General Public License
439+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
440+ */
441+
442+#ifndef UBUNTUGESTURES_TEST_ITEM_H
443+#define UBUNTUGESTURES_TEST_ITEM_H
444+
445+#include <QQuickItem>
446+
447+class TestItem : public QQuickItem
448+{
449+ Q_OBJECT
450+
451+public:
452+ QList<QSharedPointer<QTouchEvent>> touchEventsReceived;
453+
454+protected:
455+ void touchEvent(QTouchEvent *event) override;
456+};
457+
458+#endif // UBUNTUGESTURES_TEST_ITEM_H
459
460=== added file 'tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp'
461--- tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp 1970-01-01 00:00:00 +0000
462+++ tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp 2015-04-24 15:23:25 +0000
463@@ -0,0 +1,122 @@
464+/*
465+ * Copyright (C) 2015 Canonical, Ltd.
466+ *
467+ * This program is free software; you can redistribute it and/or modify
468+ * it under the terms of the GNU General Public License as published by
469+ * the Free Software Foundation; version 3.
470+ *
471+ * This program is distributed in the hope that it will be useful,
472+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
473+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
474+ * GNU General Public License for more details.
475+ *
476+ * You should have received a copy of the GNU General Public License
477+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
478+ */
479+
480+#include <QtTest>
481+#include <QQuickView>
482+
483+// Ubuntu.Gestures plugin
484+#include <DirectionalDragArea.h>
485+#include <FloatingFlickable.h>
486+
487+#include "GestureTest.h"
488+#include "TestItem.h"
489+
490+using namespace UbuntuGestures;
491+
492+class tst_FloatingFlickable: public GestureTest
493+{
494+ Q_OBJECT
495+public:
496+ tst_FloatingFlickable();
497+private Q_SLOTS:
498+ void tapGoesThrough();
499+ void flickChangesContentX();
500+ void flickChangesContentY();
501+};
502+
503+tst_FloatingFlickable::tst_FloatingFlickable()
504+ : GestureTest(QStringLiteral("tst_FloatingFlickable.qml"))
505+{
506+}
507+
508+void tst_FloatingFlickable::tapGoesThrough()
509+{
510+ FloatingFlickable *floatingFlickable =
511+ m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
512+ QVERIFY(floatingFlickable != nullptr);
513+
514+ TestItem *testItem = new TestItem;
515+ testItem->setWidth(floatingFlickable->width());
516+ testItem->setHeight(floatingFlickable->height());
517+ testItem->setParentItem(m_view->rootObject());
518+ testItem->setZ(1.0);
519+
520+ floatingFlickable->setZ(2.0);
521+
522+ QTest::touchEvent(m_view, m_device)
523+ .press(0, QPoint(floatingFlickable->width()/2, floatingFlickable->height()/2));
524+
525+ QCOMPARE(testItem->touchEventsReceived.count(), 1);
526+}
527+
528+void tst_FloatingFlickable::flickChangesContentX()
529+{
530+ FloatingFlickable *floatingFlickable =
531+ m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
532+ QVERIFY(floatingFlickable != nullptr);
533+
534+ floatingFlickable->m_dragArea->removeTimeConstraints();
535+
536+ qreal startContentX = floatingFlickable->contentX();
537+
538+ QPoint startPos(floatingFlickable->width() - 5, 10);
539+ int stepCount = 20;
540+ int step = (startPos.x() - 5) / stepCount;
541+
542+ QTest::touchEvent(m_view, m_device).press(0, startPos);
543+ for (int i = 0; i < stepCount; ++i) {
544+ QTest::qWait(10);
545+ QPoint touchPos = startPos - QPoint(step*i, 0);
546+ QTest::touchEvent(m_view, m_device).move(0, touchPos);
547+ }
548+
549+ QTest::qWait(10);
550+ QTest::touchEvent(m_view, m_device).release(0, QPoint(5, 10));
551+
552+ QVERIFY(floatingFlickable->contentX() > (startContentX + floatingFlickable->width()/2));
553+}
554+
555+void tst_FloatingFlickable::flickChangesContentY()
556+{
557+ FloatingFlickable *floatingFlickable =
558+ m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
559+ QVERIFY(floatingFlickable != nullptr);
560+
561+ floatingFlickable->setDirection(Direction::Vertical);
562+ floatingFlickable->m_dragArea->removeTimeConstraints();
563+
564+ qreal startContentY = floatingFlickable->contentY();
565+
566+ QPoint startPos(10, floatingFlickable->height() - 5);
567+ int stepCount = 20;
568+ int step = (startPos.y() - 5) / stepCount;
569+
570+ QTest::touchEvent(m_view, m_device).press(0, startPos);
571+ for (int i = 0; i < stepCount; ++i) {
572+ QTest::qWait(10);
573+ QPoint touchPos = startPos - QPoint(0, step*i);
574+ QTest::touchEvent(m_view, m_device).move(0, touchPos);
575+ }
576+
577+ QTest::qWait(10);
578+ QTest::touchEvent(m_view, m_device).release(0, QPoint(10, 5));
579+
580+ QVERIFY(floatingFlickable->contentY() > (startContentY + floatingFlickable->height()/2));
581+}
582+
583+QTEST_MAIN(tst_FloatingFlickable)
584+
585+#include "tst_FloatingFlickable.moc"
586
587=== added file 'tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml'
588--- tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml 1970-01-01 00:00:00 +0000
589+++ tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml 2015-04-24 15:23:25 +0000
590@@ -0,0 +1,80 @@
591+/*
592+ * Copyright (C) 2015 Canonical, Ltd.
593+ *
594+ * This program is free software; you can redistribute it and/or modify
595+ * it under the terms of the GNU General Public License as published by
596+ * the Free Software Foundation; version 3.
597+ *
598+ * This program is distributed in the hope that it will be useful,
599+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
600+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
601+ * GNU General Public License for more details.
602+ *
603+ * You should have received a copy of the GNU General Public License
604+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
605+ */
606+
607+import QtQuick 2.0
608+import Ubuntu.Components 0.1
609+import Ubuntu.Gestures 0.1
610+import Unity.Test 0.1
611+
612+Rectangle {
613+ id: root
614+ width: units.gu(60)
615+ height: units.gu(60)
616+ color: "white"
617+
618+ Binding {
619+ target: MouseTouchAdaptor
620+ property: "enabled"
621+ value: true
622+ }
623+
624+ Grid {
625+ id: colorGrid
626+ readonly property bool horizontal: floatingFlickable.direction === Direction.Horizontal
627+ x: horizontal ? -floatingFlickable.contentX : 0
628+ y: horizontal ? 0 : -floatingFlickable.contentY
629+ rows: horizontal ? 1 : 100
630+ columns: horizontal ? 100 : 1
631+ Repeater {
632+ model: 100
633+ Rectangle {
634+ width: colorGrid.horizontal ? units.gu(12) : root.width
635+ height: colorGrid.horizontal ? root.height : units.gu(12)
636+ color: mouseArea.pressed ? "red"
637+ : Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
638+ MouseArea {
639+ id: mouseArea
640+ anchors.fill: parent
641+ }
642+ }
643+ }
644+ }
645+
646+ FloatingFlickable {
647+ id: floatingFlickable
648+ objectName: "floatingFlickable"
649+ anchors.fill: parent
650+ contentWidth: colorGrid.width
651+ contentHeight: colorGrid.height
652+ }
653+
654+ Button {
655+ anchors.bottom: parent.bottom
656+ anchors.right: parent.right
657+ anchors.margins: units.gu(1)
658+
659+ text: floatingFlickable.direction === Direction.Horizontal ? "Horizontal" : "Vertical"
660+ activeFocusOnPress: false
661+
662+ onClicked: {
663+ if (floatingFlickable.direction === Direction.Horizontal) {
664+ floatingFlickable.direction = Direction.Vertical;
665+ } else {
666+ floatingFlickable.direction = Direction.Horizontal;
667+ }
668+ }
669+ }
670+}
671
672=== modified file 'tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp'
673--- tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp 2015-04-24 15:23:24 +0000
674+++ tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp 2015-04-24 15:23:25 +0000
675@@ -29,16 +29,7 @@
676 #include <TouchGate.h>
677 #include <TouchRegistry.h>
678
679-class TestItem : public QQuickItem
680-{
681- Q_OBJECT
682-
683-public:
684- QList<QSharedPointer<QTouchEvent>> touchEventsReceived;
685-
686-protected:
687- void touchEvent(QTouchEvent *event) override;
688-};
689+#include "TestItem.h"
690
691 class CandidateItem : public QQuickItem
692 {
693@@ -381,19 +372,6 @@
694 }
695 }
696
697-///////////// TestItem /////////////////////////////////////////////////////////////
698-
699-void TestItem::touchEvent(QTouchEvent *event)
700-{
701- QTouchEvent *clonedEvent = new QTouchEvent(event->type(),
702- event->device(),
703- event->modifiers(),
704- event->touchPointStates(),
705- event->touchPoints());
706-
707- touchEventsReceived.append(QSharedPointer<QTouchEvent>(clonedEvent));
708-}
709-
710 ///////////// CandidateItem /////////////////////////////////////////////////////////////
711
712 void CandidateItem::touchEvent(QTouchEvent *event)

Subscribers

People subscribed via source and target branches