on fb178ff help sign in
unity8/qml/Dash/PageHeaderExtraPanel.qml
202 lines 6.1 kB history raw
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 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Ubuntu.Components.ListItems 1.3 as ListItems
20import "Filters" as Filters
21import "../Components"
23Item {
24 id: root
26 readonly property real searchesHeight: recentSearchesRepeater.count > 0 ? searchColumn.height + recentSearchesLabels.height + recentSearchesLabels.anchors.topMargin : 0
28 implicitHeight: searchesHeight + dashNavigation.implicitHeight + dashNavigation.anchors.topMargin + primaryFilterContainer.height + primaryFilterContainer.anchors.topMargin
30 // Set by parent
31 property ListModel searchHistory
32 property var scope: null
33 property real windowHeight
35 // Used by PageHeader
36 readonly property bool hasContents: searchHistory.count > 0 || scope && scope.hasNavigation || scope && scope.primaryNavigationFilter
38 signal historyItemClicked(string text)
39 signal dashNavigationLeafClicked()
40 signal extraPanelOptionSelected()
42 function resetNavigation() {
43 dashNavigation.resetNavigation();
44 }
46 Rectangle {
47 color: "white"
48 anchors.fill: parent
49 }
51 ListItems.ThinDivider {
52 anchors.top: parent.top
53 }
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 }
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 }
78 AbstractButton {
79 anchors.fill: parent
80 onClicked: searchHistory.clear();
81 }
82 }
84 Column {
85 id: searchColumn
86 anchors {
87 top: recentSearchesLabels.bottom
88 left: parent.left
89 right: parent.right
90 }
92 Repeater {
93 id: recentSearchesRepeater
94 objectName: "recentSearchesRepeater"
95 model: searchHistory
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)
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 }
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 }
130 divider.visible: index != recentSearchesRepeater.count - 1 || (scope && scope.hasNavigation) || primaryFilter.active
132 onClicked: root.historyItemClicked(query)
133 }
134 }
135 }
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
148 onLeafClicked: root.dashNavigationLeafClicked();
149 }
151 Flickable {
152 id: primaryFilterContainer
153 objectName: "primaryFilterContainer"
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 }
165 clip: true
166 contentHeight: primaryFilter.implicitHeight
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 }
175 Filters.FilterWidgetFactory {
176 id: primaryFilter
177 objectName: "primaryFilter"
179 active: scope && !scope.hasNavigation
181 anchors.fill: parent
182 property var filter: active ? scope.primaryNavigationFilter : null
184 widgetId: filter ? filter.filterId : ""
185 widgetType: filter ? filter.filterType : -1
186 widgetData: filter
188 onSingleSelectionFilterSelected: extraPanelOptionSelected()
189 }
190 }
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 }