Merge lp:~zsombi/ubuntu-ui-toolkit/listItemContentDrag into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Cris Dywan
Approved revision: 1704
Merged at revision: 1704
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/listItemContentDrag
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 238 lines (+140/-2)
5 files modified
components.api (+1/-0)
src/Ubuntu/Components/plugin/uclistitem.cpp (+53/-2)
src/Ubuntu/Components/plugin/uclistitem.h (+4/-0)
src/Ubuntu/Components/plugin/uclistitem_p.h (+1/-0)
tests/unit_x11/tst_components/tst_listitem_extras.qml (+81/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/listItemContentDrag
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+275691@code.launchpad.net

Commit message

Add ListItem.swipeEnabled property to block swiping when overlay MouseArea is used to drag content. Fixes swiping when leading/trailing actions list is empty.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Nice!

review: Approve

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 2015-10-23 05:42:14 +0000
3+++ components.api 2015-10-26 11:51:01 +0000
4@@ -514,6 +514,7 @@
5 signal contentMovementEnded()
6 property bool selectMode
7 property bool selected
8+ property bool swipeEnabled 1.3
9 property ListItemActions trailingActions
10 Ubuntu.Components.ListItemActions 1.2: QtObject
11 readonly property Action actions
12
13=== modified file 'src/Ubuntu/Components/plugin/uclistitem.cpp'
14--- src/Ubuntu/Components/plugin/uclistitem.cpp 2015-10-20 11:05:53 +0000
15+++ src/Ubuntu/Components/plugin/uclistitem.cpp 2015-10-26 11:51:01 +0000
16@@ -198,6 +198,7 @@
17 , xAxisMoveThresholdGU(DEFAULT_SWIPE_THRESHOLD_GU)
18 , button(Qt::NoButton)
19 , highlighted(false)
20+ , swipeEnabled(true)
21 , contentMoved(false)
22 , swiped(false)
23 , suppressClick(false)
24@@ -1255,10 +1256,15 @@
25 // returns true if the mouse is swiped over the threshold value
26 bool UCListItemPrivate::swipedOverThreshold(const QPointF &mousePos, const QPointF relativePos)
27 {
28+ if ((!leadingActions || UCListItemActionsPrivate::get(leadingActions)->actions.size() <= 0) &&
29+ (!trailingActions || UCListItemActionsPrivate::get(trailingActions)->actions.size() <= 0))
30+ {
31+ return false;
32+ }
33 qreal threshold = UCUnits::instance().gu(xAxisMoveThresholdGU);
34 qreal mouseX = mousePos.x();
35 qreal pressedX = relativePos.x();
36- return ((mouseX < (pressedX - threshold)) || (mouseX > (pressedX + threshold)));
37+ return swipeEnabled && ((mouseX < (pressedX - threshold)) || (mouseX > (pressedX + threshold)));
38 }
39
40 void UCListItem::mouseMoveEvent(QMouseEvent *event)
41@@ -1273,7 +1279,7 @@
42
43 // accept the tugging only if the move is within the threshold
44 // use saved button because MouseMove has no button() and buttons() isn't reliable
45- if (d->button == Qt::LeftButton && d->highlighted && !d->swiped && (d->leadingActions || d->trailingActions)) {
46+ if (d->button == Qt::LeftButton && d->highlighted && !d->swiped) {
47 // check if we can initiate the drag at all
48 // only X direction matters, if Y-direction leaves the threshold, but X not, the tug is not valid
49 if (d->swipedOverThreshold(event->localPos(), d->pressedPos)) {
50@@ -1797,4 +1803,49 @@
51 }
52 }
53
54+/*!
55+ * \qmlproperty bool ListItem::swipeEnabled
56+ * \since Ubuntu.Components 1.3
57+ * The property enables the swiping of the leading- or trailing actions. This
58+ * is useful when an overlay component needs to handle mouse moves or drag events
59+ * without the ListItem to steal the events. Defaults to true.
60+ * \qml
61+ * import QtQuick 2.4
62+ * import Ubuntu.Components 1.3
63+ *
64+ * ListView {
65+ * width: units.gu(40)
66+ * height: units.gu(70)
67+ * model: 25
68+ * delegate: ListItem {
69+ * swipeEnabled: !mouseArea.drag.active
70+ * Rectangle {
71+ * color: "red"
72+ * width: units.gu(2)
73+ * height: width
74+ * MouseArea {
75+ * id: mouseArea
76+ * anchors.fill: parent
77+ * drag.target: parent
78+ * }
79+ * }
80+ * }
81+ * }
82+ * \endqml
83+ */
84+bool UCListItem::isSwipeEnabled() const
85+{
86+ Q_D(const UCListItem);
87+ return d->swipeEnabled;
88+}
89+void UCListItem::setSwipeEnabled(bool swipeEnabled)
90+{
91+ Q_D(UCListItem);
92+ if (d->swipeEnabled == swipeEnabled) {
93+ return;
94+ }
95+ d->swipeEnabled = swipeEnabled;
96+ Q_EMIT swipeEnabledChanged();
97+}
98+
99 #include "moc_uclistitem.cpp"
100
101=== modified file 'src/Ubuntu/Components/plugin/uclistitem.h'
102--- src/Ubuntu/Components/plugin/uclistitem.h 2015-09-23 14:31:26 +0000
103+++ src/Ubuntu/Components/plugin/uclistitem.h 2015-10-26 11:51:01 +0000
104@@ -47,6 +47,7 @@
105 Q_CLASSINFO("DefaultProperty", "listItemData")
106 // 1.3
107 Q_PROPERTY(UCListItemExpansion* expansion READ expansion CONSTANT REVISION 1)
108+ Q_PROPERTY(bool swipeEnabled READ isSwipeEnabled WRITE setSwipeEnabled NOTIFY swipeEnabledChanged FINAL REVISION 1)
109 public:
110 explicit UCListItem(QQuickItem *parent = 0);
111 ~UCListItem();
112@@ -65,6 +66,8 @@
113 void resetHighlightColor();
114 // 1.3
115 UCListItemExpansion *expansion();
116+ bool isSwipeEnabled() const;
117+ void setSwipeEnabled(bool swipeEnabled);
118
119 protected:
120 virtual QObject *attachedViewItems(QObject *object, bool create);
121@@ -92,6 +95,7 @@
122 void selectModeChanged();
123 void actionChanged();
124 void listItemChildrenChanged();
125+ Q_REVISION(1) void swipeEnabledChanged();
126
127 void clicked();
128 void pressAndHold();
129
130=== modified file 'src/Ubuntu/Components/plugin/uclistitem_p.h'
131--- src/Ubuntu/Components/plugin/uclistitem_p.h 2015-09-23 14:31:26 +0000
132+++ src/Ubuntu/Components/plugin/uclistitem_p.h 2015-10-26 11:51:01 +0000
133@@ -95,6 +95,7 @@
134 qreal xAxisMoveThresholdGU;
135 Qt::MouseButton button;
136 bool highlighted:1;
137+ bool swipeEnabled:1;
138 bool contentMoved:1;
139 bool swiped:1;
140 bool suppressClick:1;
141
142=== modified file 'tests/unit_x11/tst_components/tst_listitem_extras.qml'
143--- tests/unit_x11/tst_components/tst_listitem_extras.qml 2015-09-18 10:49:07 +0000
144+++ tests/unit_x11/tst_components/tst_listitem_extras.qml 2015-10-26 11:51:01 +0000
145@@ -96,6 +96,28 @@
146 leadingActions: leading
147 }
148 }
149+ ListItem {
150+ id: emptyActionList
151+ leadingActions: ListItemActions {}
152+ trailingActions: ListItemActions {
153+ actions: []
154+ }
155+ }
156+ ListItem {
157+ id: contentDragging
158+ swipeEnabled: ma.drag.active
159+ Rectangle {
160+ id: draggedItem
161+ width: units.gu(2)
162+ height: width
163+ color: "red"
164+ MouseArea {
165+ id: ma
166+ anchors.fill: parent
167+ drag.target: parent
168+ }
169+ }
170+ }
171 }
172
173 ListItemTestCase13 {
174@@ -246,5 +268,64 @@
175 }
176 clickSpy.wait(200);
177 }
178+
179+ function test_swipe_on_empty_actions_bug1500416_data() {
180+ return [
181+ {tag: "swipe leading, touch", item: emptyActionList, dx: units.gu(5), touch: true},
182+ {tag: "swipe trailing, touch", item: emptyActionList, dx: -units.gu(5), touch: true},
183+ {tag: "swipe leading, mouse", item: emptyActionList, dx: units.gu(5), touch: false},
184+ {tag: "swipe trailing, mouse", item: emptyActionList, dx: -units.gu(5), touch: false}
185+ ];
186+ }
187+ function test_swipe_on_empty_actions_bug1500416(data) {
188+ setupSpy(data.item, "contentMovementEnded");
189+ if (data.touch) {
190+ tugNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
191+ } else {
192+ swipeNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
193+ }
194+ expectFailContinue(data.tag, "No swipe should happen");
195+ spyWait(200);
196+ }
197+
198+ function test_swipe_not_possible_when_swipe_disabled_data() {
199+ listView.positionViewAtBeginning();
200+ return [
201+ {tag: "leading, touch", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: true},
202+ {tag: "trailing, touch", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: true},
203+ {tag: "leading, mouse", item: findChild(listView, "listItem0"), dx: units.gu(10), touch: false},
204+ {tag: "trailing, mouse", item: findChild(listView, "listItem0"), dx: -units.gu(10), touch: false},
205+ ];
206+ }
207+ function test_swipe_not_possible_when_swipe_disabled(data) {
208+ verify(data.item, "test item not found");
209+ data.item.swipeEnabled = false;
210+ setupSpy(data.item, "contentMovementEnded");
211+ if (data.touch) {
212+ tugNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
213+ } else {
214+ swipeNoWait(data.item, centerOf(data.item).x, centerOf(data.item).y, data.dx, 0);
215+ }
216+ expectFailContinue(data.tag, "No swipe should happen");
217+ spyWait(200);
218+ data.item.swipeEnabled = true;
219+ }
220+
221+ function test_drag_listitem_content_bug1500409_data() {
222+ return [
223+ {tag: "touch", touch: true},
224+ {tag: "mouse", touch: false}
225+ ];
226+ }
227+ function test_drag_listitem_content_bug1500409(data) {
228+ setupSpy(contentDragging, "contentMovementStarted");
229+ if (data.touch) {
230+ TestExtras.touchDrag(0, draggedItem, centerOf(draggedItem), Qt.point(units.gu(10), units.gu(3)));
231+ } else {
232+ mouseDrag(draggedItem, centerOf(draggedItem).x, centerOf(draggedItem).y, units.gu(10), units.gu(3));
233+ }
234+ expectFailContinue("", "drag disables swipe");
235+ spyWait(200);
236+ }
237 }
238 }

Subscribers

People subscribed via source and target branches