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