2
* Copyright 2014 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import Ubuntu.Components 1.3 as Toolkit
21
\qmltype UbuntuListView
22
\inqmlmodule Ubuntu.Components 1.1
24
\brief A ListView with special features tailored for a look and feel fitting the
25
Ubuntu Touch platform.
26
The UbuntuListView works just like a regular ListView, but it adds special features
27
such as expanding/collapsing items (when used together with the Expandable item).
28
It provides features like automatically positioning the expanding item when it
29
expands and collapsing it again when the user taps outside of it.
33
import Ubuntu.Components 1.3
34
import Ubuntu.Components.ListItems 1.3 as ListItem
43
anchors { left: parent.left; right: parent.right }
47
delegate: ListItem.Expandable {
50
expandedHeight: units.gu(30)
53
ubuntuListView.expandedIndex = index;
65
The index of the currently expanded item. -1 if no item is expanded.
67
property int expandedIndex: -1
72
function positionViewAtIndexAnimated(expandedIndex) {
73
animation.from = root.contentY;
74
root.currentIndex = expandedIndex;
75
if (expandedIndex == root.count - 1) {
76
root.positionViewAtIndex(expandedIndex, ListView.End);
78
root.positionViewAtIndex(expandedIndex + 1, ListView.End);
81
var effectiveExpandedHeight = Math.min(root.currentItem.expandedHeight, root.height - root.currentItem.collapsedHeight);
82
if (root.contentY - root.originY == 0) {
83
if (((root.currentIndex + 1) * root.currentItem.collapsedHeight) + effectiveExpandedHeight > root.height) {
84
animation.to = ((root.currentIndex + 1) * root.currentItem.collapsedHeight + effectiveExpandedHeight) - root.height + root.originY
86
animation.to = root.originY
89
animation.to = root.contentY + (effectiveExpandedHeight - root.currentItem.collapsedHeight);
94
function requestFocus(reason) {
95
// lookup for the currentItem, and if it is a FocusScope, focus the view
96
// this will also focus the currentItem
97
if (root.currentItem && root.currentItem.hasOwnProperty("activeFocusOnPress")) {
98
root.forceActiveFocus(reason);
107
Grab focus when moved, flicked or clicked
109
onMovementStarted: priv.requestFocus(Qt.MouseFocusReason)
110
onFlickStarted: priv.requestFocus(Qt.MouseFocusReason)
111
Toolkit.Mouse.onClicked: priv.requestFocus(Qt.MouseFocusReason)
114
Expand the item at the given index.
116
onExpandedIndexChanged: {
117
if (expandedIndex < 0) {
120
priv.positionViewAtIndexAnimated(expandedIndex, ListView.End)
133
enabled: root.expandedIndex != -1
134
onClicked: root.expandedIndex = -1;
137
// animate move displaced
138
moveDisplaced: Transition {