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

Proposed by Zsombor Egri on 2015-09-30
Status: Merged
Approved by: Christian Dywan on 2015-10-01
Approved revision: 1663
Merged at revision: 1669
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/abstractbutton_longpress
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 126 lines (+50/-5)
3 files modified
src/Ubuntu/Components/plugin/ucabstractbutton.cpp (+19/-5)
src/Ubuntu/Components/plugin/ucabstractbutton.h (+3/-0)
tests/unit_x11/tst_components/tst_abstractbutton13.qml (+28/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/abstractbutton_longpress
Reviewer Review Type Date Requested Status
Christian Dywan 2015-09-30 Approve on 2015-10-01
PS Jenkins bot continuous-integration Approve on 2015-09-30
Review via email: mp+272926@code.launchpad.net

Commit Message

AbstractButton.pressAndHold captured in Connection.

To post a comment you must log in.
1663. By Zsombor Egri on 2015-09-30

fix

Christian Dywan (kalikiana) wrote :

Looks clean and sensible.

Idly wondering if the current uses of UniqueConnection should be re-evaluated as you're avoiding it here for performance reasons and we do use it in ucqquickimageextension and the QML plugin right now/

review: Approve
Zsombor Egri (zsombi) wrote :

> Looks clean and sensible.
>
> Idly wondering if the current uses of UniqueConnection should be re-evaluated
> as you're avoiding it here for performance reasons and we do use it in
> ucqquickimageextension and the QML plugin right now/

Yes, we should! Especially in the image, as that is pretty slow right now!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/ucabstractbutton.cpp'
2--- src/Ubuntu/Components/plugin/ucabstractbutton.cpp 2015-08-25 11:31:29 +0000
3+++ src/Ubuntu/Components/plugin/ucabstractbutton.cpp 2015-09-30 18:55:30 +0000
4@@ -52,15 +52,14 @@
5 : UCActionItem(parent)
6 , m_mouseArea(new QQuickMouseArea)
7 , m_acceptEvents(true)
8+ , m_pressAndHoldConnected(false)
9 {
10 setActiveFocusOnPress(true);
11 }
12
13 bool UCAbstractButton::isPressAndHoldConnected()
14 {
15- static QMetaMethod method = QMetaMethod::fromSignal(&UCAbstractButton::pressAndHold);
16- static int signalIdx = QMetaObjectPrivate::signalIndex(method);
17- return QObjectPrivate::get(this)->isSignalConnected(signalIdx);
18+ IS_SIGNAL_CONNECTED(this, UCAbstractButton, pressAndHold, ());
19 }
20
21 void UCAbstractButton::classBegin()
22@@ -88,8 +87,23 @@
23 connect(m_mouseArea, &QQuickMouseArea::pressedChanged, this, &UCAbstractButton::pressedChanged);
24 connect(m_mouseArea, &QQuickMouseArea::hoveredChanged, this, &UCAbstractButton::hoveredChanged);
25 connect(m_mouseArea, SIGNAL(clicked(QQuickMouseEvent*)), this, SLOT(_q_mouseAreaClicked()));
26- if (isPressAndHoldConnected()) {
27- connect(m_mouseArea, SIGNAL(pressAndHold(QQuickMouseEvent*)), this, SLOT(_q_mouseAreaPressAndHold()));
28+ connect(m_mouseArea, SIGNAL(pressed(QQuickMouseEvent*)), this, SLOT(_q_mouseAreaPressed()));
29+}
30+
31+// check the pressAndHold connection on runtime, as Connections
32+// may not be available on compoennt completion
33+void UCAbstractButton::_q_mouseAreaPressed()
34+{
35+ bool longPressConnected = isPressAndHoldConnected();
36+ if (longPressConnected && !m_pressAndHoldConnected) {
37+ // do not use UniqueConnection as that has huge impact on performance
38+ connect(m_mouseArea, SIGNAL(pressAndHold(QQuickMouseEvent*)),
39+ this, SLOT(_q_mouseAreaPressAndHold()));
40+ m_pressAndHoldConnected = true;
41+ } else if (!longPressConnected && m_pressAndHoldConnected) {
42+ disconnect(m_mouseArea, SIGNAL(pressAndHold(QQuickMouseEvent*)),
43+ this, SLOT(_q_mouseAreaPressAndHold()));
44+ m_pressAndHoldConnected = false;
45 }
46 }
47
48
49=== modified file 'src/Ubuntu/Components/plugin/ucabstractbutton.h'
50--- src/Ubuntu/Components/plugin/ucabstractbutton.h 2015-08-20 15:33:51 +0000
51+++ src/Ubuntu/Components/plugin/ucabstractbutton.h 2015-09-30 18:55:30 +0000
52@@ -20,6 +20,7 @@
53 #include "ucactionitem.h"
54
55 class QQuickMouseArea;
56+class QQuickMouseEvent;
57 class UCAbstractButton : public UCActionItem
58 {
59 Q_OBJECT
60@@ -51,12 +52,14 @@
61 void pressAndHold();
62
63 protected Q_SLOTS:
64+ void _q_mouseAreaPressed();
65 void _q_mouseAreaClicked();
66 void _q_mouseAreaPressAndHold();
67
68 protected:
69 QQuickMouseArea *m_mouseArea;
70 bool m_acceptEvents:1;
71+ bool m_pressAndHoldConnected:1;
72
73 bool isPressAndHoldConnected();
74 };
75
76=== modified file 'tests/unit_x11/tst_components/tst_abstractbutton13.qml'
77--- tests/unit_x11/tst_components/tst_abstractbutton13.qml 2015-08-25 11:31:29 +0000
78+++ tests/unit_x11/tst_components/tst_abstractbutton13.qml 2015-09-30 18:55:30 +0000
79@@ -41,6 +41,21 @@
80 height: width
81 function trigger() {}
82 }
83+ Loader {
84+ id: loader
85+ width: units.gu(10)
86+ height: units.gu(10)
87+ sourceComponent: AbstractButton { objectName: "dynamic"}
88+ property bool click: false
89+ property bool longPress: false
90+ }
91+ }
92+
93+ Connections {
94+ id: test
95+ target: loader.item
96+ onClicked: loader.click = true
97+ onPressAndHold: loader.longPress = true
98 }
99
100 Action {
101@@ -73,6 +88,8 @@
102 function cleanup() {
103 signalSpy.clear();
104 triggeredSpy.clear();
105+ loader.click = false;
106+ loader.longPress = false;
107 }
108
109 function test_action() {
110@@ -111,5 +128,16 @@
111 mouseRelease(absLongTap, centerOf(absLongTap).x, centerOf(absLongTap).y);
112 compare(signalSpy.count, 0, "click() must be suppressed when pressAndHold handler is implemented");
113 }
114+
115+ function test_pressAndHold_emitted_on_connections_bug1495554() {
116+ mouseLongPress(loader.item, centerOf(loader.item).x, centerOf(loader.item).y);
117+ mouseRelease(loader.item, centerOf(loader.item).x, centerOf(loader.item).y);
118+ compare(loader.click, false, "clicked should not be emitted");
119+ compare(loader.longPress, true, "pressAndHold not captured by Connection");
120+ }
121+ function test_clicked_emitted_on_connections_bug1495554() {
122+ mouseClick(loader.item, centerOf(loader.item).x, centerOf(loader.item).y);
123+ compare(loader.click, true, "clicked not captured by Connection");
124+ }
125 }
126 }

Subscribers

People subscribed via source and target branches