on xenial help sign in
Merge new-header.
commit43bbdfb301a52320c724cf0670ad79e2c805a031 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 4 Jul 2014, 11:42 (12 years ago) parent72743f7132c2e6
13 files changed+53−95
qml/Components/PageHeader.qml+47−55 qml/Components/SearchHistoryModel.qml → qml/Components/SearchHistoryModel/SearchHistoryModel.qml+1 qml/Components/SearchHistoryModel/qmldir+1 qml/Dash/Dash.qml−3 qml/Dash/DashContent.qml+1−4 qml/Dash/GenericScopeView.qml+1−4 qml/Dash/PreviewListView.qml+1−1 qml/Dash/ScopeItem.qml−3 qml/Dash/graphics/icon_listview_clear@20.png qml/ScopeTool.qml−1 tests/qmltests/Components/tst_PageHeader.qml+1−1 tests/qmltests/Dash/tst_Dash.qml−21 tests/qmltests/Dash/tst_DashContent.qml−2
qml/Components/PageHeader.qml+47−55
@@ -19,18 +19,18 @@ import Ubuntu.Components 1.1
1919import Ubuntu.Components.Themes.Ambiance 1.1
2020import Ubuntu.Components.Popups 1.0
2121import Ubuntu.Components.ListItems 1.0
22+import "SearchHistoryModel"
2223
2324Item {
2425 id: root
2526 implicitHeight: headerContainer.height + units.gu(2) + bottomContainer.height
26− height: implicitHeight
2727
2828 property bool showBackButton: false
2929 property string title
3030 property string imageSource
3131
3232 property bool searchEntryEnabled: false
33− property ListModel searchHistory
33+ property ListModel searchHistory: SearchHistoryModel
3434 property alias searchQuery: searchTextField.text
3535 property bool searchInProgress: false
3636
@@ -43,18 +43,14 @@ Item {
4343 signal backClicked()
4444
4545 function triggerSearch() {
46− if (searchEntryEnabled) searchTextField.forceActiveFocus()
46+ if (searchEntryEnabled) searchTextField.forceActiveFocus();
4747 }
4848
49− function resetSearch(unfocusField) {
50− if (unfocusField == undefined) {
51− unfocusField = true;
52− }
53−
49+ function resetSearch(keepFocus) {
5450 if (searchHistory) {
5551 searchHistory.addQuery(searchTextField.text);
5652 }
57− if (unfocusField) {
53+ if (!keepFocus) {
5854 unfocus();
5955 }
6056 searchTextField.text = "";
@@ -65,27 +61,38 @@ Item {
6561
6662 function unfocus() {
6763 searchTextField.focus = false;
64+ if (!searchTextField.text) {
65+ headerContainer.showSearch = false;
66+ }
6867 }
6968
7069 function openSearchHistory() {
7170 if (openSearchAnimation.running) {
72− openSearchAnimation.openSearchHistory = true
71+ openSearchAnimation.openSearchHistory = true;
7372 } else if (root.searchHistory.count > 0 && headerContainer.popover == null) {
7473 headerContainer.popover = PopupUtils.open(popoverComponent, searchTextField,
75− {
76− "contentWidth": searchTextField.width,
77− "edgeMargins": units.gu(1)
78− }
79− )
74+ {
75+ "contentWidth": searchTextField.width,
76+ "edgeMargins": units.gu(1)
77+ }
78+ );
8079 }
8180 }
8281
8382 onImageSourceChanged: {
84− if (imageSource.length > 0) {
83+ if (imageSource) {
8584 header.contents = imageComponent.createObject();
8685 } else {
8786 header.contents.destroy();
88− header.contents = null
87+ header.contents = null;
88+ }
89+ }
90+
91+ InverseMouseArea {
92+ anchors.fill: parent
93+ visible: headerContainer.popover !== null
94+ onPressed: {
95+ PopupUtils.close(headerContainer.popover);
8996 }
9097 }
9198
@@ -110,7 +117,7 @@ Item {
110117 onRunningChanged: {
111118 if (!running && openSearchAnimation.openSearchHistory) {
112119 openSearchAnimation.openSearchHistory = false;
113− root.openSearchHistory()
120+ root.openSearchHistory();
114121 }
115122 }
116123 }
@@ -118,8 +125,7 @@ Item {
118125
119126 Column {
120127 id: headersColumn
121− anchors.fill: parent
122− height: searchHeader.height + header.height
128+ anchors { left: parent.left; right: parent.right }
123129
124130 PageHeadStyle {
125131 id: searchHeader
@@ -127,14 +133,15 @@ Item {
127133 height: headerContainer.height
128134 contentHeight: height
129135 separatorSource: ""
136+ // Required to keep PageHeadStyle noise down as it expects the Page's properties around.
130137 property var styledItem: searchHeader
131− property string title: "searchHeader"
138+ property string title
132139 property var config: PageHeadConfiguration {
133140 backAction: Action {
134141 iconName: "back"
135142 onTriggered: {
136− root.resetSearch(true)
137− headerContainer.showSearch = false
143+ root.resetSearch();
144+ headerContainer.showSearch = false;
138145 }
139146 }
140147 }
@@ -142,7 +149,7 @@ Item {
142149 id: searchTextField
143150 hasClearButton: false
144151 anchors {
145− fill: parent;
152+ fill: parent
146153 leftMargin: units.gu(1)
147154 topMargin: units.gu(1)
148155 bottomMargin: units.gu(1)
@@ -160,6 +167,9 @@ Item {
160167 source: "image://theme/clear"
161168 opacity: searchTextField.text.length > 0 && !searchActivityIndicator.running
162169 visible: opacity > 0
170+ Behavior on opacity {
171+ UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
172+ }
163173 }
164174
165175 ActivityIndicator {
@@ -175,14 +185,14 @@ Item {
175185 }
176186
177187 onClicked: {
178− root.resetSearch(false)
179− root.openSearchHistory()
188+ root.resetSearch(true);
189+ root.openSearchHistory();
180190 }
181191 }
182192
183193 onActiveFocusChanged: {
184194 if (activeFocus) {
185− root.openSearchHistory()
195+ root.openSearchHistory();
186196 }
187197 }
188198 }
@@ -202,7 +212,7 @@ Item {
202212 iconName: "back"
203213 visible: root.showBackButton
204214 onTriggered: {
205− root.backClicked()
215+ root.backClicked();
206216 }
207217 }
208218
@@ -211,8 +221,8 @@ Item {
211221 iconName: "search"
212222 visible: root.searchEntryEnabled
213223 onTriggered: {
214− headerContainer.showSearch = true
215− searchTextField.forceActiveFocus()
224+ headerContainer.showSearch = true;
225+ searchTextField.forceActiveFocus();
216226 }
217227 }
218228 ]
@@ -220,7 +230,7 @@ Item {
220230
221231 property var contents: null
222232 Component.onCompleted: {
223− if (root.imageSource.length > 0) {
233+ if (root.imageSource) {
224234 header.contents = imageComponent.createObject();
225235 }
226236 }
@@ -236,6 +246,7 @@ Item {
236246 source: root.imageSource
237247 fillMode: Image.PreserveAspectFit
238248 horizontalAlignment: Image.AlignLeft
249+ sourceSize.height: height
239250 }
240251 }
241252 }
@@ -247,29 +258,10 @@ Item {
247258 id: popoverComponent
248259 Popover {
249260 id: popover
261+ autoClose: false
250262
251263 Component.onDestruction: {
252− headerContainer.popover = null
253− }
254−
255− // FIXME: this should go into the first item below, but enable: false
256− // prevents mouse events propagation
257− AbstractButton {
258− anchors {
259− top: parent.top
260− right: parent.right
261− }
262− height: units.gu(6)
263− width: height
264−
265− onClicked: PopupUtils.close(popover)
266−
267− Image {
268− anchors.centerIn: parent
269− width: units.gu(2)
270− height: units.gu(2)
271− source: "../Dash/graphics/icon_listview_clear.png"
272− }
264+ headerContainer.popover = null;
273265 }
274266
275267 Column {
@@ -289,9 +281,9 @@ Item {
289281 showDivider: index < recentSearches.count - 1
290282 text: query
291283 onClicked: {
292− searchHistory.addQuery(text)
293− searchTextField.text = text
294− PopupUtils.close(popover)
284+ searchHistory.addQuery(text);
285+ searchTextField.text = text;
286+ PopupUtils.close(popover);
295287 }
296288 }
297289 }
qml/Components/SearchHistoryModel.qml → qml/Components/SearchHistoryModel/SearchHistoryModel.qmlrenamed+1
@@ -14,6 +14,7 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17+pragma Singleton
1718import QtQuick 2.0
1819
1920// TODO sanitize input, move to persistent storage
qml/Components/SearchHistoryModel/qmldirnew file+1
@@ -0,0 +1 @@
1+singleton SearchHistoryModel 1.0 SearchHistoryModel.qml
qml/Dash/Dash.qml−3
@@ -26,7 +26,6 @@ Showable {
2626
2727 visible: shown
2828
29− property ListModel searchHistory: SearchHistoryModel {}
3029 property bool searchable: !dashContent.previewOpen && !scopeItem.previewOpen
3130
3231 property string showScopeOnLoaded: "clickscope"
@@ -76,7 +75,6 @@ Showable {
7675 height: parent.height
7776 model: filteredScopes
7877 scopes: scopes
79− searchHistory: dash.searchHistory
8078 visible: x != -width
8179 onGotoScope: {
8280 dash.setCurrentScope(scopeId, true, false);
@@ -110,7 +108,6 @@ Showable {
110108 anchors.left: dashContent.right
111109 width: parent.width
112110 height: parent.height
113− searchHistory: dash.searchHistory
114111 scale: dash.contentScale
115112 clip: scale != 1.0
116113 visible: scope != null
qml/Dash/DashContent.qml+1−4
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 1.1
18+import Ubuntu.Components 0.1
1919import Unity 0.2
2020import Utils 0.1
2121import "../Components"
@@ -28,8 +28,6 @@ Item {
2828 readonly property alias currentIndex: dashContentList.currentIndex
2929 property alias previewOpen: previewListView.open
3030
31− property ListModel searchHistory
32−
3331 signal scopeLoaded(string scopeId)
3432 signal gotoScope(string scopeId)
3533 signal openScope(var scope)
@@ -147,7 +145,6 @@ Item {
147145
148146 onLoaded: {
149147 item.objectName = scope.id
150− item.searchHistory = dashContent.searchHistory;
151148 item.previewListView = previewListView;
152149 item.scope = Qt.binding(function() { return scope })
153150 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
qml/Dash/GenericScopeView.qml+1−4
@@ -15,8 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 1.1
19−import Ubuntu.Components.Themes.Ambiance 1.1
18+import Ubuntu.Components 0.1
2019import Utils 0.1
2120import Unity 0.2
2221import Unity.Application 0.1
@@ -33,7 +32,6 @@ FocusScope {
3332 property Item previewListView: null
3433 property string title
3534 property bool hasBackAction: false
36− property ListModel searchHistory
3735 property bool enableHeightBehaviorOnNextCreation: false
3836 property var categoryView: categoryView
3937 property color foregroundColor: scope && scope.customizations["foreground-color"] || "grey"
@@ -325,7 +323,6 @@ FocusScope {
325323 id: pageHeader
326324 width: parent.width
327325 title: scopeView.title
328− searchHistory: scopeView.searchHistory
329326 showBackButton: scopeView.hasBackAction
330327 searchEntryEnabled: true
331328 searchInProgress: scopeView.scope.searchInProgress
qml/Dash/PreviewListView.qml+1−1
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 1.1
18+import Ubuntu.Components 0.1
1919import Unity 0.2
2020import "../Components"
2121import "Previews" as Previews
qml/Dash/ScopeItem.qml−3
@@ -25,8 +25,6 @@ Item {
2525 property alias scope: scopeView.scope
2626 property alias previewOpen: previewListView.open
2727
28− property ListModel searchHistory
29−
3028 signal back
3129 signal gotoScope(string scopeId)
3230 signal openScope(var scope)
@@ -50,7 +48,6 @@ Item {
5048 isCurrent: scope != null
5149 title: scope ? scope.name : ""
5250 hasBackAction: true
53− searchHistory: root.searchHistory
5451 previewListView: previewListView
5552
5653 onBackClicked: root.back();
qml/Dash/graphics/icon_listview_clear@20.pngdeleted

Binary file not shown.

qml/ScopeTool.qml−1
@@ -73,7 +73,6 @@ Rectangle {
7373 id: dashContent
7474
7575 model: filteredScopes
76− searchHistory: SearchHistoryModel { }
7776 property var scope: scopes.getScope(currentIndex)
7877
7978 anchors {
tests/qmltests/Components/tst_PageHeader.qml+1−1
@@ -201,7 +201,6 @@ Item {
201201 }
202202
203203 searchEntryEnabled: true
204− searchHistory: SearchHistoryModel {}
205204 title: "%^$%^%^&%^&%^$%GHR%"
206205 imageSource: showImageCheckBox.checked ? titleImageSource : ""
207206 showBackButton: showBackButtonCheckBox.checked
@@ -244,6 +243,7 @@ Item {
244243 anchors.verticalCenter: parent.verticalCenter
245244 }
246245 }
246+
247247 Row {
248248 spacing: units.gu(1)
249249 anchors {
tests/qmltests/Dash/tst_Dash.qml−21
@@ -70,27 +70,6 @@ Item {
7070 ]
7171 }
7272
73− function test_set_current_scope_data() {
74− return get_scope_data()
75− }
76−
77− function test_set_current_scope(data) {
78− // wait for scopes to load
79− tryCompare(scopes, "loaded", true);
80−
81− var tabbar = findChild(dash, "tabbar");
82− verify(tabbar != undefined)
83− var dashContent = findChild(dash, "dashContent");
84− var current_index = dashContent.currentIndex;
85−
86− dash.setCurrentScope(data.tag, true /* animate */, false /* reset */);
87− compare(dashContent.currentIndex, data.shouldBeVisible ? data.visualIndex : current_index);
88−
89− var dashContentList = findChild(dash, "dashContentList");
90− var expectedTitle = dashContentList.model.get(data.shouldBeVisible ? data.visualIndex : current_index).title
91− compare(tabbar.title, expectedTitle);
92− }
93−
9473 function test_show_scope_on_load_data() {
9574 return get_scope_data()
9675 }
tests/qmltests/Dash/tst_DashContent.qml−2
@@ -47,8 +47,6 @@ Item {
4747 model: scopesModel
4848 }
4949 scopes : scopesModel
50−
51− searchHistory: SearchHistoryModel {}
5250 }
5351
5452 SignalSpy {