Merge lp:~zsombi/ubuntu-ui-toolkit/50-custom-delegates into lp:~zsombi/ubuntu-ui-toolkit/listitem-master

Proposed by Zsombor Egri
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
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.

To post a comment you must log in.
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

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

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....

Revision history for this message
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:

        ListItemActions {
            id: trailActions
            actions: [
                Action {
                    iconName: "save-to"
                    text: "Move"
                    onTriggered: print("Move" +value)
                }
            ]
            delegate: Rectangle {
                color: delegateArea.pressed ? "orange" : "yellow"
                width: units.gu(10)
                Label {
                    text: action.text
                    anchors.centerIn: parent
                }
                MouseArea {
                    anchors.fill: parent
                    id: delegateArea
                    onPressed: print("press")
                }
            }
        }

but that eats the mouse events and prevents the trigger() signal on clicked.

Revision history for this message
Tim Peeters (tpeeters) :
review: Needs Fixing
1291. By Zsombor Egri

review comments added

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

thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml'
--- modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml 2014-11-27 10:33:21 +0000
+++ modules/Ubuntu/Components/Themes/Ambiance/ListItemPanel.qml 2014-11-27 10:33:24 +0000
@@ -101,6 +101,7 @@
101 Repeater {101 Repeater {
102 model: panel.ListItemActions.visibleActions102 model: panel.ListItemActions.visibleActions
103 AbstractButton {103 AbstractButton {
104 id: actionButton
104 action: modelData105 action: modelData
105 enabled: action.enabled106 enabled: action.enabled
106 opacity: action.enabled ? 1.0 : 0.5107 opacity: action.enabled ? 1.0 : 0.5
@@ -124,9 +125,10 @@
124 Loader {125 Loader {
125 id: delegateLoader126 id: delegateLoader
126 height: parent.height127 height: parent.height
127 sourceComponent: panel.ListItemActions.delegate ? panel.ListItemActions.delegate : defaultDelegate128 sourceComponent: panel.ListItemActions.container.delegate ? panel.ListItemActions.container.delegate : defaultDelegate
128 property Action action: modelData129 property Action action: modelData
129 property int index: index130 property int index: index
131 property bool pressed: actionButton.pressed
130 onItemChanged: {132 onItemChanged: {
131 // use action's objectName to identify the visualized action133 // use action's objectName to identify the visualized action
132 if (item && item.objectName === "") {134 if (item && item.objectName === "") {
133135
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp'
--- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-27 10:33:21 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-27 10:33:24 +0000
@@ -1087,7 +1087,7 @@
1087 */1087 */
10881088
1089/*!1089/*!
1090 * \qmlsignal UCListItemPrivate::contentMovementEnded1090 * \qmlsignal ListItem::contentMovementEnded()
1091 * The signal is emitted when the content movement has ended.1091 * The signal is emitted when the content movement has ended.
1092 */1092 */
1093bool UCListItemPrivate::contentMoving() const1093bool UCListItemPrivate::contentMoving() const
10941094
=== modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.cpp'
--- modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-27 10:33:21 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-27 10:33:24 +0000
@@ -260,8 +260,8 @@
260 * ListItemActions instances can be shared between ListItem instances within the260 * ListItemActions instances can be shared between ListItem instances within the
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,
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.
263 * Depending on how long the initialization of the component used in \c ListItem::actionsDelegate263 * Depending on how long the initialization of the component used in \l {ListItemStyle::actionsDelegate}
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.
265 * However, this implies that swiping a new ListItem content while another one is265 * However, this implies that swiping a new ListItem content while another one is
266 * swiped will result in showing the newly swiped item's panel delayed, as the266 * swiped will result in showing the newly swiped item's panel delayed, as the
267 * panel can be shown only after the previous item's snapping is completed. Depending267 * panel can be shown only after the previous item's snapping is completed. Depending
@@ -393,8 +393,67 @@
393393
394/*!394/*!
395 * \qmlproperty Component ListItemActions::delegate395 * \qmlproperty Component ListItemActions::delegate
396 * Custom delegate which overrides the default one used by the ListItem. If the396 * The property holds the custom delegate to visualize the actions listed in the
397 * value is null, the default delegate will be used.397 * ListItemActions. When set to null, the default delegate specified by the \l
398 * {ListItemStyle::actionsDelegate}{actionsDelegate} will be used.
399 *
400 * ListItemActions provides the \c action context property which contains the
401 * Action instance visualized. Using this property delegates can access
402 * the information to be visualized. The action is triggered by the panel item
403 * holding the visualized action, therefore only visualization is needed by the
404 * custom delegate. The other context property exposed to delegates is the \c
405 * index, which specifies the index of the action visualized.
406 *
407 * Specifying a custom delegate will not override the triggering logic of the
408 * action, that will be still handled by the panel itself. However custom delegates
409 * may still need to distinguish the pressed/released state visually. This can
410 * be achieved using the \c pressed context property, which informs the delegate
411 * about the pressed state of the action.
412 *
413 * The delegate height is set automatically by the panel item, only the width must
414 * be specified which will be clamped between height and the maximum width of the
415 * list item divided by the number of actions in the list.
416 * \qml
417 * import QtQuick 2.2
418 * import Ubuntu.Components 1.2
419 *
420 * MainView {
421 * width: units.gu(40)
422 * height: units.gu(71)
423 *
424 * UbuntuListView {
425 * anchors.fill: parent
426 * model: 50
427 * delegate: ListItem {
428 * trailingActions: actionsList
429 * }
430 * ListItemActions {
431 * id: actionsList
432 * delegate: Column {
433 * width: height + units.gu(2)
434 * Icon {
435 * name: action.iconName
436 * width: units.gu(3)
437 * height: width
438 * color: pressed ? "blue" : "lightblue"
439 * anchors.horizontalCenter: parent.horizontalCenter
440 * }
441 * Label {
442 * text: action.text + "#" + index
443 * width: parent.width
444 * horizontalAlignment: Text.AlignHCenter
445 * }
446 * }
447 * actions: Action {
448 * iconName: "starred"
449 * text: "Star"
450 * }
451 * }
452 * }
453 * }
454 * \endqml
455 * \note Putting a Rectangle in the delegate can be used to override the color
456 * of the panel.
398 *457 *
399 * Defaults to null.458 * Defaults to null.
400 */459 */
401460
=== modified file 'modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp'
--- modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-27 10:33:21 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-27 10:33:24 +0000
@@ -212,7 +212,7 @@
212}212}
213213
214/*!214/*!
215 * \qmlproperty real ListItemActions::overshoot215 * \qmlattachedproperty real ListItemActions::overshoot
216 * The property holds the overshoot value set for the list item.216 * The property holds the overshoot value set for the list item.
217 */217 */
218qreal UCListItemActionsAttached::overshoot()218qreal UCListItemActionsAttached::overshoot()
219219
=== modified file 'tests/resources/listitems/ListItemTest.qml'
--- tests/resources/listitems/ListItemTest.qml 2014-11-27 10:33:21 +0000
+++ tests/resources/listitems/ListItemTest.qml 2014-11-27 10:33:24 +0000
@@ -28,6 +28,7 @@
28 objectName: "stock"28 objectName: "stock"
29 id: stock29 id: stock
30 iconName: "starred"30 iconName: "starred"
31 text: "Staaaar"
31 onTriggered: print(iconName, "triggered")32 onTriggered: print(iconName, "triggered")
32 }33 }
3334
@@ -101,6 +102,21 @@
101 leadingActions: ListItemActions {102 leadingActions: ListItemActions {
102 objectName: "InlineLeading"103 objectName: "InlineLeading"
103 actions: [stock]104 actions: [stock]
105 delegate: Column {
106 width: height + units.gu(2)
107 Icon {
108 width: units.gu(3)
109 height: width
110 name: action.iconName
111 color: "blue"
112 anchors.horizontalCenter: parent.horizontalCenter
113 }
114 Label {
115 text: action.text + index
116 width: parent.width
117 horizontalAlignment: Text.AlignHCenter
118 }
119 }
104 }120 }
105 trailingActions: leading121 trailingActions: leading
106 }122 }
107123
=== modified file 'tests/unit_x11/tst_components/tst_listitem.qml'
--- tests/unit_x11/tst_components/tst_listitem.qml 2014-11-27 10:33:21 +0000
+++ tests/unit_x11/tst_components/tst_listitem.qml 2014-11-27 10:33:24 +0000
@@ -56,6 +56,15 @@
56 id: actionsDefault56 id: actionsDefault
57 }57 }
5858
59 Component {
60 id: customDelegate
61 Rectangle {
62 width: units.gu(10)
63 color: "green"
64 objectName: "custom_delegate"
65 }
66 }
67
59 Column {68 Column {
60 width: parent.width69 width: parent.width
61 ListItem {70 ListItem {
@@ -150,6 +159,7 @@
150 movingSpy.clear();159 movingSpy.clear();
151 interactiveSpy.target = null;160 interactiveSpy.target = null;
152 interactiveSpy.clear();161 interactiveSpy.clear();
162 trailing.delegate = null;
153 }163 }
154164
155 function test_0_defaults() {165 function test_0_defaults() {
@@ -384,5 +394,18 @@
384 movingSpy.wait();394 movingSpy.wait();
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");
386 }396 }
397
398 function test_custom_trailing_delegate() {
399 trailing.delegate = customDelegate;
400 listView.positionViewAtBeginning();
401 var item = findChild(listView, "listItem0");
402 flick(item, centerOf(item).x, centerOf(item).y, -units.gu(20), 0);
403 var panel = panelItem(item, false);
404 verify(panel, "Panel is not visible");
405 var custom = findChild(panel, "custom_delegate");
406 verify(custom, "Custom delegate not in use");
407 // cleanup
408 rebound(item);
409 }
387 }410 }
388}411}

Subscribers

People subscribed via source and target branches

to all changes: