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