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