Unity 8
 All Classes Functions
MenuContent.qml
1 /*
2  * Copyright (C) 2013 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.0
18 import QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.1
20 import Unity.Indicators 0.1 as Indicators
21 import Utils 0.1
22 import "../Components"
23 import "../Components/Flickables" as Flickables
24 import "Indicators"
25 
26 Rectangle {
27  id: content
28 
29  property QtObject indicatorsModel: null
30  readonly property alias currentMenuIndex: listViewHeader.currentIndex
31  color: "#221e1c" // FIXME not in palette yet
32  property real headerHeight: listViewHeader.height
33 
34  width: units.gu(40)
35  height: units.gu(42)
36 
37  function setCurrentMenuIndex(index, animate) {
38  // FIXME - https://bugreports.qt-project.org/browse/QTBUG-41229
39  listViewHeader.currentIndex = -1;
40  listViewHeader.currentIndex = index;
41  }
42 
43  Flickables.ListView {
44  id: listViewHeader
45  objectName: "indicatorsHeaderListView"
46  model: content.indicatorsModel
47  clip: true
48 
49  anchors {
50  left: parent.left
51  right: parent.right
52  }
53  height: units.gu(8.5)
54 
55  highlightFollowsCurrentItem: true
56  highlightMoveDuration: 0
57 
58  orientation: ListView.Horizontal
59  snapMode: ListView.SnapOneItem
60  highlightRangeMode: ListView.StrictlyEnforceRange
61  boundsBehavior: Flickable.StopAtBounds
62  // Load all the indicator menus (a big number)
63  cacheBuffer: 1073741823
64 
65  delegate: Header {
66  width: ListView.view.width
67  height: implicitHeight
68 
69  title: indicatorDelegate.title !== "" ? indicatorDelegate.title : identifier
70 
71  IndicatorDelegate {
72  id: indicatorDelegate
73  Component.onCompleted: {
74  for(var pName in indicatorProperties) {
75  if (indicatorDelegate.hasOwnProperty(pName)) {
76  indicatorDelegate[pName] = indicatorProperties[pName];
77  }
78  }
79  }
80  }
81  }
82  }
83 
84  Flickables.ListView {
85  id: listViewContent
86  objectName: "indicatorsContentListView"
87  anchors {
88  left: parent.left
89  right: parent.right
90  top: listViewHeader.bottom
91  bottom: parent.bottom
92  }
93  model: content.indicatorsModel
94  clip: true
95 
96  currentIndex: listViewHeader.currentIndex
97  interactive: false
98  highlightMoveDuration: 0
99  orientation: ListView.Horizontal
100  // Load all the indicator menus (a big number)
101  cacheBuffer: 1073741823
102 
103  delegate: Loader {
104  id: loader
105  width: ListView.view.width
106  height: ListView.view.height
107  objectName: identifier
108 
109  source: pageSource
110  asynchronous: true
111 
112  onVisibleChanged: {
113  // Reset the indicator states
114  if (!visible && item && item["reset"]) {
115  item.reset()
116  }
117  }
118 
119  onLoaded: {
120  for(var pName in indicatorProperties) {
121  if (item.hasOwnProperty(pName)) {
122  item[pName] = indicatorProperties[pName]
123  }
124  }
125  }
126 
127  Binding {
128  target: loader.item
129  property: "identifier"
130  value: identifier
131  }
132 
133  Binding {
134  target: loader.item
135  property: "objectName"
136  value: identifier + "-page"
137  }
138  }
139  }
140 }