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

Proposed by Zsombor Egri
Status: Merged
Approved by: Cris Dywan
Approved revision: 1620
Merged at revision: 1622
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/listItemHandleUnacceptedMouseEvent
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 121 lines (+35/-18)
4 files modified
src/Ubuntu/Components/plugin/uclistitem.cpp (+6/-16)
src/Ubuntu/Components/plugin/uclistitem_p.h (+1/-1)
tests/unit_x11/tst_components/ListItemTestCase.qml (+1/-0)
tests/unit_x11/tst_components/tst_listitem_extras.qml (+27/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/listItemHandleUnacceptedMouseEvent
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Review via email: mp+269607@code.launchpad.net

Commit message

Fix ListItem swipe handling when gesture is initiated over an overlay MouseArea which does not accept pressed event.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

That makes a whole lot of sense. A MouseArea really shouldn't have a say in accepting the swipe handling.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/Components/plugin/uclistitem.cpp'
--- src/Ubuntu/Components/plugin/uclistitem.cpp 2015-07-30 13:27:32 +0000
+++ src/Ubuntu/Components/plugin/uclistitem.cpp 2015-08-31 07:54:47 +0000
@@ -372,23 +372,13 @@
372 (parentItem ? QQuickItemPrivate::get(parentItem)->childItems.indexOf(q) : -1);372 (parentItem ? QQuickItemPrivate::get(parentItem)->childItems.indexOf(q) : -1);
373}373}
374374
375// returns true if the highlight is possible375// returns true if the highlight is possible; the highlight is possible if the
376bool UCListItemPrivate::canHighlight(QMouseEvent *event)376// list item has at least one action, leading/trailing actions set, onClicked
377// or onPressAndHold signal handlers set
378bool UCListItemPrivate::canHighlight()
377{379{
378 // if automatic, the highlight should not happen if we clicked on an active component;
379 // localPos is a position relative to ListItem which will give us a child from
380 // from the original coordinates; therefore we must map the position to the contentItem
381 Q_Q(UCListItem);380 Q_Q(UCListItem);
382 QPointF myPos = q->mapToItem(contentItem, event->localPos());381 return (isClickedConnected() || isPressAndHoldConnected() || mainAction || leadingActions || trailingActions);
383 QQuickItem *child = contentItem->childAt(myPos.x(), myPos.y());
384 bool activeComponent = child && (child->acceptedMouseButtons() & event->button()) &&
385 child->isEnabled() && !qobject_cast<QQuickText*>(child);
386 // do highlight if not pressed above the active component, and the component has either
387 // action, leading or trailing actions list or at least an active child component declared
388 QQuickMouseArea *ma = q->findChild<QQuickMouseArea*>();
389 bool activeMouseArea = ma && ma->isEnabled();
390 return !activeComponent && (isClickedConnected() || isPressAndHoldConnected() ||
391 mainAction || leadingActions || trailingActions || activeMouseArea);
392}382}
393383
394// set highlighted flag and update contentItem384// set highlighted flag and update contentItem
@@ -1081,7 +1071,7 @@
1081 // while moving, we cannot select any items1071 // while moving, we cannot select any items
1082 return;1072 return;
1083 }1073 }
1084 if (d->canHighlight(event) && !d->highlighted && event->button() == Qt::LeftButton) {1074 if (d->canHighlight() && !d->highlighted && event->button() == Qt::LeftButton) {
1085 d->grabLeftButtonEvents(event);1075 d->grabLeftButtonEvents(event);
1086 }1076 }
1087 // accept the event so we get the rest of the events as well1077 // accept the event so we get the rest of the events as well
10881078
=== modified file 'src/Ubuntu/Components/plugin/uclistitem_p.h'
--- src/Ubuntu/Components/plugin/uclistitem_p.h 2015-07-30 13:27:32 +0000
+++ src/Ubuntu/Components/plugin/uclistitem_p.h 2015-08-31 07:54:47 +0000
@@ -60,7 +60,7 @@
60 void _q_syncSelectMode();60 void _q_syncSelectMode();
61 void _q_syncDragMode();61 void _q_syncDragMode();
62 int index();62 int index();
63 bool canHighlight(QMouseEvent *event);63 bool canHighlight();
64 void setHighlighted(bool pressed);64 void setHighlighted(bool pressed);
65 void listenToRebind(bool listen);65 void listenToRebind(bool listen);
66 void lockContentItem(bool lock);66 void lockContentItem(bool lock);
6767
=== modified file 'tests/unit_x11/tst_components/ListItemTestCase.qml'
--- tests/unit_x11/tst_components/ListItemTestCase.qml 2015-07-31 06:55:59 +0000
+++ tests/unit_x11/tst_components/ListItemTestCase.qml 2015-08-31 07:54:47 +0000
@@ -34,6 +34,7 @@
34 if (item.hasOwnProperty("leadingActions")) {34 if (item.hasOwnProperty("leadingActions")) {
35 signalSpy.target = item;35 signalSpy.target = item;
36 signalSpy.signalName = signalName;36 signalSpy.signalName = signalName;
37 signalSpy.clear();
37 }38 }
38 }39 }
39 // wait on the previosuly set up spy40 // wait on the previosuly set up spy
4041
=== modified file 'tests/unit_x11/tst_components/tst_listitem_extras.qml'
--- tests/unit_x11/tst_components/tst_listitem_extras.qml 2015-08-04 20:09:10 +0000
+++ tests/unit_x11/tst_components/tst_listitem_extras.qml 2015-08-31 07:54:47 +0000
@@ -68,10 +68,22 @@
68 anchors.centerIn: parent68 anchors.centerIn: parent
69 }69 }
70 }70 }
71
72 ListItem {
73 id: overlaidMouseArea
74 leadingActions: leading
75 trailingActions: trailing
76 property bool acceptEvent
77 MouseArea {
78 id: overlayArea
79 anchors.fill: parent
80 onPressed: mouse.accepted = overlaidMouseArea.acceptEvent
81 }
82 }
71 }83 }
7284
73 ListItemTestCase {85 ListItemTestCase {
7486 name: "ListItemExtras"
75 SignalSpy {87 SignalSpy {
76 id: clickSpy88 id: clickSpy
77 signalName: "clicked"89 signalName: "clicked"
@@ -79,6 +91,7 @@
7991
80 function cleanup() {92 function cleanup() {
81 rebound(testWithActiveItem);93 rebound(testWithActiveItem);
94 rebound(overlaidMouseArea);
82 clickSpy.target = null;95 clickSpy.target = null;
83 clickSpy.clear();96 clickSpy.clear();
84 }97 }
@@ -88,5 +101,18 @@
88 swipe(activeItem, centerOf(activeItem).x, centerOf(activeItem).y, units.gu(10));101 swipe(activeItem, centerOf(activeItem).x, centerOf(activeItem).y, units.gu(10));
89 compare(clickSpy.count, 0, "activeItem was clicked");102 compare(clickSpy.count, 0, "activeItem was clicked");
90 }103 }
104
105 function test_swipe_over_mousearea_not_accepting_press_data() {
106 return [
107 {tag: "Accept events", accept: true},
108 {tag: "Do not accept events", accept: false},
109 ];
110 }
111 function test_swipe_over_mousearea_not_accepting_press(data) {
112 overlaidMouseArea.acceptEvent = data.accept;
113 setupSpy(overlaidMouseArea, "contentMovementEnded");
114 swipeNoWait(overlayArea, centerOf(overlayArea).x, centerOf(overlayArea).y, units.gu(10));
115 spyWait();
116 }
91 }117 }
92}118}

Subscribers

People subscribed via source and target branches