~zeller-benjamin/ubuntu-ui-toolkit/qrcify3

« back to all changes in this revision

Viewing changes to tests/resources/listitems/ListItemExpansion.qml

  • Committer: Benjamin Zeller
  • Date: 2015-09-10 08:43:12 UTC
  • mfrom: (1585.1.2 staging)
  • Revision ID: benjamin.zeller@canonical.com-20150910084312-6eh8n2729jpslgmb
Merge staging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import QtQuick.Layouts 1.1
 
19
import Ubuntu.Components 1.3
 
20
 
 
21
MainView {
 
22
    id: main
 
23
    width: units.gu(40)
 
24
    height: units.gu(71)
 
25
 
 
26
    Action {
 
27
        id: deleteAction
 
28
        iconName: "delete"
 
29
    }
 
30
    property list<Action> contextualActions: [
 
31
        Action {
 
32
            iconName: "edit"
 
33
        },
 
34
        Action {
 
35
            iconName: "share"
 
36
        },
 
37
        Action {
 
38
            iconName: "stock_website"
 
39
        }
 
40
    ]
 
41
    Page {
 
42
        title: "Expansion"
 
43
        Column {
 
44
            anchors.fill: parent
 
45
            spacing: units.dp(4)
 
46
            UbuntuListView {
 
47
                id: listView
 
48
                onEnabledChanged: print("enabled", enabled)
 
49
                width: parent.width
 
50
                height: parent.height / 2
 
51
                clip: true
 
52
                ViewItems.onExpandedIndicesChanged: print(ViewItems.expandedIndices)
 
53
                ViewItems.expansionFlags: ViewItems.CollapseOnOutsidePress
 
54
 
 
55
                model: ListModel {
 
56
                    Component.onCompleted: {
 
57
                        for (var i = 0; i < 3; i++) {
 
58
                            append({label: "List item #"+i, sectionData: "Locked"});
 
59
                        }
 
60
                        for (i = 3; i < 11; i++) {
 
61
                            append({label: "List item #"+i, sectionData: "Limited, live move"});
 
62
                        }
 
63
                        for (i = 11; i < 25; i++) {
 
64
                            append({label: "List item #"+i, sectionData: "Unlimited, drag'n'drop"});
 
65
                        }
 
66
                    }
 
67
                }
 
68
 
 
69
                delegate: ListItem {
 
70
                    id: item
 
71
                    objectName: "ListItem-" + index
 
72
                    leadingActions: ListItemActions {
 
73
                        actions: deleteAction
 
74
                    }
 
75
                    trailingActions: ListItemActions {
 
76
                        actions: contextualActions
 
77
                    }
 
78
                    expansion.height: units.gu(15)
 
79
 
 
80
                    RowLayout {
 
81
                        anchors {
 
82
                            fill: parent
 
83
                            margins: units.gu(0.5)
 
84
                            leftMargin: anchors.rightMargin
 
85
                            rightMargin: units.gu(2)
 
86
                        }
 
87
                        Captions {
 
88
                            id: captions
 
89
                            title.text: label
 
90
                            subtitle.text: "from index #" + index
 
91
                        }
 
92
                        Button {
 
93
                            text: "Enable drag mode"
 
94
                            onClicked: listView.ViewItems.dragMode = true
 
95
                        }
 
96
                    }
 
97
 
 
98
                    onPressAndHold: {
 
99
                        print("expand/collapse")
 
100
                        expansion.expanded = !expansion.expanded
 
101
                    }
 
102
                }
 
103
            }
 
104
            ListItem {
 
105
                Label { text: "Standalone ListItem" }
 
106
                expansion.height: units.gu(15)
 
107
                onPressAndHold: expansion.expanded = !expansion.expanded;
 
108
            }
 
109
            ListItem {
 
110
                Label { text: "Other Standalone ListItem" }
 
111
                expansion.height: units.gu(15)
 
112
                onPressAndHold: expansion.expanded = !expansion.expanded;
 
113
            }
 
114
 
 
115
            Button {
 
116
                text: "Set ListView.ViewItems.expandedIndices"
 
117
                onClicked: listView.ViewItems.expandedIndices = [0, 1, 2]
 
118
            }
 
119
        }
 
120
    }
 
121
}