Merge lp:~zsombi/ubuntu-ui-toolkit/50-custom-delegates into lp:~zsombi/ubuntu-ui-toolkit/listitem-master
- 50-custom-delegates
- Merge into listitem-master
Status: | Merged |
---|---|
Approved by: | Tim Peeters |
Approved revision: | 1291 |
Merged at revision: | 1275 |
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/50-custom-delegates |
Merge into: | lp:~zsombi/ubuntu-ui-toolkit/listitem-master |
Prerequisite: | lp:~zsombi/ubuntu-ui-toolkit/45-selected-option-rebinds |
Diff against target: |
215 lines (+107/-7) 6 files modified
modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml (+3/-1) modules/Ubuntu/Components/plugin/uclistitem.cpp (+1/-1) modules/Ubuntu/Components/plugin/uclistitemactions.cpp (+63/-4) modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp (+1/-1) tests/resources/listitems/ListItemTest.qml (+16/-0) tests/unit_x11/tst_components/tst_listitem.qml (+23/-0) |
To merge this branch: | bzr merge lp:~zsombi/ubuntu-ui-toolkit/50-custom-delegates |
Related bugs: | |
Related blueprints: |
SDK: Design a new ListItem and layouts
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Peeters | Approve | ||
Review via email: mp+235170@code.launchpad.net |
Commit message
Introducing custom delegates.
Description of the change
Introducing custom delegates.
- 1251. By Zsombor Egri
-
prereq sync
- 1252. By Zsombor Egri
-
prereq sync
- 1253. By Zsombor Egri
-
prereq sync
- 1254. By Zsombor Egri
-
prereq sync
- 1255. By Zsombor Egri
-
fixing tests
- 1256. By Zsombor Egri
-
prereq sync
- 1257. By Zsombor Egri
-
prereq sync
- 1258. By Zsombor Egri
-
documentation fxed
- 1259. By Zsombor Egri
-
prereq sync
- 1260. By Zsombor Egri
-
prereq sync
- 1261. By Zsombor Egri
-
prereq sync
- 1262. By Zsombor Egri
-
prereq sync
- 1263. By Zsombor Egri
-
prereq sync
- 1264. By Zsombor Egri
-
prereq sync
- 1265. By Zsombor Egri
-
prereq sync
- 1266. By Zsombor Egri
-
prereq sync
- 1267. By Zsombor Egri
-
prereq sync
- 1268. By Zsombor Egri
-
proper rebounding fix in test
- 1269. By Zsombor Egri
-
prereq sync
- 1270. By Zsombor Egri
-
prereq sync
- 1271. By Zsombor Egri
-
prereq sync
- 1272. By Zsombor Egri
-
fixing documentation
- 1273. By Zsombor Egri
-
prereq sync
- 1274. By Zsombor Egri
-
tests fixed
- 1275. By Zsombor Egri
-
prereq sync
- 1276. By Zsombor Egri
-
prereq sync
- 1277. By Zsombor Egri
-
tests adjusted
- 1278. By Zsombor Egri
-
prereq sync
- 1279. By Zsombor Egri
-
prereq sync
- 1280. By Zsombor Egri
-
prereq sync
- 1281. By Zsombor Egri
-
prereq sync
- 1282. By Zsombor Egri
-
prereq sync
- 1283. By Zsombor Egri
-
prereq sync
- 1284. By Zsombor Egri
-
prereq sync
- 1285. By Zsombor Egri
-
prereq sync
- 1286. By Zsombor Egri
-
documentation link fixed
- 1287. By Zsombor Egri
-
documentation link fixed
- 1288. By Zsombor Egri
-
more documentation fixes
- 1289. By Zsombor Egri
-
prereq sync
- 1290. By Zsombor Egri
-
remove typo from property documentation
Tim Peeters (tpeeters) wrote : | # |
Tim Peeters (tpeeters) wrote : | # |
Please expose a pressed attached property to the custom delegate as well.
I have no way now to detect inside the custom delegate whether it is pressed. I could add a MouseArea like this:
id: trailActions
}
]
}
}
}
}
but that eats the mouse events and prevents the trigger() signal on clicked.
Tim Peeters (tpeeters) : | # |
- 1291. By Zsombor Egri
-
review comments added
Preview Diff
1 | === modified file 'modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml' | |||
2 | --- modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml 2014-11-27 10:33:21 +0000 | |||
3 | +++ modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml 2014-11-27 10:33:24 +0000 | |||
4 | @@ -101,6 +101,7 @@ | |||
5 | 101 | Repeater { | 101 | Repeater { |
6 | 102 | model: panel.ListItemActions.visibleActions | 102 | model: panel.ListItemActions.visibleActions |
7 | 103 | AbstractButton { | 103 | AbstractButton { |
8 | 104 | id: actionButton | ||
9 | 104 | action: modelData | 105 | action: modelData |
10 | 105 | enabled: action.enabled | 106 | enabled: action.enabled |
11 | 106 | opacity: action.enabled ? 1.0 : 0.5 | 107 | opacity: action.enabled ? 1.0 : 0.5 |
12 | @@ -124,9 +125,10 @@ | |||
13 | 124 | Loader { | 125 | Loader { |
14 | 125 | id: delegateLoader | 126 | id: delegateLoader |
15 | 126 | height: parent.height | 127 | height: parent.height |
17 | 127 | sourceComponent: panel.ListItemActions.delegate ? panel.ListItemActions.delegate : defaultDelegate | 128 | sourceComponent: panel.ListItemActions.container.delegate ? panel.ListItemActions.container.delegate : defaultDelegate |
18 | 128 | property Action action: modelData | 129 | property Action action: modelData |
19 | 129 | property int index: index | 130 | property int index: index |
20 | 131 | property bool pressed: actionButton.pressed | ||
21 | 130 | onItemChanged: { | 132 | onItemChanged: { |
22 | 131 | // use action's objectName to identify the visualized action | 133 | // use action's objectName to identify the visualized action |
23 | 132 | if (item && item.objectName === "") { | 134 | if (item && item.objectName === "") { |
24 | 133 | 135 | ||
25 | === modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp' | |||
26 | --- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-27 10:33:21 +0000 | |||
27 | +++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-27 10:33:24 +0000 | |||
28 | @@ -1087,7 +1087,7 @@ | |||
29 | 1087 | */ | 1087 | */ |
30 | 1088 | 1088 | ||
31 | 1089 | /*! | 1089 | /*! |
33 | 1090 | * \qmlsignal UCListItemPrivate::contentMovementEnded | 1090 | * \qmlsignal ListItem::contentMovementEnded() |
34 | 1091 | * The signal is emitted when the content movement has ended. | 1091 | * The signal is emitted when the content movement has ended. |
35 | 1092 | */ | 1092 | */ |
36 | 1093 | bool UCListItemPrivate::contentMoving() const | 1093 | bool UCListItemPrivate::contentMoving() const |
37 | 1094 | 1094 | ||
38 | === modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.cpp' | |||
39 | --- modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-27 10:33:21 +0000 | |||
40 | +++ modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-27 10:33:24 +0000 | |||
41 | @@ -260,8 +260,8 @@ | |||
42 | 260 | * ListItemActions instances can be shared between ListItem instances within the | 260 | * ListItemActions instances can be shared between ListItem instances within the |
43 | 261 | * same view. When shared, the memory footprint of the view will be lot smaller, | 261 | * same view. When shared, the memory footprint of the view will be lot smaller, |
44 | 262 | * as there will be no individual panel created for each list's actions visualization. | 262 | * as there will be no individual panel created for each list's actions visualization. |
47 | 263 | * Depending on how long the initialization of the component used in \c ListItem::actionsDelegate | 263 | * Depending on how long the initialization of the component used in \l {ListItemStyle::actionsDelegate} |
48 | 264 | * takes, creation time will be also reduced to one time per view. | 264 | * {actionsDelegate} takes, creation time will be also reduced to one time per view. |
49 | 265 | * However, this implies that swiping a new ListItem content while another one is | 265 | * However, this implies that swiping a new ListItem content while another one is |
50 | 266 | * swiped will result in showing the newly swiped item's panel delayed, as the | 266 | * swiped will result in showing the newly swiped item's panel delayed, as the |
51 | 267 | * panel can be shown only after the previous item's snapping is completed. Depending | 267 | * panel can be shown only after the previous item's snapping is completed. Depending |
52 | @@ -393,8 +393,67 @@ | |||
53 | 393 | 393 | ||
54 | 394 | /*! | 394 | /*! |
55 | 395 | * \qmlproperty Component ListItemActions::delegate | 395 | * \qmlproperty Component ListItemActions::delegate |
58 | 396 | * Custom delegate which overrides the default one used by the ListItem. If the | 396 | * The property holds the custom delegate to visualize the actions listed in the |
59 | 397 | * value is null, the default delegate will be used. | 397 | * ListItemActions. When set to null, the default delegate specified by the \l |
60 | 398 | * {ListItemStyle::actionsDelegate}{actionsDelegate} will be used. | ||
61 | 399 | * | ||
62 | 400 | * ListItemActions provides the \c action context property which contains the | ||
63 | 401 | * Action instance visualized. Using this property delegates can access | ||
64 | 402 | * the information to be visualized. The action is triggered by the panel item | ||
65 | 403 | * holding the visualized action, therefore only visualization is needed by the | ||
66 | 404 | * custom delegate. The other context property exposed to delegates is the \c | ||
67 | 405 | * index, which specifies the index of the action visualized. | ||
68 | 406 | * | ||
69 | 407 | * Specifying a custom delegate will not override the triggering logic of the | ||
70 | 408 | * action, that will be still handled by the panel itself. However custom delegates | ||
71 | 409 | * may still need to distinguish the pressed/released state visually. This can | ||
72 | 410 | * be achieved using the \c pressed context property, which informs the delegate | ||
73 | 411 | * about the pressed state of the action. | ||
74 | 412 | * | ||
75 | 413 | * The delegate height is set automatically by the panel item, only the width must | ||
76 | 414 | * be specified which will be clamped between height and the maximum width of the | ||
77 | 415 | * list item divided by the number of actions in the list. | ||
78 | 416 | * \qml | ||
79 | 417 | * import QtQuick 2.2 | ||
80 | 418 | * import Ubuntu.Components 1.2 | ||
81 | 419 | * | ||
82 | 420 | * MainView { | ||
83 | 421 | * width: units.gu(40) | ||
84 | 422 | * height: units.gu(71) | ||
85 | 423 | * | ||
86 | 424 | * UbuntuListView { | ||
87 | 425 | * anchors.fill: parent | ||
88 | 426 | * model: 50 | ||
89 | 427 | * delegate: ListItem { | ||
90 | 428 | * trailingActions: actionsList | ||
91 | 429 | * } | ||
92 | 430 | * ListItemActions { | ||
93 | 431 | * id: actionsList | ||
94 | 432 | * delegate: Column { | ||
95 | 433 | * width: height + units.gu(2) | ||
96 | 434 | * Icon { | ||
97 | 435 | * name: action.iconName | ||
98 | 436 | * width: units.gu(3) | ||
99 | 437 | * height: width | ||
100 | 438 | * color: pressed ? "blue" : "lightblue" | ||
101 | 439 | * anchors.horizontalCenter: parent.horizontalCenter | ||
102 | 440 | * } | ||
103 | 441 | * Label { | ||
104 | 442 | * text: action.text + "#" + index | ||
105 | 443 | * width: parent.width | ||
106 | 444 | * horizontalAlignment: Text.AlignHCenter | ||
107 | 445 | * } | ||
108 | 446 | * } | ||
109 | 447 | * actions: Action { | ||
110 | 448 | * iconName: "starred" | ||
111 | 449 | * text: "Star" | ||
112 | 450 | * } | ||
113 | 451 | * } | ||
114 | 452 | * } | ||
115 | 453 | * } | ||
116 | 454 | * \endqml | ||
117 | 455 | * \note Putting a Rectangle in the delegate can be used to override the color | ||
118 | 456 | * of the panel. | ||
119 | 398 | * | 457 | * |
120 | 399 | * Defaults to null. | 458 | * Defaults to null. |
121 | 400 | */ | 459 | */ |
122 | 401 | 460 | ||
123 | === modified file 'modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp' | |||
124 | --- modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-27 10:33:21 +0000 | |||
125 | +++ modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-27 10:33:24 +0000 | |||
126 | @@ -212,7 +212,7 @@ | |||
127 | 212 | } | 212 | } |
128 | 213 | 213 | ||
129 | 214 | /*! | 214 | /*! |
131 | 215 | * \qmlproperty real ListItemActions::overshoot | 215 | * \qmlattachedproperty real ListItemActions::overshoot |
132 | 216 | * The property holds the overshoot value set for the list item. | 216 | * The property holds the overshoot value set for the list item. |
133 | 217 | */ | 217 | */ |
134 | 218 | qreal UCListItemActionsAttached::overshoot() | 218 | qreal UCListItemActionsAttached::overshoot() |
135 | 219 | 219 | ||
136 | === modified file 'tests/resources/listitems/ListItemTest.qml' | |||
137 | --- tests/resources/listitems/ListItemTest.qml 2014-11-27 10:33:21 +0000 | |||
138 | +++ tests/resources/listitems/ListItemTest.qml 2014-11-27 10:33:24 +0000 | |||
139 | @@ -28,6 +28,7 @@ | |||
140 | 28 | objectName: "stock" | 28 | objectName: "stock" |
141 | 29 | id: stock | 29 | id: stock |
142 | 30 | iconName: "starred" | 30 | iconName: "starred" |
143 | 31 | text: "Staaaar" | ||
144 | 31 | onTriggered: print(iconName, "triggered") | 32 | onTriggered: print(iconName, "triggered") |
145 | 32 | } | 33 | } |
146 | 33 | 34 | ||
147 | @@ -101,6 +102,21 @@ | |||
148 | 101 | leadingActions: ListItemActions { | 102 | leadingActions: ListItemActions { |
149 | 102 | objectName: "InlineLeading" | 103 | objectName: "InlineLeading" |
150 | 103 | actions: [stock] | 104 | actions: [stock] |
151 | 105 | delegate: Column { | ||
152 | 106 | width: height + units.gu(2) | ||
153 | 107 | Icon { | ||
154 | 108 | width: units.gu(3) | ||
155 | 109 | height: width | ||
156 | 110 | name: action.iconName | ||
157 | 111 | color: "blue" | ||
158 | 112 | anchors.horizontalCenter: parent.horizontalCenter | ||
159 | 113 | } | ||
160 | 114 | Label { | ||
161 | 115 | text: action.text + index | ||
162 | 116 | width: parent.width | ||
163 | 117 | horizontalAlignment: Text.AlignHCenter | ||
164 | 118 | } | ||
165 | 119 | } | ||
166 | 104 | } | 120 | } |
167 | 105 | trailingActions: leading | 121 | trailingActions: leading |
168 | 106 | } | 122 | } |
169 | 107 | 123 | ||
170 | === modified file 'tests/unit_x11/tst_components/tst_listitem.qml' | |||
171 | --- tests/unit_x11/tst_components/tst_listitem.qml 2014-11-27 10:33:21 +0000 | |||
172 | +++ tests/unit_x11/tst_components/tst_listitem.qml 2014-11-27 10:33:24 +0000 | |||
173 | @@ -56,6 +56,15 @@ | |||
174 | 56 | id: actionsDefault | 56 | id: actionsDefault |
175 | 57 | } | 57 | } |
176 | 58 | 58 | ||
177 | 59 | Component { | ||
178 | 60 | id: customDelegate | ||
179 | 61 | Rectangle { | ||
180 | 62 | width: units.gu(10) | ||
181 | 63 | color: "green" | ||
182 | 64 | objectName: "custom_delegate" | ||
183 | 65 | } | ||
184 | 66 | } | ||
185 | 67 | |||
186 | 59 | Column { | 68 | Column { |
187 | 60 | width: parent.width | 69 | width: parent.width |
188 | 61 | ListItem { | 70 | ListItem { |
189 | @@ -150,6 +159,7 @@ | |||
190 | 150 | movingSpy.clear(); | 159 | movingSpy.clear(); |
191 | 151 | interactiveSpy.target = null; | 160 | interactiveSpy.target = null; |
192 | 152 | interactiveSpy.clear(); | 161 | interactiveSpy.clear(); |
193 | 162 | trailing.delegate = null; | ||
194 | 153 | } | 163 | } |
195 | 154 | 164 | ||
196 | 155 | function test_0_defaults() { | 165 | function test_0_defaults() { |
197 | @@ -384,5 +394,18 @@ | |||
198 | 384 | movingSpy.wait(); | 394 | movingSpy.wait(); |
199 | 385 | fuzzyCompare(data.item.contentItem.x, 0.0, 0.1, "Content not snapped out"); | 395 | fuzzyCompare(data.item.contentItem.x, 0.0, 0.1, "Content not snapped out"); |
200 | 386 | } | 396 | } |
201 | 397 | |||
202 | 398 | function test_custom_trailing_delegate() { | ||
203 | 399 | trailing.delegate = customDelegate; | ||
204 | 400 | listView.positionViewAtBeginning(); | ||
205 | 401 | var item = findChild(listView, "listItem0"); | ||
206 | 402 | flick(item, centerOf(item).x, centerOf(item).y, -units.gu(20), 0); | ||
207 | 403 | var panel = panelItem(item, false); | ||
208 | 404 | verify(panel, "Panel is not visible"); | ||
209 | 405 | var custom = findChild(panel, "custom_delegate"); | ||
210 | 406 | verify(custom, "Custom delegate not in use"); | ||
211 | 407 | // cleanup | ||
212 | 408 | rebound(item); | ||
213 | 409 | } | ||
214 | 387 | } | 410 | } |
215 | 388 | } | 411 | } |
58 + * The delegate height is set automatically by the panel item, and the width value
59 + * is clamped between height and the maximum width of the list item divided by the
60 + * number of actions in the list.
, and the width must be specified but will be clamped between....