Unity 8
PageHeaderExtraPanel.qml
1 /*
2  * Copyright (C) 2013-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 ListItems
20 import "Filters" as Filters
21 
22 Item {
23  id: root
24 
25  readonly property real searchesHeight: recentSearchesRepeater.count > 0 ? searchColumn.height + recentSearchesLabels.height + recentSearchesLabels.anchors.topMargin : 0
26 
27  implicitHeight: searchesHeight + dashNavigation.implicitHeight + dashNavigation.anchors.topMargin + primaryFilterContainer.height + primaryFilterContainer.anchors.topMargin
28 
29  // Set by parent
30  property ListModel searchHistory
31  property var scope: null
32  property real windowHeight
33 
34  // Used by PageHeader
35  readonly property bool hasContents: searchHistory.count > 0 || scope && scope.hasNavigation || scope && scope.primaryNavigationFilter
36 
37  signal historyItemClicked(string text)
38  signal dashNavigationLeafClicked()
39  signal extraPanelOptionSelected()
40 
41  function resetNavigation() {
42  dashNavigation.resetNavigation();
43  }
44 
45  Rectangle {
46  color: "white"
47  anchors.fill: parent
48  }
49 
50  ListItems.ThinDivider {
51  anchors.top: parent.top
52  }
53 
54  Label {
55  id: recentSearchesLabels
56  text: i18n.tr("Recent Searches")
57  visible: recentSearchesRepeater.count > 0
58  anchors {
59  top: parent.top
60  left: parent.left
61  margins: units.gu(2)
62  topMargin: units.gu(3)
63  }
64  }
65 
66  Label {
67  text: i18n.tr("Clear All")
68  fontSize: "small"
69  visible: recentSearchesRepeater.count > 0
70  anchors {
71  top: parent.top
72  right: parent.right
73  margins: units.gu(2)
74  topMargin: units.gu(3)
75  }
76 
77  AbstractButton {
78  anchors.fill: parent
79  onClicked: searchHistory.clear();
80  }
81  }
82 
83  Column {
84  id: searchColumn
85  anchors {
86  top: recentSearchesLabels.bottom
87  left: parent.left
88  right: parent.right
89  }
90 
91  Repeater {
92  id: recentSearchesRepeater
93  objectName: "recentSearchesRepeater"
94  model: searchHistory
95 
96  // FIXME Move to ListItem once 1556971 is fixed
97  delegate: ListItems.Empty {
98  anchors {
99  left: parent.left
100  right: parent.right
101  leftMargin: units.gu(2)
102  rightMargin: units.gu(2)
103  }
104  height: units.gu(5)
105 
106  Icon {
107  id: searchIcon
108  anchors {
109  verticalCenter: parent.verticalCenter
110  left: parent.left
111  }
112  height: units.gu(1.5)
113  width: height
114  name: "search"
115  }
116 
117  Label {
118  anchors {
119  verticalCenter: parent.verticalCenter
120  left: searchIcon.right
121  leftMargin: units.gu(1)
122  right: parent.right
123  }
124  text: query
125  color: "#888888"
126  }
127 
128  divider.visible: index != recentSearchesRepeater.count - 1 || (scope && scope.hasNavigation) || primaryFilter.active
129 
130  onClicked: root.historyItemClicked(query)
131  }
132  }
133  }
134 
135  DashNavigation {
136  id: dashNavigation
137  scope: root.scope
138  anchors {
139  top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
140  topMargin: implicitHeight && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
141  left: parent.left
142  right: parent.right
143  }
144  availableHeight: windowHeight * 4 / 6 - searchesHeight
145 
146  onLeafClicked: root.dashNavigationLeafClicked();
147  }
148 
149  Flickable {
150  id: primaryFilterContainer
151  objectName: "primaryFilterContainer"
152 
153  height: {
154  if (!primaryFilter.active) {
155  return 0;
156  } else if (contentHeight > dashNavigation.availableHeight) {
157  return dashNavigation.availableHeight;
158  } else {
159  return contentHeight;
160  }
161  }
162 
163  clip: true
164  contentHeight: primaryFilter.implicitHeight
165 
166  anchors {
167  top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
168  topMargin: primaryFilter.active && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
169  left: parent.left
170  right: parent.right
171  }
172 
173  Filters.FilterWidgetFactory {
174  id: primaryFilter
175  objectName: "primaryFilter"
176 
177  active: scope && !scope.hasNavigation
178 
179  anchors.fill: parent
180  property var filter: active ? scope.primaryNavigationFilter : null
181 
182  widgetId: filter ? filter.filterId : ""
183  widgetType: filter ? filter.filterType : -1
184  widgetData: filter
185 
186  onSingleSelectionFilterSelected: extraPanelOptionSelected()
187  }
188  }
189 
190  // This is outside the item
191  Image {
192  anchors {
193  top: parent.bottom
194  left: parent.left
195  right: parent.right
196  }
197  fillMode: Image.Stretch
198  source: "graphics/navigation_shadow.png"
199  }
200 }