Merge lp:~tpeeters/ubuntu-ui-toolkit/listitem-disabled-control into lp:ubuntu-ui-toolkit

Proposed by Tim Peeters
Status: Merged
Approved by: Florian Boucault
Approved revision: 430
Merged at revision: 439
Proposed branch: lp:~tpeeters/ubuntu-ui-toolkit/listitem-disabled-control
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 242 lines (+120/-60)
4 files modified
demos/ListItems.qml (+7/-0)
modules/Ubuntu/Components/ListItems/SingleControl.qml (+3/-3)
modules/Ubuntu/Components/ListItems/Standard.qml (+4/-4)
tests/unit/tst_components/tst_listitems_standard.qml (+106/-53)
To merge this branch: bzr merge lp:~tpeeters/ubuntu-ui-toolkit/listitem-disabled-control
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Florian Boucault Pending
Review via email: mp+158998@code.launchpad.net

Commit message

Disable events on disabled controls inside list items.

Description of the change

Disable events on disabled controls inside list items.

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

On hold. Perhaps design doesn't want this in, because if the control is disabled then maybe it is better not to show it at all.

Revision history for this message
Tim Peeters (tpeeters) wrote :

We decided to include the support for disabled controls (see discussion in bug report), but it depends on the case whether it is the desired thing to use (vs. not showing a control).

Also added tests.

430. By Tim Peeters

remove blank line

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
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
1=== modified file 'demos/ListItems.qml'
2--- demos/ListItems.qml 2013-04-15 13:43:19 +0000
3+++ demos/ListItems.qml 2013-04-22 12:39:26 +0000
4@@ -319,6 +319,13 @@
5 control: controlExample.createObject(parent)
6 }
7 ListItem.Standard {
8+ text: i18n.tr("Control disabled")
9+ control: Switch {
10+ anchors.verticalCenter: parent.verticalCenter
11+ enabled: false
12+ }
13+ }
14+ ListItem.Standard {
15 selected: true
16 text: i18n.tr("Selected")
17 control: controlExample.createObject(parent)
18
19=== modified file 'modules/Ubuntu/Components/ListItems/SingleControl.qml'
20--- modules/Ubuntu/Components/ListItems/SingleControl.qml 2013-04-16 10:59:28 +0000
21+++ modules/Ubuntu/Components/ListItems/SingleControl.qml 2013-04-22 12:39:26 +0000
22@@ -55,10 +55,10 @@
23 property AbstractButton control
24
25 /*! \internal */
26- onClicked: control.clicked()
27- pressed: __mouseArea.pressed || control.__mouseArea.pressed
28+ onClicked: if (control && control.enabled) control.clicked()
29+ pressed: __mouseArea.pressed || (control && control.__mouseArea.pressed)
30 /*! \internal */
31- onPressedChanged: control.pressed = singleControlListItem.pressed
32+ onPressedChanged: if (control && control.enabled) control.pressed = singleControlListItem.pressed
33
34 /*!
35 \internal
36
37=== modified file 'modules/Ubuntu/Components/ListItems/Standard.qml'
38--- modules/Ubuntu/Components/ListItems/Standard.qml 2013-04-15 18:49:12 +0000
39+++ modules/Ubuntu/Components/ListItems/Standard.qml 2013-04-22 12:39:26 +0000
40@@ -241,7 +241,7 @@
41 margins: units.gu(2)
42 }
43 onControlChanged: {
44- control.parent = controlContainer;
45+ if (control) control.parent = controlContainer;
46 }
47
48 Connections {
49@@ -249,14 +249,14 @@
50
51 onClicked: {
52 if (control && __mouseArea.mouseX < progressionHelper.x) {
53- control.clicked();
54+ if (control.enabled) control.clicked();
55 } else {
56 listItem.clicked();
57 }
58 }
59
60 onPressAndHold: {
61- if (control && __mouseArea.mouseX < progressionHelper.x) {
62+ if (control && control.enabled && __mouseArea.mouseX < progressionHelper.x) {
63 control.pressAndHold();
64 } else {
65 listItem.pressAndHold();
66@@ -269,7 +269,7 @@
67 \internal
68 */
69 onPressedChanged: {
70- if (listItem.pressed && control && (__mouseArea.mouseX < progressionHelper.x)) {
71+ if (listItem.pressed && control && control.enabled && (__mouseArea.mouseX < progressionHelper.x)) {
72 listItem.__controlAreaPressed = true
73 } else {
74 listItem.__controlAreaPressed = false
75
76=== modified file 'tests/unit/tst_components/tst_listitems_standard.qml'
77--- tests/unit/tst_components/tst_listitems_standard.qml 2012-12-10 09:12:46 +0000
78+++ tests/unit/tst_components/tst_listitems_standard.qml 2013-04-22 12:39:26 +0000
79@@ -19,57 +19,110 @@
80 import Ubuntu.Components 0.1
81 import Ubuntu.Components.ListItems 0.1 as ListItem
82
83-TestCase {
84- name: "ListItemsStandardAPI"
85-
86- function test_fallbackIconSource() {
87- expectFail("","https://bugs.launchpad.net/tavastia/+bug/1076762")
88- compare(listItemStandard.fallbackIconSource,undefined,"fallbackIconSource is not set by default")
89- }
90-
91- function test_control() {
92- compare(listItemStandard.control,null,"control is null by default")
93- listItemStandard.control = testControl
94- compare(listItemStandard.control,testControl,"set/get")
95- }
96-
97- function test_icon() {
98- compare(listItemStandard.icon,undefined,"icon is not set by default")
99-
100- // test with item
101- listItemStandard.icon = testItem
102- compare(listItemStandard.icon,testItem,"set/get from Item")
103-
104- // test with url
105- var newIcon = "../../../demos/small_avatar.png"
106- listItemStandard.icon = newIcon
107- compare(listItemStandard.icon,newIcon,"set/get from url")
108- }
109-
110- function test_iconFrame() {
111- compare(listItemStandard.iconFrame,true,"iconFrame is true by default")
112- }
113-
114- function test_progression() {
115- compare(listItemStandard.progression,false,"progression is false by default")
116- }
117-
118- function test_text() {
119- compare(listItemStandard.text,"","text is '' by default")
120- var newText = "Hello World!"
121- listItemStandard.text = newText
122- compare(listItemStandard.text,newText,"set/get")
123- }
124-
125- Rectangle {
126- id: testItem
127- }
128-
129- AbstractButton {
130- id: testControl
131- }
132-
133- ListItem.Standard {
134- id: listItemStandard
135- }
136+Item {
137+ width: 400
138+ height: 400
139+
140+ Rectangle {
141+ id: testItem
142+ }
143+
144+ AbstractButton {
145+ id: testControl
146+ visible: false
147+ }
148+
149+ ListItem.Standard {
150+ id: listItemStandard
151+ anchors.fill: parent
152+ }
153+
154+ TestCase {
155+ name: "ListItemsStandardAPI"
156+ when: windowShown
157+
158+ function test_fallbackIconSource() {
159+ expectFail("","https://bugs.launchpad.net/tavastia/+bug/1076762")
160+ compare(listItemStandard.fallbackIconSource,undefined,"fallbackIconSource is not set by default")
161+ }
162+
163+ function test_control() {
164+ listItemStandard.control = testControl
165+ compare(listItemStandard.control,testControl,"set/get")
166+ listItemStandard.control = null
167+ compare(listItemStandard.control, null, "unset")
168+ }
169+
170+ function test_clicked() {
171+ compare(listItemClickedSpy.valid, true, "clicked signal exists")
172+ compare(controlClickedSpy.valid, true, "control has clicked signal")
173+ var listItemClickedCount = listItemClickedSpy.count
174+ var controlClickedCount = controlClickedSpy.count
175+ mouseMove(listItemStandard, 10, 10)
176+ mouseClick(listItemStandard, 10, 10, Qt.LeftButton)
177+ listItemClickedCount++;
178+ compare(listItemClickedSpy.count, listItemClickedCount, "List item clicked triggered")
179+ listItemStandard.control = testControl;
180+ mouseMove(listItemStandard, 10, 10)
181+ mouseClick(listItemStandard, 10, 10, Qt.LeftButton)
182+ compare(listItemStandard.control, testControl, "control can be set")
183+ controlClickedCount++;
184+ compare(controlClickedSpy.count, controlClickedCount, "Control clicked triggered")
185+ compare(listItemClickedSpy.count, listItemClickedCount, "List item clicked not triggered when there is a control")
186+ listItemStandard.control = null;
187+ }
188+
189+ function test_bug1166982_disabled_control_clicked() {
190+ var listItemClickedCount = listItemClickedSpy.count
191+ var controlClickedCount = controlClickedSpy.count
192+ listItemStandard.control = testControl
193+ testControl.enabled = false
194+ mouseMove(listItemStandard, 10, 10)
195+ mouseClick(listItemStandard, 10, 10, Qt.LeftButton)
196+ compare(listItemClickedSpy.count, listItemClickedCount, "List item clicked not triggered with disabled control")
197+ compare(controlClickedSpy.count, controlClickedCount, "Control clicked not triggered with disabled control")
198+ testControl.enabled = true
199+ listItemStandard.control = null
200+ }
201+
202+ function test_icon() {
203+ compare(listItemStandard.icon,undefined,"icon is not set by default")
204+
205+ // test with item
206+ listItemStandard.icon = testItem
207+ compare(listItemStandard.icon,testItem,"set/get from Item")
208+
209+ // test with url
210+ var newIcon = "../../../demos/small_avatar.png"
211+ listItemStandard.icon = newIcon
212+ compare(listItemStandard.icon,newIcon,"set/get from url")
213+ }
214+
215+ function test_iconFrame() {
216+ compare(listItemStandard.iconFrame,true,"iconFrame is true by default")
217+ }
218+
219+ function test_progression() {
220+ compare(listItemStandard.progression,false,"progression is false by default")
221+ }
222+
223+ function test_text() {
224+ compare(listItemStandard.text,"","text is '' by default")
225+ var newText = "Hello World!"
226+ listItemStandard.text = newText
227+ compare(listItemStandard.text,newText,"set/get")
228+ }
229+
230+ SignalSpy {
231+ id: listItemClickedSpy
232+ target: listItemStandard
233+ signalName: "clicked"
234+ }
235+
236+ SignalSpy {
237+ id: controlClickedSpy
238+ target: testControl
239+ signalName: "clicked"
240+ }
241+ }
242 }

Subscribers

People subscribed via source and target branches

to status/vote changes: