Merge lp:~fboucault/ubuntu-ui-toolkit/list_item_swipe_position into lp:ubuntu-ui-toolkit/staging

Proposed by Florian Boucault on 2016-10-14
Status: Needs review
Proposed branch: lp:~fboucault/ubuntu-ui-toolkit/list_item_swipe_position
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 277 lines (+108/-20)
5 files modified
components.api (+1/-0)
src/UbuntuToolkit/uclistitem.cpp (+54/-0)
src/UbuntuToolkit/uclistitem_p.h (+4/-0)
tests/unit/visual/tst_listitem.13.qml (+21/-8)
tests/unit/visual/tst_listitem_extras.13.qml (+28/-12)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-toolkit/list_item_swipe_position
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Needs Fixing on 2016-10-15
Zsombor Egri 2016-10-14 Approve on 2016-10-15
Review via email: mp+308495@code.launchpad.net

Commit message

Added new property to ListItem: real swipePosition

Description of the change

Added new property to ListItem: real swipePosition

To post a comment you must log in.
Zsombor Egri (zsombi) wrote :

Looks good, krillin is again OoO :/ Hopefully autolanding will get it.

review: Approve

Unmerged revisions

2144. By Florian Boucault on 2016-10-14

Fix some unit tests

2143. By Florian Boucault on 2016-10-14

Added basic unit tests for ListItem.swipePosition

2142. By Florian Boucault on 2016-10-14

Added more unit tests for ListItem.swipePosition

2141. By Florian Boucault on 2016-10-13

Added new property to API

2140. By Florian Boucault on 2016-10-11

Preliminary implementation of ListItem::swipePosition

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2016-09-17 05:48:25 +0000
3+++ components.api 2016-10-14 12:12:03 +0000
4@@ -612,6 +612,7 @@
5 property bool selectMode
6 property bool selected
7 property bool swipeEnabled 1.3
8+ property double swipePosition 1.3
9 readonly property bool swiped 1.3
10 property ListItemActions trailingActions
11 Ubuntu.Components.ListItemActions 1.2 UCListItemActions: QtObject
12
13=== modified file 'src/UbuntuToolkit/uclistitem.cpp'
14--- src/UbuntuToolkit/uclistitem.cpp 2016-09-20 06:24:44 +0000
15+++ src/UbuntuToolkit/uclistitem.cpp 2016-10-14 12:12:03 +0000
16@@ -509,6 +509,8 @@
17 if (event.m_contentPos != contentItem->position()) {
18 contentItem->setPosition(event.m_contentPos);
19 lastPos = localPos;
20+ Q_Q(UCListItem);
21+ q->swipePositionChanged();
22 if (status == UCSwipeEvent::Updated) {
23 setContentMoving(true);
24 setSwiped(true);
25@@ -2009,6 +2011,58 @@
26 }
27
28 /*!
29+ * \qmlproperty bool ListItem::swipePosition
30+ * \since Ubuntu.Components 1.3
31+ * The property controls the swiping of the leading- or trailing actions. This
32+ * is useful when swiping needs to be triggered programatically, for example
33+ * when demonstrating that actions are present and can be swiped.
34+ * \qml
35+ * import QtQuick 2.4
36+ * import Ubuntu.Components 1.3
37+ *
38+ * ListItem {
39+ * id: listItem
40+ *
41+ * leadingActions: ListItemActions {
42+ * actions: [
43+ * Action {
44+ * iconName: "delete"
45+ * }
46+ * ]
47+ * }
48+ *
49+ * UbuntuNumberAnimation {
50+ * target: listItem
51+ * property: "swipePosition"
52+ * to: units.gu(8)
53+ * }
54+ * }
55+ * \endqml
56+ */
57+qreal UCListItem::swipePosition() const
58+{
59+ Q_D(const UCListItem);
60+ return d->contentItem->position().x();
61+}
62+void UCListItem::setSwipePosition(qreal swipePosition)
63+{
64+ Q_D(UCListItem);
65+ if (!d->leadingActions || !d->trailingActions) {
66+ return;
67+ }
68+ if (d->contentItem->position().x() == swipePosition) {
69+ return;
70+ }
71+
72+ d->setSwiped(true);
73+ d->lockContentItem(false);
74+ d->loadStyleItem();
75+ d->lastPos = QPointF(0.0, 0.0);
76+ QPointF localPos(swipePosition, 0.0);
77+ d->swipeEvent(localPos, UCSwipeEvent::Updated);
78+}
79+
80+/*!
81 * \qmlproperty bool ListItem::swiped
82 * \readonly
83 * \since Ubuntu.Components 1.3
84
85=== modified file 'src/UbuntuToolkit/uclistitem_p.h'
86--- src/UbuntuToolkit/uclistitem_p.h 2016-09-16 05:01:13 +0000
87+++ src/UbuntuToolkit/uclistitem_p.h 2016-10-14 12:12:03 +0000
88@@ -66,6 +66,7 @@
89 #endif
90 Q_PROPERTY(bool swipeEnabled READ isSwipeEnabled WRITE setSwipeEnabled NOTIFY swipeEnabledChanged FINAL REVISION 1)
91 Q_PROPERTY(bool swiped READ isSwiped NOTIFY swipedChanged FINAL REVISION 1)
92+ Q_PROPERTY(qreal swipePosition READ swipePosition WRITE setSwipePosition NOTIFY swipePositionChanged FINAL REVISION 1)
93 public:
94 explicit UCListItem(QQuickItem *parent = 0);
95 ~UCListItem();
96@@ -89,6 +90,8 @@
97 UCListItemExpansion *expansion();
98 bool isSwipeEnabled() const;
99 void setSwipeEnabled(bool swipeEnabled);
100+ qreal swipePosition() const;
101+ void setSwipePosition(qreal swipePosition);
102 bool isSwiped();
103
104 protected:
105@@ -123,6 +126,7 @@
106 void listItemChildrenChanged();
107 Q_REVISION(1) void swipeEnabledChanged();
108 Q_REVISION(1) void swipedChanged();
109+ Q_REVISION(1) void swipePositionChanged();
110
111 void clicked();
112 void pressAndHold();
113
114=== modified file 'tests/unit/visual/tst_listitem.13.qml'
115--- tests/unit/visual/tst_listitem.13.qml 2016-10-06 11:22:26 +0000
116+++ tests/unit/visual/tst_listitem.13.qml 2016-10-14 12:12:03 +0000
117@@ -263,6 +263,7 @@
118 compare(defaults.__styleInstance, null, "__styleInstance must be null.");
119 compare(defaults.selected, false, "Not selected by default");
120 compare(defaults.selectMode, false, "Not selectable by default");
121+ compare(defaults.swipePosition, 0, "swipePosition must be 0 by default");
122 compare(testColumn.ViewItems.selectMode, false, "The parent attached property is not selectable by default");
123 compare(testColumn.ViewItems.selectedIndices.length, 0, "No item is selected by default");
124 compare(listView.ViewItems.dragMode, false, "Drag mode is off on ListView");
125@@ -423,16 +424,20 @@
126 function test_tug_actions_data() {
127 var item = findChild(listView, "listItem0");
128 return [
129- {tag: "Trailing, mouse", item: item, pos: centerOf(item), dx: -units.gu(20), positiveDirection: false, mouse: true},
130- {tag: "Leading, mouse", item: item, pos: centerOf(item), dx: units.gu(20), positiveDirection: true, mouse: true},
131- {tag: "Trailing, touch", item: item, pos: centerOf(item), dx: -units.gu(20), positiveDirection: false, mouse: false},
132- {tag: "Leading, touch", item: item, pos: centerOf(item), dx: units.gu(20), positiveDirection: true, mouse: false},
133+ {tag: "Trailing, mouse", item: item, pos: centerOf(item), dx: -units.gu(20), positiveDirection: false, mouse: true, swipePosition: false},
134+ {tag: "Leading, mouse", item: item, pos: centerOf(item), dx: units.gu(20), positiveDirection: true, mouse: true, swipePosition: false},
135+ {tag: "Trailing, touch", item: item, pos: centerOf(item), dx: -units.gu(20), positiveDirection: false, mouse: false, swipePosition: false},
136+ {tag: "Leading, touch", item: item, pos: centerOf(item), dx: units.gu(20), positiveDirection: true, mouse: false, swipePosition: false},
137+ {tag: "Trailing, swipePosition", item: item, pos: centerOf(item), dx: -units.gu(20), positiveDirection: false, mouse: false, swipePosition: true},
138+ {tag: "Leading, swipePosition", item: item, pos: centerOf(item), dx: units.gu(20), positiveDirection: true, mouse: false, swipePosition: true},
139 ];
140 }
141 function test_tug_actions(data) {
142 listView.positionViewAtBeginning();
143 if (data.mouse) {
144 swipe(data.item, data.pos.x, data.pos.y, data.dx, 0);
145+ } else if (data.swipePosition) {
146+ data.item.swipePosition = data.dx;
147 } else {
148 tug(data.item, data.pos.x, data.pos.y, data.dx, 0);
149 }
150@@ -458,16 +463,20 @@
151 var item0 = findChild(listView, "listItem0");
152 var item1 = findChild(listView, "listItem1");
153 return [
154- {tag: "Click on an other Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: true},
155- {tag: "Click on the same Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item0, mouse: true},
156- {tag: "Tap on an other Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: false},
157- {tag: "Tap on the same Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item0, mouse: false},
158+ {tag: "Click on an other Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: true, swipePosition: false},
159+ {tag: "Click on the same Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item0, mouse: true, swipePosition: false},
160+ {tag: "Tap on an other Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: false, swipePosition: false},
161+ {tag: "Tap on the same Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item0, mouse: false, swipePosition: false},
162+ {tag: "Set swipePosition then click on an other Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: false, swipePosition: true},
163+ {tag: "Set swipePosition then click on the same Item", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item0, mouse: false, swipePosition: true},
164 ];
165 }
166 function test_rebound_when_pressed_outside_or_clicked(data) {
167 listView.positionViewAtBeginning();
168 if (data.mouse) {
169 swipe(data.item, data.pos.x, data.pos.y, data.dx, 0);
170+ } else if (data.swipePosition) {
171+ data.item.swipePosition = data.dx;
172 } else {
173 tug(data.item, data.pos.x, data.pos.y, data.dx, 0);
174 }
175@@ -484,6 +493,8 @@
176 {tag: "Leading", item: item0, pos: centerOf(item0), dx: units.gu(20), clickOn: item0.contentItem, mouse: true},
177 {tag: "Trailing", item: item0, pos: centerOf(item0), dx: -units.gu(20), clickOn: item1, mouse: false},
178 {tag: "Leading", item: item0, pos: centerOf(item0), dx: units.gu(20), clickOn: item0.contentItem, mouse: false},
179+ {tag: "Trailing, swipePosition", item: item0, pos: centerOf(item0), dx: -units.gu(10), clickOn: item1, mouse: false, swipePosition: true},
180+ {tag: "Leading, swipePosition", item: item0, pos: centerOf(item0), dx: units.gu(10), clickOn: item0.contentItem, mouse: false, swipePosition: true},
181 ];
182 }
183 function test_listview_not_interactive_while_tugged(data) {
184@@ -492,6 +503,8 @@
185 compare(listView.interactive, true, "ListView is not interactive");
186 if (data.mouse) {
187 swipe(data.item, data.pos.x, data.pos.y, data.dx, units.gu(5));
188+ } else if (data.swipePosition) {
189+ data.item.swipePosition = data.dx;
190 } else {
191 tug(data.item, data.pos.x, data.pos.y, data.dx, units.gu(5));
192 }
193
194=== modified file 'tests/unit/visual/tst_listitem_extras.13.qml'
195--- tests/unit/visual/tst_listitem_extras.13.qml 2016-06-15 13:46:51 +0000
196+++ tests/unit/visual/tst_listitem_extras.13.qml 2016-10-14 12:12:03 +0000
197@@ -215,17 +215,25 @@
198
199 function test_button_inactive_while_swiped_data() {
200 return [
201- {tag: "mouse", touch: false, dx: units.gu(20)},
202- {tag: "touch", touch: true, dx: units.gu(20)},
203+ {tag: "mouse", touch: false, swipePosition: false, dx: units.gu(20)},
204+ {tag: "touch", touch: true, swipePosition: false, dx: units.gu(20)},
205+ {tag: "swipePosition", touch: false, swipePosition: true, dx: units.gu(20)},
206+ {tag: "swipePosition", touch: true, swipePosition: true, dx: units.gu(20)},
207 ];
208 }
209 function test_button_inactive_while_swiped(data) {
210 clickSpy.target = activeItem;
211+ if (data.swipePosition) {
212+ testWithActiveItem.swipePosition = data.dx;
213+ } else if (data.touch) {
214+ tug(testWithActiveItem, centerOf(testWithActiveItem).x, centerOf(testWithActiveItem).y, data.dx, 0);
215+ } else {
216+ swipe(testWithActiveItem, centerOf(testWithActiveItem).x, centerOf(testWithActiveItem).y, data.dx, 0);
217+ }
218+
219 if (data.touch) {
220- tug(testWithActiveItem, centerOf(testWithActiveItem).x, centerOf(testWithActiveItem).y, data.dx, 0);
221 TestExtras.touchClick(0, activeItem, centerOf(activeItem));
222 } else {
223- swipe(testWithActiveItem, centerOf(testWithActiveItem).x, centerOf(testWithActiveItem).y, data.dx, 0);
224 mouseClick(activeItem, centerOf(activeItem).x, centerOf(activeItem).y);
225 }
226 expectFail(data.tag, "Button is inactive while swiped");
227@@ -271,16 +279,20 @@
228
229 function test_swipe_on_empty_actions_bug1500416_data() {
230 return [
231- {tag: "swipe leading, touch", item: emptyActionList, dx: units.gu(5), touch: true},
232- {tag: "swipe trailing, touch", item: emptyActionList, dx: -units.gu(5), touch: true},
233- {tag: "swipe leading, mouse", item: emptyActionList, dx: units.gu(5), touch: false},
234- {tag: "swipe trailing, mouse", item: emptyActionList, dx: -units.gu(5), touch: false}
235+ {tag: "swipe leading, touch", item: emptyActionList, dx: units.gu(5), touch: true, swipePosition: false},
236+ {tag: "swipe trailing, touch", item: emptyActionList, dx: -units.gu(5), touch: true, swipePosition: false},
237+ {tag: "swipe leading, mouse", item: emptyActionList, dx: units.gu(5), touch: false, swipePosition: false},
238+ {tag: "swipe trailing, mouse", item: emptyActionList, dx: -units.gu(5), touch: false, swipePosition: false},
239+ {tag: "swipe leading, swipePosition", item: emptyActionList, dx: units.gu(5), touch: false, swipePosition: true},
240+ {tag: "swipe trailing, swipePosition", item: emptyActionList, dx: -units.gu(5), touch: false, swipePosition: true}
241 ];
242 }
243 function test_swipe_on_empty_actions_bug1500416(data) {
244 setupSpy(data.item, "contentMovementEnded");
245 if (data.touch) {
246 tugNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
247+ } else if (data.swipePosition) {
248+ data.item.swipePosition = data.dx;
249 } else {
250 swipeNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
251 }
252@@ -291,10 +303,12 @@
253 function test_swipe_not_possible_when_swipe_disabled_data() {
254 listView.positionViewAtBeginning();
255 return [
256- {tag: "leading, touch", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: true},
257- {tag: "trailing, touch", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: true},
258- {tag: "leading, mouse", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: false},
259- {tag: "trailing, mouse", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: false},
260+ {tag: "leading, touch", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: true, swipePosition: false},
261+ {tag: "trailing, touch", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: true, swipePosition: false},
262+ {tag: "leading, mouse", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: false, swipePosition: false},
263+ {tag: "trailing, mouse", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: false, swipePosition: false},
264+ {tag: "leading, swipePosition", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: false, swipePosition: true},
265+ {tag: "trailing, swipePosition", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: false, swipePosition: true},
266 ];
267 }
268 function test_swipe_not_possible_when_swipe_disabled(data) {
269@@ -303,6 +317,8 @@
270 setupSpy(data.item, "contentMovementEnded");
271 if (data.touch) {
272 tugNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
273+ } else if (data.swipePosition) {
274+ data.item.swipePosition = data.dx;
275 } else {
276 swipeNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
277 }

Subscribers

People subscribed via source and target branches