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 import "../Components/Flickables" as Flickables
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  Flickables.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  // TODO: check if SDK ListItems could be used here
63  // and if not make them be useful since this is a quite common pattern
64 
65  AbstractButton {
66  id: backButton
67  objectName: "backButton"
68  width: parent.width
69  visible: navigation && !navigation.isRoot || false
70  height: itemHeight
71 
72  onClicked: root.goBackToParentClicked();
73 
74  Icon {
75  id: backImage
76  anchors {
77  verticalCenter: parent.verticalCenter
78  left: parent.left
79  leftMargin: units.gu(2)
80  }
81  name: "back"
82  height: units.gu(2)
83  width: height
84  color: root.foregroundColor
85  }
86 
87  Label {
88  anchors {
89  verticalCenter: parent.verticalCenter
90  left: backImage.right
91  right: parent.right
92  leftMargin: units.gu(0.5)
93  rightMargin: units.gu(2)
94  }
95  text: navigation ? navigation.parentLabel : ""
96  color: root.foregroundColor
97  wrapMode: Text.Wrap
98  maximumLineCount: 2
99  elide: Text.ElideMiddle
100  }
101 
102  Rectangle {
103  anchors {
104  bottom: parent.bottom
105  left: parent.left
106  right: parent.right
107  leftMargin: units.gu(2)
108  rightMargin: units.gu(2)
109  }
110  color: root.foregroundColor
111  opacity: 0.2
112  height: units.dp(1)
113  }
114  }
115 
116  AbstractButton {
117  id: allButton
118  objectName: "allButton"
119  width: parent.width
120  visible: navigation && (!navigation.isRoot || (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
121  height: itemHeight
122 
123  Label {
124  anchors {
125  verticalCenter: parent.verticalCenter
126  left: parent.left
127  right: parent.right
128  leftMargin: units.gu(2)
129  rightMargin: units.gu(2)
130  }
131  text: navigation ? (navigation.allLabel != "" ? navigation.allLabel : navigation.label) : ""
132  font.bold: true
133  color: root.foregroundColor
134  wrapMode: Text.Wrap
135  maximumLineCount: 2
136  elide: Text.ElideMiddle
137  }
138 
139  Rectangle {
140  anchors {
141  bottom: parent.bottom
142  left: parent.left
143  right: parent.right
144  leftMargin: units.gu(2)
145  rightMargin: units.gu(2)
146  }
147  color: root.foregroundColor
148  opacity: 0.2
149  height: units.dp(1)
150  }
151 
152  onClicked: root.allNavigationClicked();
153  }
154 
155  Repeater {
156  model: navigation && navigation.loaded ? navigation : null
157  clip: true
158  delegate: AbstractButton {
159  objectName: root.objectName + "child" + index
160  height: root.itemHeight
161  width: root.width
162 
163  onClicked: root.enterNavigation(navigationId, hasChildren)
164 
165  Label {
166  anchors {
167  verticalCenter: parent.verticalCenter
168  left: parent.left
169  leftMargin: units.gu(2)
170  right: rightIcon.visible ? rightIcon.left : parent.right
171  rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
172  }
173  text: label
174  color: root.foregroundColor
175  wrapMode: Text.Wrap
176  maximumLineCount: 2
177  elide: Text.ElideMiddle
178  }
179 
180  Icon {
181  id: rightIcon
182  anchors {
183  verticalCenter: parent.verticalCenter
184  right: parent.right
185  rightMargin: units.gu(2)
186  }
187  height: units.gu(2)
188  width: height
189  name: hasChildren ? "go-next" : "tick"
190  color: root.foregroundColor
191  visible: hasChildren || isActive
192  }
193 
194  Rectangle {
195  anchors {
196  bottom: parent.bottom
197  left: parent.left
198  right: parent.right
199  leftMargin: units.gu(2)
200  rightMargin: units.gu(2)
201  }
202  color: root.foregroundColor
203  opacity: 0.1
204  height: units.dp(1)
205  visible: index != navigation.count - 1
206  }
207  }
208  }
209  }
210  }
211 }