Unity 8
DashNavigationList.qml
1 /*
2  * Copyright (C) 2014,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 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU 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 Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3 as ListItem
20 import "../Components"
21 
22 Item {
23  id: root
24  property var navigation: null
25  property var currentNavigation: null
26  property var scopeStyle: null
27  property color foregroundColor: theme.palette.normal.baseText
28  signal enterNavigation(var newNavigationId, bool hasChildren)
29  signal goBackToParentClicked()
30  signal allNavigationClicked()
31 
32  readonly property int itemHeight: units.gu(5)
33  implicitHeight: flickable.contentHeight
34 
35  Background {
36  style: root.scopeStyle ? root.scopeStyle.navigationBackground : "color:///#f5f5f5"
37  anchors.fill: parent
38  }
39 
40  clip: true
41 
42  Behavior on height {
43  UbuntuNumberAnimation {
44  id: heightAnimation
45  duration: UbuntuAnimation.SnapDuration
46  }
47  }
48 
49  Flickable {
50  id: flickable
51 
52  anchors.fill: parent
53 
54  flickableDirection: Flickable.VerticalFlick
55  contentHeight: column.height
56  contentWidth: width
57 
58  Column {
59  id: column
60  width: parent.width
61 
62  ListItem.Standard {
63  id: backButton
64  objectName: "backButton"
65  visible: navigation && !navigation.isRoot || false
66  height: itemHeight
67 
68  onClicked: root.goBackToParentClicked();
69 
70  Icon {
71  id: backImage
72  anchors {
73  verticalCenter: parent.verticalCenter
74  left: parent.left
75  leftMargin: units.gu(2)
76  }
77  name: "back"
78  height: units.gu(2)
79  width: height
80  color: root.foregroundColor
81  }
82 
83  Label {
84  anchors {
85  verticalCenter: parent.verticalCenter
86  left: backImage.right
87  right: parent.right
88  leftMargin: units.gu(0.5)
89  rightMargin: units.gu(2)
90  }
91  text: navigation ? navigation.parentLabel : ""
92  color: root.foregroundColor
93  wrapMode: Text.Wrap
94  maximumLineCount: 2
95  elide: Text.ElideMiddle
96  }
97  }
98 
99  ListItem.Standard {
100  id: allButton
101  objectName: "allButton"
102  visible: navigation && (!navigation.isRoot || (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
103  height: itemHeight
104 
105  Label {
106  anchors {
107  verticalCenter: parent.verticalCenter
108  left: parent.left
109  right: parent.right
110  leftMargin: units.gu(2)
111  rightMargin: units.gu(2)
112  }
113  text: navigation ? (navigation.allLabel != "" ? navigation.allLabel : navigation.label) : ""
114  font.bold: true
115  color: root.foregroundColor
116  wrapMode: Text.Wrap
117  maximumLineCount: 2
118  elide: Text.ElideMiddle
119  }
120 
121  onClicked: root.allNavigationClicked();
122  }
123 
124  Repeater {
125  model: navigation && navigation.loaded ? navigation : null
126  clip: true
127  delegate: ListItem.Standard {
128  objectName: root.objectName + "child" + index
129  height: root.itemHeight
130  showDivider: index != navigation.count - 1
131  selected: isActive
132 
133  onClicked: root.enterNavigation(navigationId, hasChildren)
134 
135  Label {
136  anchors {
137  verticalCenter: parent.verticalCenter
138  left: parent.left
139  leftMargin: units.gu(2)
140  right: rightIcon.visible ? rightIcon.left : parent.right
141  rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
142  }
143  text: label
144  color: root.foregroundColor
145  wrapMode: Text.Wrap
146  maximumLineCount: 2
147  elide: Text.ElideMiddle
148  }
149 
150  Icon {
151  id: rightIcon
152  anchors {
153  verticalCenter: parent.verticalCenter
154  right: parent.right
155  rightMargin: units.gu(2)
156  }
157  height: units.gu(2)
158  width: height
159  name: hasChildren ? "go-next" : "tick"
160  color: root.foregroundColor
161  visible: hasChildren || isActive
162  }
163  }
164  }
165  }
166  }
167 }