on 157e33e help sign in
unity8/qml/Dash/PageHeaderExtraPanel.qml
173 lines 5.2 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.margins : 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 }
62 }
64 Label {
65 text: i18n.tr("Clear All")
66 fontSize: "small"
67 visible: recentSearchesRepeater.count > 0
68 anchors {
69 top: parent.top
70 right: parent.right
71 margins: units.gu(2)
72 }
74 AbstractButton {
75 anchors.fill: parent
76 onClicked: searchHistory.clear();
77 }
78 }
80 Column {
81 id: searchColumn
82 anchors {
83 top: recentSearchesLabels.bottom
84 left: parent.left
85 right: parent.right
86 }
88 Repeater {
89 id: recentSearchesRepeater
90 objectName: "recentSearchesRepeater"
91 model: searchHistory
93 delegate: ListItem {
94 anchors {
95 left: parent.left
96 right: parent.right
97 leftMargin: units.gu(2)
98 rightMargin: units.gu(2)
99 }
100 height: units.gu(5)
102 Icon {
103 id: searchIcon
104 anchors {
105 verticalCenter: parent.verticalCenter
106 left: parent.left
107 }
108 height: units.gu(1.5)
109 width: height
110 name: "search"
111 }
113 Label {
114 anchors {
115 verticalCenter: parent.verticalCenter
116 left: searchIcon.right
117 leftMargin: units.gu(1)
118 right: parent.right
119 }
120 text: query
121 color: "#888888"
122 }
124 divider.visible: index != repeater.count - 1 || (scope && scope.hasNavigation) || primaryFilter.active
126 onClicked: root.historyItemClicked(text)
127 }
128 }
129 }
131 DashNavigation {
132 id: dashNavigation
133 scope: root.scope
134 anchors {
135 top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
136 topMargin: implicitHeight && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
137 left: parent.left
138 right: parent.right
139 }
140 availableHeight: windowHeight * 4 / 6 - searchesHeight
142 onLeafClicked: root.dashNavigationLeafClicked();
143 }
145 Filters.FilterWidgetFactory {
146 id: primaryFilter
147 active: scope && !scope.hasNavigation
149 property var filter: active ? scope.primaryNavigationFilter : null
151 anchors {
152 top: recentSearchesRepeater.count > 0 ? searchColumn.bottom : parent.top
153 topMargin: active && recentSearchesRepeater.count > 0 ? units.gu(2) : 0
154 left: parent.left
155 right: parent.right
156 }
158 widgetId: filter ? filter.filterId : ""
159 widgetType: filter ? filter.filterType : -1
160 widgetData: filter
161 }
163 // This is outside the item
164 Image {
165 anchors {
166 top: parent.bottom
167 left: parent.left
168 right: parent.right
169 }
170 fillMode: Image.Stretch
171 source: "graphics/navigation_shadow.png"
172 }