on 239fdcc help sign in
unity8/qml/Dash/PageHeaderExtraPanel.qml
176 lines 5.3 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
22Item {
23 id: root
25 readonly property real searchesHeight: recentSearchesRepeater.count > 0 ? searchColumn.height + recentSearchesLabels.height + recentSearchesLabels.anchors.topMargin : 0
27 implicitHeight: searchesHeight + dashNavigation.implicitHeight + dashNavigation.anchors.topMargin + primaryFilter.height + primaryFilter.anchors.topMargin
29 // Set by parent
30 property ListModel searchHistory
31 property var scope: null
32 property real windowHeight
34 // Used by PageHeader
35 readonly property bool hasContents: searchHistory.count > 0 || scope && scope.hasNavigation || scope && scope.primaryNavigationFilter
37 signal historyItemClicked(string text)
38 signal dashNavigationLeafClicked()
40 function resetNavigation() {
41 dashNavigation.resetNavigation();
42 }
44 Rectangle {
45 color: "white"
46 anchors.fill: parent
47 }
49 ListItems.ThinDivider {
50 anchors.top: parent.top
51 }
53 Label {
54 id: recentSearchesLabels
55 text: i18n.tr("Recent Searches")
56 visible: recentSearchesRepeater.count > 0
57 anchors {
58 top: parent.top
59 left: parent.left
60 margins: units.gu(2)
61 topMargin: units.gu(3)
62 }
63 }
65 Label {
66 text: i18n.tr("Clear All")
67 fontSize: "small"
68 visible: recentSearchesRepeater.count > 0
69 anchors {
70 top: parent.top
71 right: parent.right
72 margins: units.gu(2)
73 topMargin: units.gu(3)
74 }
76 AbstractButton {
77 anchors.fill: parent
78 onClicked: searchHistory.clear();
79 }
80 }
82 Column {
83 id: searchColumn
84 anchors {
85 top: recentSearchesLabels.bottom
86 left: parent.left
87 right: parent.right
88 }
90 Repeater {
91 id: recentSearchesRepeater
92 objectName: "recentSearchesRepeater"
93 model: searchHistory
95 // FIXME Move to ListItem once 1556971 is fixed
96 delegate: ListItems.Empty {
97 anchors {
98 left: parent.left
99 right: parent.right
100 leftMargin: units.gu(2)
101 rightMargin: units.gu(2)
102 }
103 height: units.gu(5)
105 Icon {
106 id: searchIcon
107 anchors {
108 verticalCenter: parent.verticalCenter
109 left: parent.left
110 }
111 height: units.gu(1.5)
112 width: height
113 name: "search"
114 }
116 Label {
117 anchors {
118 verticalCenter: parent.verticalCenter
119 left: searchIcon.right
120 leftMargin: units.gu(1)
121 right: parent.right
122 }
123 text: query
124 color: "#888888"
125 }
127 divider.visible: index != repeater.count - 1 || (scope && scope.hasNavigation) || primaryFilter.active
129 onClicked: root.historyItemClicked(query)
130 }
131 }
132 }
134 DashNavigation {
135 id: dashNavigation
136 scope: root.scope
137 anchors {
138 top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
139 topMargin: implicitHeight && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
140 left: parent.left
141 right: parent.right
142 }
143 availableHeight: windowHeight * 4 / 6 - searchesHeight
145 onLeafClicked: root.dashNavigationLeafClicked();
146 }
148 Filters.FilterWidgetFactory {
149 id: primaryFilter
150 active: scope && !scope.hasNavigation
152 property var filter: active ? scope.primaryNavigationFilter : null
154 anchors {
155 top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
156 topMargin: active && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
157 left: parent.left
158 right: parent.right
159 }
161 widgetId: filter ? filter.filterId : ""
162 widgetType: filter ? filter.filterType : -1
163 widgetData: filter
164 }
166 // This is outside the item
167 Image {
168 anchors {
169 top: parent.bottom
170 left: parent.left
171 right: parent.right
172 }
173 fillMode: Image.Stretch
174 source: "graphics/navigation_shadow.png"
175 }