Unity 8
 All Classes Functions
DashNavigationList.qml
1 /*
2  * Copyright (C) 2014 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.2
18 import Ubuntu.Components 1.1
19 import "../Components"
20 
21 Item {
22  id: root
23  property var navigation: null
24  property var currentNavigation: null
25  property var scopeStyle: null
26  property color foregroundColor: Theme.palette.normal.baseText
27  signal enterNavigation(var newNavigationId, bool hasChildren)
28  signal goBackToParentClicked()
29  signal allNavigationClicked()
30 
31  readonly property int itemHeight: units.gu(5)
32  implicitHeight: flickable.contentHeight
33 
34  Background {
35  style: root.scopeStyle ? root.scopeStyle.navigationBackground : "color:///#f5f5f5"
36  anchors.fill: parent
37  }
38 
39  clip: true
40 
41  Behavior on height {
42  UbuntuNumberAnimation {
43  id: heightAnimation
44  duration: UbuntuAnimation.SnapDuration
45  }
46  }
47 
48  Flickable {
49  id: flickable
50 
51  anchors.fill: parent
52 
53  flickableDirection: Flickable.VerticalFlick
54  contentHeight: column.height
55  contentWidth: width
56 
57  Column {
58  id: column
59  width: parent.width
60 
61  // TODO: check if SDK ListItems could be used here
62  // and if not make them be useful since this is a quite common pattern
63 
64  AbstractButton {
65  id: backButton
66  objectName: "backButton"
67  width: parent.width
68  visible: navigation && !navigation.isRoot || false
69  height: itemHeight
70 
71  onClicked: root.goBackToParentClicked();
72 
73  Icon {
74  id: backImage
75  anchors {
76  verticalCenter: parent.verticalCenter
77  left: parent.left
78  leftMargin: units.gu(2)
79  }
80  name: "back"
81  height: units.gu(2)
82  width: height
83  color: root.foregroundColor
84  }
85 
86  Label {
87  anchors {
88  verticalCenter: parent.verticalCenter
89  left: backImage.right
90  right: parent.right
91  leftMargin: units.gu(0.5)
92  rightMargin: units.gu(2)
93  }
94  text: navigation ? navigation.parentLabel : ""
95  color: root.foregroundColor
96  wrapMode: Text.Wrap
97  maximumLineCount: 2
98  elide: Text.ElideMiddle
99  }
100 
101  Rectangle {
102  anchors {
103  bottom: parent.bottom
104  left: parent.left
105  right: parent.right
106  leftMargin: units.gu(2)
107  rightMargin: units.gu(2)
108  }
109  color: root.foregroundColor
110  opacity: 0.2
111  height: units.dp(1)
112  }
113  }
114 
115  AbstractButton {
116  id: allButton
117  objectName: "allButton"
118  width: parent.width
119  visible: navigation && (!navigation.isRoot || (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
120  height: itemHeight
121 
122  Label {
123  anchors {
124  verticalCenter: parent.verticalCenter
125  left: parent.left
126  right: parent.right
127  leftMargin: units.gu(2)
128  rightMargin: units.gu(2)
129  }
130  text: navigation ? (navigation.allLabel != "" ? navigation.allLabel : navigation.label) : ""
131  font.bold: true
132  color: root.foregroundColor
133  wrapMode: Text.Wrap
134  maximumLineCount: 2
135  elide: Text.ElideMiddle
136  }
137 
138  Rectangle {
139  anchors {
140  bottom: parent.bottom
141  left: parent.left
142  right: parent.right
143  leftMargin: units.gu(2)
144  rightMargin: units.gu(2)
145  }
146  color: root.foregroundColor
147  opacity: 0.2
148  height: units.dp(1)
149  }
150 
151  onClicked: root.allNavigationClicked();
152  }
153 
154  Repeater {
155  model: navigation && navigation.loaded ? navigation : null
156  clip: true
157  delegate: AbstractButton {
158  objectName: root.objectName + "child" + index
159  height: root.itemHeight
160  width: root.width
161 
162  onClicked: root.enterNavigation(navigationId, hasChildren)
163 
164  Label {
165  anchors {
166  verticalCenter: parent.verticalCenter
167  left: parent.left
168  leftMargin: units.gu(2)
169  right: rightIcon.visible ? rightIcon.left : parent.right
170  rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
171  }
172  text: label
173  color: root.foregroundColor
174  wrapMode: Text.Wrap
175  maximumLineCount: 2
176  elide: Text.ElideMiddle
177  }
178 
179  Icon {
180  id: rightIcon
181  anchors {
182  verticalCenter: parent.verticalCenter
183  right: parent.right
184  rightMargin: units.gu(2)
185  }
186  height: units.gu(2)
187  width: height
188  name: hasChildren ? "go-next" : "tick"
189  color: root.foregroundColor
190  visible: hasChildren || isActive
191  }
192 
193  Rectangle {
194  anchors {
195  bottom: parent.bottom
196  left: parent.left
197  right: parent.right
198  leftMargin: units.gu(2)
199  rightMargin: units.gu(2)
200  }
201  color: root.foregroundColor
202  opacity: 0.1
203  height: units.dp(1)
204  visible: index != navigation.count - 1
205  }
206  }
207  }
208  }
209  }
210 }