2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18import Ubuntu.Components 1.1
19import Ubuntu.Components.Themes.Ambiance 1.1
20import Ubuntu.Components.Popups 1.0
21import Ubuntu.Components.ListItems 1.0
22import "SearchHistoryModel"
26 objectName: "pageHeader"
27 implicitHeight: headerContainer.height + units.gu(2) + bottomContainer.height
29 property bool showBackButton: false
32 property bool searchEntryEnabled: false
33 property ListModel searchHistory: SearchHistoryModel
34 property alias searchQuery: searchTextField.text
36 property alias bottomItem: bottomContainer.children
37 property int paginationCount: 0
38 property int paginationIndex: -1
40 // TODO We should use foreground for the icons
41 // of the toolbar but unfortunately Action does not have
42 // the keyColor property as Icon does :-/
43 property var scopeStyle: null
47 onScopeStyleChanged: refreshLogo()
48 onSearchQueryChanged: {
49 // Make sure we are at the search page if the search query changes behind our feet
51 headerContainer.showSearch = true;
55 function triggerSearch() {
56 if (searchEntryEnabled) {
57 headerContainer.showSearch = true;
58 searchTextField.forceActiveFocus();
62 function closePopup() {
63 if (headerContainer.popover != null) {
64 PopupUtils.close(headerContainer.popover);
68 function resetSearch(keepFocus) {
70 searchHistory.addQuery(searchTextField.text);
75 searchTextField.text = "";
80 searchTextField.focus = false;
81 if (!searchTextField.text) {
82 headerContainer.showSearch = false;
86 function openSearchHistory() {
87 if (openSearchAnimation.running) {
88 openSearchAnimation.openSearchHistory = true;
89 } else if (root.searchHistory.count > 0 && headerContainer.popover == null) {
90 headerContainer.popover = PopupUtils.open(popoverComponent, searchTextField,
92 "contentWidth": searchTextField.width,
93 "edgeMargins": units.gu(1)
99 function refreshLogo() {
100 if (scopeStyle ? scopeStyle.headerLogo != "" : false) {
101 header.contents = imageComponent.createObject();
102 } else if (header.contents) {
103 header.contents.destroy();
104 header.contents = null;
109 target: root.scopeStyle
110 onHeaderLogoChanged: root.refreshLogo()
114 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
115 visible: headerContainer.showSearch
118 if (!searchTextField.text) {
119 headerContainer.showSearch = false;
121 searchTextField.focus = false;
122 mouse.accepted = false;
128 objectName: "headerContainer"
129 clip: contentY < height
130 anchors { left: parent.left; top: parent.top; right: parent.right }
131 height: units.gu(6.5)
132 contentHeight: headersColumn.height
134 contentY: showSearch ? 0 : height
136 property bool showSearch: false
137 property var popover: null
140 objectName: "headerBackground"
141 style: scopeStyle.headerBackground
144 Behavior on contentY {
145 UbuntuNumberAnimation {
146 id: openSearchAnimation
147 property bool openSearchHistory: false
150 if (!running && openSearchAnimation.openSearchHistory) {
151 openSearchAnimation.openSearchHistory = false;
152 root.openSearchHistory();
160 anchors { left: parent.left; right: parent.right }
164 anchors { left: parent.left; right: parent.right }
165 height: headerContainer.height
166 contentHeight: height
167 opacity: headerContainer.clip || headerContainer.showSearch ? 1 : 0 // setting visible false cause column to relayout
169 // Required to keep PageHeadStyle noise down as it expects the Page's properties around.
170 property var styledItem: searchHeader
171 property string title
172 property var config: PageHeadConfiguration {
173 foregroundColor: root.scopeStyle ? root.scopeStyle.headerForeground : "grey"
178 headerContainer.showSearch = false;
182 property var contents: TextField {
184 objectName: "searchTextField"
185 inputMethodHints: Qt.ImhNoPredictiveText
186 hasClearButton: false
189 leftMargin: units.gu(1)
190 topMargin: units.gu(1)
191 bottomMargin: units.gu(1)
192 rightMargin: root.width > units.gu(60) ? root.width - units.gu(40) : units.gu(1)
195 secondaryItem: AbstractButton {
196 height: searchTextField.height
198 enabled: searchTextField.text.length > 0
201 objectName: "clearIcon"
203 anchors.margins: units.gu(.75)
204 source: "image://theme/clear"
205 opacity: searchTextField.text.length > 0
207 Behavior on opacity {
208 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
213 root.resetSearch(true);
214 root.openSearchHistory();
218 onActiveFocusChanged: {
220 root.openSearchHistory();
234 objectName: "innerPageHeader"
235 anchors { left: parent.left; right: parent.right }
236 height: headerContainer.height
237 contentHeight: height
238 opacity: headerContainer.clip || !headerContainer.showSearch ? 1 : 0 // setting visible false cause column to relayout
240 property var styledItem: header
241 property string title: root.title
242 property var config: PageHeadConfiguration {
243 foregroundColor: root.scopeStyle ? root.scopeStyle.headerForeground : "grey"
246 visible: root.showBackButton
255 visible: root.searchEntryEnabled
257 headerContainer.showSearch = true;
258 searchTextField.forceActiveFocus();
264 property var contents: null
265 Component.onCompleted: root.refreshLogo()
271 anchors { fill: parent; topMargin: units.gu(1); bottomMargin: units.gu(1) }
274 objectName: "titleImage"
276 source: root.scopeStyle ? root.scopeStyle.headerLogo : ""
277 fillMode: Image.PreserveAspectFit
278 horizontalAlignment: Image.AlignLeft
279 sourceSize.height: height
288 spacing: units.gu(.5)
290 objectName: "paginationRepeater"
291 model: root.paginationCount
293 objectName: "paginationDots_" + index
296 source: (index == root.paginationIndex) ? "graphics/pagination_dot_on.png" : "graphics/pagination_dot_off.png"
300 top: headerContainer.bottom
301 horizontalCenter: headerContainer.horizontalCenter
302 topMargin: units.gu(.5)
312 Component.onDestruction: {
313 headerContainer.popover = null;
325 objectName: "recentSearches"
329 showDivider: index < recentSearches.count - 1
332 searchHistory.addQuery(text);
333 searchTextField.text = text;
346 top: headerContainer.bottom
349 bottom: bottomContainer.top
352 source: "graphics/PageHeaderBaseDivider.sci"
361 bottom: parent.bottom
363 height: childrenRect.height
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list