Merge lp:~kalikiana/ubuntu-ui-toolkit/pagesearch into lp:ubuntu-ui-toolkit

Proposed by Cris Dywan
Status: Work in progress
Proposed branch: lp:~kalikiana/ubuntu-ui-toolkit/pagesearch
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 477 lines (+387/-0)
9 files modified
components.api (+11/-0)
examples/examples.pro (+1/-0)
examples/search/MessageList.qml (+44/-0)
examples/search/search.desktop (+8/-0)
examples/search/search.pro (+18/-0)
examples/search/search.qml (+150/-0)
modules/Ubuntu/Components/Page.qml (+39/-0)
modules/Ubuntu/Components/Search.qml (+115/-0)
modules/Ubuntu/Components/qmldir (+1/-0)
To merge this branch: bzr merge lp:~kalikiana/ubuntu-ui-toolkit/pagesearch
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu SDK team Pending
Review via email: mp+173996@code.launchpad.net

Commit message

Implement Page-based search in header and an example

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

This is a fake merge request. I want to see the diff, jenkins etc but I don't expect review yet.

584. By Cris Dywan

Merge lp:ubuntu-ui-toolkit

[ Kaleo ]
* ListItems Base & Standard: prevent the icon from going taller than
  5GU. . (LP: #1187128)
[ Timo Jyrinki ]
* Remove qmlrunner. On saucy, the less complicated way is to just use
  qmlscene with either environment variable set or with a command line
  parameter.
[ Ubuntu daily release ]
* Automatic snapshot from revision 605
[ Kaleo ]
* Add a CrossFadeImage component which crossfades when its source is
  updated.
* Standard animation durations adapted for new design: - SnapDuration
  goes from 125ms to 100ms - FastDuration goes from 250ms to 165ms -
  new BriskDuration is introduced at 333ms.
* GIconProvider: avoid using QPixmap which is not re-entrant. Fixes
  crashes. (LP: #1197784)
* Fine tuned UbuntuAnimation.StandardEasing to match design.
  Introduced new standard Ubuntu easing
  UbuntuAnimation.StandardEasingReverse.
* Panel.animating: do not rely on comparing real values that sometimes
  have rounding errors. (LP: #1199550)
[ Iain Lane ]
* Add a CrossFadeImage component which crossfades when its source is
  updated.
[ Loïc Molinari ]
* [UbuntuShape] Moved content flagging before implicit sizing to
  prevent assertion.
[ Ubuntu daily release ]
* Automatic snapshot from revision 602
[ Kaleo ]
* Pass import paths from main QQmlEngine to QQuickUtils' QQmlEngine.
  Fixes case where qmlscene is passed import paths via the -I
  argument.
[ Ubuntu daily release ]
* Automatic snapshot from revision 593
[ Kaleo ]
* Latest fix in ButtonStyle had 3 typos. Fixing them. .
* ListItem.SingleControl: Ensure that there is always enough vertical
  padding around the control. (LP: #1198116)
[ Christian Dywan ]
* Include alias types in qmlapicheck. (LP: #1192540)
[ Ubuntu daily release ]
* Automatic snapshot from revision 589
[ Kaleo ]
* Reintroduced QML proxy for ShapeItem C++ class in order to
  workaround CPU hog when no image was set to ShapeItem. (LP:
  #1197801)
[ Loïc Molinari ]
* Added workaround for QML buggy support for color props in ternary
  ops. (LP: #1197802)
[ Ubuntu daily release ]
* Automatic snapshot from revision 584

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
585. By Cris Dywan

Mark onQueryReset default handler as internal

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
586. By Cris Dywan

Build and install Search example

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
587. By Cris Dywan

Use "search" icon so that the example works on phone and desktop

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
588. By Cris Dywan

Provide an action to trigger search; remove built-in reset callback

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
589. By Cris Dywan

Save original header and restore on queryReset

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
590. By Cris Dywan

Merge lp:ubuntu-ui-toolkit

[ Kaleo ]
* Dialog: removed clipping that not clipping anything.
* Removed unused PointerStyleShader.
[ Ubuntu daily release ]
* Automatic snapshot from revision 626
[ Kaleo ]
* MainView: new API to choose the background colors. That requires: -
  HeaderStyle: removed background. - MainView: clip the contents when
  necessary. - PageTreeNode: new properties 'isLeaf' and
  'activeLeafNode'.
[ Leo Arias ]
* Fixed the pep8 errors and copyright notices.
[ Didier Roche ]
* fix icon -> iconSource for toolbar doc.
[ tpeeters ]
* Fix bug where Header did not get linked to the new Flickable when
  Page.flickable is automatically detected. (LP: #1200642, #1192591)
[ Ubuntu daily release ]
* Automatic snapshot from revision 623
[ Kaleo ]
* Removed unused artwork.
* Added experimental dark & gradient themes.
* Reverted standard easings to Quad because it seems
  QEasingCurve::BezierSpline does not ensure the target value is
  always reached. (LP: #1199662)
[ Loïc Molinari ]
* [UbuntuShape] Prevented dangling nodes in the scene graph. (LP:
  #1180794)
[ Ubuntu daily release ]
* Automatic snapshot from revision 618
[ Kaleo ]
* Introduce new theme color palette API centralising the definition of
  the colors used by the widgets to draw themselves. Adapted most
  widgets to use the theme color palette. The color palette defined in
  the Ambiance theme is the one from the new visual design. (LP:
  #1186968, #1197853)
* Switch: refresh to match new visual design.
* Tabs: more robust binding of the header component.
* CheckBox: refresh to match new visual design.
[ Loïc Molinari ]
* Added support for -Werror flagged debug builds and fixed warnings.
* [UbuntuShape] Fixed alignment support.
[ tpeeters ]
* Add API tests for MainView.
[ Ubuntu daily release ]
* Automatic snapshot from revision 613

591. By Cris Dywan

Define global Search and Quit actions and no toolbar

Unmerged revisions

591. By Cris Dywan

Define global Search and Quit actions and no toolbar

590. By Cris Dywan

Merge lp:ubuntu-ui-toolkit

[ Kaleo ]
* Dialog: removed clipping that not clipping anything.
* Removed unused PointerStyleShader.
[ Ubuntu daily release ]
* Automatic snapshot from revision 626
[ Kaleo ]
* MainView: new API to choose the background colors. That requires: -
  HeaderStyle: removed background. - MainView: clip the contents when
  necessary. - PageTreeNode: new properties 'isLeaf' and
  'activeLeafNode'.
[ Leo Arias ]
* Fixed the pep8 errors and copyright notices.
[ Didier Roche ]
* fix icon -> iconSource for toolbar doc.
[ tpeeters ]
* Fix bug where Header did not get linked to the new Flickable when
  Page.flickable is automatically detected. (LP: #1200642, #1192591)
[ Ubuntu daily release ]
* Automatic snapshot from revision 623
[ Kaleo ]
* Removed unused artwork.
* Added experimental dark & gradient themes.
* Reverted standard easings to Quad because it seems
  QEasingCurve::BezierSpline does not ensure the target value is
  always reached. (LP: #1199662)
[ Loïc Molinari ]
* [UbuntuShape] Prevented dangling nodes in the scene graph. (LP:
  #1180794)
[ Ubuntu daily release ]
* Automatic snapshot from revision 618
[ Kaleo ]
* Introduce new theme color palette API centralising the definition of
  the colors used by the widgets to draw themselves. Adapted most
  widgets to use the theme color palette. The color palette defined in
  the Ambiance theme is the one from the new visual design. (LP:
  #1186968, #1197853)
* Switch: refresh to match new visual design.
* Tabs: more robust binding of the header component.
* CheckBox: refresh to match new visual design.
[ Loïc Molinari ]
* Added support for -Werror flagged debug builds and fixed warnings.
* [UbuntuShape] Fixed alignment support.
[ tpeeters ]
* Add API tests for MainView.
[ Ubuntu daily release ]
* Automatic snapshot from revision 613

589. By Cris Dywan

Save original header and restore on queryReset

588. By Cris Dywan

Provide an action to trigger search; remove built-in reset callback

587. By Cris Dywan

Use "search" icon so that the example works on phone and desktop

586. By Cris Dywan

Build and install Search example

585. By Cris Dywan

Mark onQueryReset default handler as internal

584. By Cris Dywan

Merge lp:ubuntu-ui-toolkit

[ Kaleo ]
* ListItems Base & Standard: prevent the icon from going taller than
  5GU. . (LP: #1187128)
[ Timo Jyrinki ]
* Remove qmlrunner. On saucy, the less complicated way is to just use
  qmlscene with either environment variable set or with a command line
  parameter.
[ Ubuntu daily release ]
* Automatic snapshot from revision 605
[ Kaleo ]
* Add a CrossFadeImage component which crossfades when its source is
  updated.
* Standard animation durations adapted for new design: - SnapDuration
  goes from 125ms to 100ms - FastDuration goes from 250ms to 165ms -
  new BriskDuration is introduced at 333ms.
* GIconProvider: avoid using QPixmap which is not re-entrant. Fixes
  crashes. (LP: #1197784)
* Fine tuned UbuntuAnimation.StandardEasing to match design.
  Introduced new standard Ubuntu easing
  UbuntuAnimation.StandardEasingReverse.
* Panel.animating: do not rely on comparing real values that sometimes
  have rounding errors. (LP: #1199550)
[ Iain Lane ]
* Add a CrossFadeImage component which crossfades when its source is
  updated.
[ Loïc Molinari ]
* [UbuntuShape] Moved content flagging before implicit sizing to
  prevent assertion.
[ Ubuntu daily release ]
* Automatic snapshot from revision 602
[ Kaleo ]
* Pass import paths from main QQmlEngine to QQuickUtils' QQmlEngine.
  Fixes case where qmlscene is passed import paths via the -I
  argument.
[ Ubuntu daily release ]
* Automatic snapshot from revision 593
[ Kaleo ]
* Latest fix in ButtonStyle had 3 typos. Fixing them. .
* ListItem.SingleControl: Ensure that there is always enough vertical
  padding around the control. (LP: #1198116)
[ Christian Dywan ]
* Include alias types in qmlapicheck. (LP: #1192540)
[ Ubuntu daily release ]
* Automatic snapshot from revision 589
[ Kaleo ]
* Reintroduced QML proxy for ShapeItem C++ class in order to
  workaround CPU hog when no image was set to ShapeItem. (LP:
  #1197801)
[ Loïc Molinari ]
* Added workaround for QML buggy support for color props in ternary
  ops. (LP: #1197802)
[ Ubuntu daily release ]
* Automatic snapshot from revision 584

583. By Cris Dywan

Implement Page-based search in header and an example

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2013-07-16 18:44:50 +0000
3+++ components.api 2013-07-18 15:14:30 +0000
4@@ -107,6 +107,10 @@
5 modules/Ubuntu/Components/Page.qml
6 PageTreeNode
7 property string title
8+ property string searchLabel
9+ signal queryUpdated(string keywords)
10+ signal querySubmitted(string keywords)
11+ signal queryReset
12 property Flickable flickable
13 property list<Action> actions
14 modules/Ubuntu/Components/PageStack.qml
15@@ -158,6 +162,13 @@
16 property int align
17 property bool __interactive
18 property internal __private
19+modules/Ubuntu/Components/Search.qml
20+TextField
21+ property Popover visiblePopover
22+ function showSuggestions(searchField)
23+ function hideSuggestions()
24+ function searchWhileTyping(searchField)
25+ function submitSearch(keywords)
26 modules/Ubuntu/Components/Slider.qml
27 AbstractButton
28 property real minimumValue
29
30=== modified file 'examples/examples.pro'
31--- examples/examples.pro 2013-07-03 05:52:08 +0000
32+++ examples/examples.pro 2013-07-18 15:14:30 +0000
33@@ -5,6 +5,7 @@
34 jokes \
35 locale \
36 unit-converter \
37+ search \
38 calculator
39
40
41
42=== added directory 'examples/search'
43=== added file 'examples/search/MessageList.qml'
44--- examples/search/MessageList.qml 1970-01-01 00:00:00 +0000
45+++ examples/search/MessageList.qml 2013-07-18 15:14:30 +0000
46@@ -0,0 +1,44 @@
47+/*
48+ * Copyright 2013 Canonical Ltd.
49+ *
50+ * This program is free software; you can redistribute it and/or modify
51+ * it under the terms of the GNU Lesser General Public License as published by
52+ * the Free Software Foundation; version 3.
53+ *
54+ * This program is distributed in the hope that it will be useful,
55+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
56+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57+ * GNU Lesser General Public License for more details.
58+ *
59+ * You should have received a copy of the GNU Lesser General Public License
60+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
61+ *
62+ * Author: Christian Dywan <christian.dywan@canonical.com>
63+ */
64+
65+import QtQuick 2.0
66+import Ubuntu.Components 0.1
67+import Ubuntu.Components.ListItems 0.1 as ListItem
68+
69+Rectangle {
70+ property ListModel model: null
71+ anchors.fill: parent
72+
73+ ListView {
74+ id: emailView
75+ model: parent.model
76+ width: parent.width
77+ height: parent.height
78+ delegate: ListItem.Subtitled {
79+ text: subject + " <em>" + when + "</em>"
80+ subText: preview
81+ icon: Icon {
82+ name: "search"
83+ width: units.gu(3)
84+ height: units.gu(5)
85+ visible: starred
86+ }
87+ }
88+ }
89+}
90+
91
92=== added file 'examples/search/search.desktop'
93--- examples/search/search.desktop 1970-01-01 00:00:00 +0000
94+++ examples/search/search.desktop 2013-07-18 15:14:30 +0000
95@@ -0,0 +1,8 @@
96+[Desktop Entry]
97+Name=search
98+Comment=My searchable app
99+Exec=/usr/bin/qmlscene $@ /usr/lib/ubuntu-ui-toolkit/examples/search/search.qml
100+Icon=edit-find-symbolic
101+Terminal=false
102+Type=Application
103+X-Ubuntu-Touch=true
104
105=== added file 'examples/search/search.pro'
106--- examples/search/search.pro 1970-01-01 00:00:00 +0000
107+++ examples/search/search.pro 2013-07-18 15:14:30 +0000
108@@ -0,0 +1,18 @@
109+TEMPLATE = subdirs
110+
111+filetypes = qml png svg js qmltheme jpg qmlproject desktop wav
112+
113+OTHER_FILES = ""
114+
115+for(filetype, filetypes) {
116+ OTHER_FILES += *.$$filetype
117+}
118+
119+desktop_files.path = /usr/share/applications
120+desktop_files.files = search.desktop
121+
122+other_files.path = /usr/lib/ubuntu-ui-toolkit/examples/search
123+other_files.files = $$OTHER_FILES
124+
125+INSTALLS += other_files desktop_files
126+
127
128=== added file 'examples/search/search.qml'
129--- examples/search/search.qml 1970-01-01 00:00:00 +0000
130+++ examples/search/search.qml 2013-07-18 15:14:30 +0000
131@@ -0,0 +1,150 @@
132+/*
133+ * Copyright 2013 Canonical Ltd.
134+ *
135+ * This program is free software; you can redistribute it and/or modify
136+ * it under the terms of the GNU Lesser General Public License as published by
137+ * the Free Software Foundation; version 3.
138+ *
139+ * This program is distributed in the hope that it will be useful,
140+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
141+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142+ * GNU Lesser General Public License for more details.
143+ *
144+ * You should have received a copy of the GNU Lesser General Public License
145+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
146+ *
147+ * Author: Christian Dywan <christian.dywan@canonical.com>
148+ */
149+
150+import QtQuick 2.0
151+import Ubuntu.Components 0.1
152+
153+/*!
154+ \brief In-app search.
155+*/
156+
157+MainView {
158+ id: mainView
159+ objectName: "mainView"
160+ applicationName: "search"
161+ automaticOrientation: true
162+ width: units.gu(40)
163+ height: units.gu(70)
164+
165+ Action {
166+ id: searchAction
167+ iconSource: Qt.resolvedUrl("image://gicon/search")
168+ text: i18n.tr("Search")
169+ keywords: i18n.tr("Find")
170+ onTriggered: {
171+ tabs.selectedTabIndex = 1 // Search
172+ }
173+ }
174+ Action {
175+ id: quitAction
176+ text: i18n.tr("Quit")
177+ keywords: i18n.tr("Close")
178+ onTriggered: {
179+ Qt.quit()
180+ }
181+ }
182+ actions: [ quitAction ]
183+
184+ Tabs {
185+ id: tabs
186+
187+ Tab { title: tabInbox.title; Page {
188+ id: tabInbox
189+ title: i18n.tr("Inbox")
190+ actions: [ searchAction ]
191+
192+ MessageList {
193+ id: messagesInbox
194+ model: emails
195+ }
196+ } }
197+
198+ Tab { title: tabSearch.title; Page {
199+ id: tabSearch
200+ title: i18n.tr("Search")
201+ searchLabel: i18n.tr("Search email messages…")
202+ Component.onCompleted: {
203+ recentSearches.append({ "query": "ouya" })
204+ recentSearches.append({ "query": "ubuntu" })
205+ recentSearches.append({ "query": "retired" })
206+ }
207+
208+ onQueryReset: {
209+ tabs.selectedTabIndex = 0 // Inbox
210+ }
211+ onQuerySubmitted: {
212+ results.clear()
213+ for (var i = 0; i < emails.count; i++) {
214+ var canonicalized = keywords.toLowerCase()
215+ var row = emails.get(i)
216+ if (row.subject.toLowerCase().indexOf(canonicalized) > -1
217+ || row.preview.toLowerCase().indexOf(canonicalized) > -1) {
218+ row = JSON.parse(JSON.stringify(row)) // don't modify the original
219+ row.subject = row.subject.replace(new RegExp(keywords, "gi"), "<b>$&</b>")
220+ row.preview = row.preview.replace(new RegExp(keywords, "gi"), "<b>$&</b>")
221+ results.append(row)
222+ }
223+ }
224+ }
225+
226+ MessageList {
227+ id: messagesSearch
228+ model: results
229+ }
230+ } }
231+
232+ Tab { title: tabSettings.title; Page {
233+ id: tabSettings
234+ title: i18n.tr("Settings")
235+ Button {
236+ text: i18n.tr("No settings whatsoever")
237+ width: units.gu(20)
238+ height: units.gu(20)
239+ }
240+ } }
241+
242+ }
243+
244+ ListModel {
245+ id: results
246+ }
247+
248+ ListModel {
249+ id: emails
250+ ListElement {
251+ subject: "Payment receipt #490524"
252+ preview: "Habitually we avoid making it too obvious what you paid to ensure you don't remember how much money you pay just for geek stuff."
253+ when: "2 days ago"
254+ starred: false
255+ }
256+ ListElement {
257+ subject: "Ubuntu Phone coming soon"
258+ preview: "Brave humans can already try it on their Android phone and even develop apps for it right now."
259+ when: "Tomorrow"
260+ starred: false
261+ }
262+ ListElement {
263+ subject: "The pope retired"
264+ preview: "In his own words “I'm too young to stay forever in one place”"
265+ when: "Last Month"
266+ starred: false
267+ }
268+ ListElement {
269+ subject: "OUYA now in store shelves"
270+ preview: "Lorem ipsum dolor sit OUYA, quo vadis"
271+ when: "Yesterday"
272+ starred: true
273+ }
274+ ListElement {
275+ subject: "Canabalt HD released"
276+ preview: "Lorem ipsum even the pope dolor sit OUYA quo vadis Ubuntu"
277+ when: "Eons ago"
278+ starred: true
279+ }
280+ }
281+}
282
283=== modified file 'modules/Ubuntu/Components/Page.qml'
284--- modules/Ubuntu/Components/Page.qml 2013-07-16 14:23:32 +0000
285+++ modules/Ubuntu/Components/Page.qml 2013-07-18 15:14:30 +0000
286@@ -86,6 +86,40 @@
287 property Item tools: ToolbarItems { }
288
289 /*!
290+ If a label is defined, the page will display a search field in the header
291+ and you need to handle querySubmitted to implement display of search results.
292+ */
293+ property string searchLabel: ""
294+ /*!
295+ The user is typing in the search field
296+ */
297+ signal queryUpdated(string keywords)
298+ /*!
299+ The user pressed Enter or selected a suggestion
300+ */
301+ signal querySubmitted(string keywords)
302+ /*!
303+ An active search was cancelled, usually using the clear button
304+ */
305+ signal queryReset
306+ /*! \internal */
307+ onQueryReset: {
308+ internal.header.contents = internal.originalHeaderContents
309+ }
310+ /*!
311+ The model stores a search history with items of the form "query": "foobar"
312+ and can be used to add or remove items or provide custom suggestions
313+ */
314+ property ListModel recentSearches: ListModel { }
315+
316+ Component {
317+ id: searchComponent
318+ Search {
319+ placeholderText: tabSearch.searchLabel
320+ }
321+ }
322+
323+ /*!
324 Optional flickable that controls the header. This property
325 is automatically set to the first child of the page that is Flickable
326 and anchors to the top of the page or fills the page. For example:
327@@ -163,6 +197,7 @@
328
329 property Header header: page.__propagated && page.__propagated.header ? page.__propagated.header : null
330 property Toolbar toolbar: page.__propagated && page.__propagated.toolbar ? page.__propagated.toolbar : null
331+ property Component originalHeaderContents: null
332
333 onHeaderChanged: internal.updateHeaderAndToolbar()
334 onToolbarChanged: internal.updateHeaderAndToolbar()
335@@ -172,6 +207,10 @@
336 if (internal.header) {
337 internal.header.title = page.title;
338 internal.header.flickable = page.flickable;
339+ if (searchLabel != "") {
340+ internal.originalHeaderContents = internal.header.contents
341+ internal.header.contents = searchComponent
342+ }
343 }
344 if (tools) {
345 // TODO: remove __pageStack when ToolbarActions becomes deprecated
346
347=== added file 'modules/Ubuntu/Components/Search.qml'
348--- modules/Ubuntu/Components/Search.qml 1970-01-01 00:00:00 +0000
349+++ modules/Ubuntu/Components/Search.qml 2013-07-18 15:14:30 +0000
350@@ -0,0 +1,115 @@
351+/*
352+ * Copyright 2013 Canonical Ltd.
353+ *
354+ * This program is free software; you can redistribute it and/or modify
355+ * it under the terms of the GNU Lesser General Public License as published by
356+ * the Free Software Foundation; version 3.
357+ *
358+ * This program is distributed in the hope that it will be useful,
359+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
360+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
361+ * GNU Lesser General Public License for more details.
362+ *
363+ * You should have received a copy of the GNU Lesser General Public License
364+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
365+ */
366+import QtQuick 2.0
367+import Ubuntu.Components.Popups 0.1
368+import Ubuntu.Components.ListItems 0.1 as ListItem
369+
370+TextField {
371+ placeholderText: null
372+ property Popover visiblePopover: null
373+
374+ function showSuggestions(searchField) {
375+ if (visiblePopover)
376+ return
377+ visiblePopover = PopupUtils.open(suggestionsComponent, searchField, {
378+ "contentWidth": searchField.width,
379+ "edgeMargins": units.gu(1)
380+ })
381+ }
382+ function hideSuggestions() {
383+ if (!visiblePopover)
384+ return
385+ PopupUtils.close(visiblePopover)
386+ visiblePopover = null
387+ }
388+ function searchWhileTyping(searchField) {
389+ var keywords = searchField.text.replace(/^\s+|\s+$/g, '')
390+ if (keywords == "") {
391+ hideSuggestions()
392+ queryReset()
393+ return
394+ }
395+
396+ if (searchField.activeFocus)
397+ showSuggestions(searchField)
398+ queryUpdated(keywords)
399+ }
400+ function submitSearch(keywords) {
401+ hideSuggestions()
402+ keywords = keywords.replace(/^\s+|\s+$/g, '')
403+ for (var i = 0; i < recentSearches.count; i++)
404+ if (recentSearches.get(i).query == keywords) {
405+ recentSearches.move(i, 0, 1)
406+ querySubmitted(keywords)
407+ return
408+ }
409+ recentSearches.insert(0, { "query": keywords })
410+ querySubmitted(keywords)
411+ }
412+
413+ Component {
414+ id: suggestionsComponent
415+ Popover {
416+ id: suggestionsPopover
417+ Column {
418+ anchors {
419+ top: parent.top
420+ left: parent.left
421+ right: parent.right
422+ }
423+ ListItem.Standard {
424+ enabled: false
425+ text: i18n.tr("Recent Searches")
426+ }
427+
428+ Repeater {
429+ model: recentSearches
430+ delegate: ListItem.Standard {
431+ showDivider: index - model.count - 1
432+ text: query
433+ onClicked: submitSearch(text)
434+ }
435+ }
436+ }
437+ }
438+ }
439+
440+ id: searchField
441+ popover: suggestionsComponent
442+ font.bold: true
443+ horizontalAlignment: Text.AlignRight
444+ height: units.gu(7)
445+ primaryItem: Button {
446+ width: height
447+ height: parent.height - units.gu(2)
448+ onClicked: submitSearch(text)
449+ color: 'transparent'
450+ Icon {
451+ name: "search"
452+ width: parent.width
453+ height: parent.height
454+ }
455+ }
456+ onAccepted: submitSearch(text)
457+ onTextChanged: {
458+ searchWhileTyping(searchField)
459+ }
460+ onActiveFocusChanged: {
461+ if (!activeFocus)
462+ hideSuggestions()
463+ }
464+}
465+
466
467=== modified file 'modules/Ubuntu/Components/qmldir'
468--- modules/Ubuntu/Components/qmldir 2013-07-05 09:25:29 +0000
469+++ modules/Ubuntu/Components/qmldir 2013-07-18 15:14:30 +0000
470@@ -25,6 +25,7 @@
471 internal ModelSectionCounter ModelSectionCounter.qml
472 Object 0.1 Object.qml
473 Page 0.1 Page.qml
474+internal Search Search.qml
475 internal PageTreeNode PageTreeNode.qml
476 PageStack 0.1 PageStack.qml
477 internal Toolbar Toolbar.qml

Subscribers

People subscribed via source and target branches

to status/vote changes: