on xenial help sign in
Merge lp:~nicolas-doffay/unity8/search-indicator
c0728c4Michal Hruby
Components/PageHeader.qml+24−1
@@ -18,6 +18,7 @@ import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19import Ubuntu.Components.Popups 0.1
19import Ubuntu.Components.Popups 0.1
20import Ubuntu.Components.ListItems 0.1 as ListItem
20import Ubuntu.Components.ListItems 0.1 as ListItem
21+import Unity 0.1
21
22
22Item {
23Item {
23 /*!
24 /*!
@@ -30,6 +31,7 @@ Item {
30 property bool searchEntryEnabled: false
31 property bool searchEntryEnabled: false
31 property alias searchQuery: searchField.text
32 property alias searchQuery: searchField.text
32 property ListModel searchHistory: SearchHistoryModel {}
33 property ListModel searchHistory: SearchHistoryModel {}
34+ property Scope scope
33
35
34 height: units.gu(8.5)
36 height: units.gu(8.5)
35 implicitHeight: units.gu(8.5)
37 implicitHeight: units.gu(8.5)
@@ -148,7 +150,7 @@ Item {
148 hasClearButton: false
150 hasClearButton: false
149
151
150 primaryItem: AbstractButton {
152 primaryItem: AbstractButton {
151− enabled: searchField.text != ""
153+ enabled: searchField.text != "" && !searchIndicator.running
152 onClicked: {
154 onClicked: {
153 if (searchField.text != "") {
155 if (searchField.text != "") {
154 searchHistory.addQuery(searchField.text)
156 searchHistory.addQuery(searchField.text)
@@ -158,8 +160,25 @@ Item {
158 height: parent.height
160 height: parent.height
159 width: height
161 width: height
160
162
163+ ActivityIndicator {
164+ id: searchIndicator
165+ objectName: "searchIndicator"
166+
167+ anchors {
168+ verticalCenter: parent.verticalCenter
169+ left: parent.left
170+ leftMargin: units.gu(0.5)
171+ }
172+
173+ running: scope.searchInProgress && searchField.text !== ""
174+ opacity: running ? 1 : 0
175+
176+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing.type: Easing.Linear } }
177+ }
178+
161 Image {
179 Image {
162 id: primaryImage
180 id: primaryImage
181+ objectName: "primaryImage"
163 anchors {
182 anchors {
164 verticalCenter: parent.verticalCenter
183 verticalCenter: parent.verticalCenter
165 left: parent.left
184 left: parent.left
@@ -167,6 +186,10 @@ Item {
167 }
186 }
168 width: units.gu(3)
187 width: units.gu(3)
169 height: units.gu(3)
188 height: units.gu(3)
189+ visible: opacity > 0
190+ opacity: searchIndicator.running ? 0 : 1
191+
192+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing.type: Easing.Linear } }
170 }
193 }
171
194
172 Item {
195 Item {
Dash/GenericScopeView.qml+1
@@ -176,6 +176,7 @@ ScopeView {
176 width: categoryView.width
176 width: categoryView.width
177 text: scopeView.scope.name
177 text: scopeView.scope.name
178 searchEntryEnabled: true
178 searchEntryEnabled: true
179+ scope: scopeView.scope
179 }
180 }
180 }
181 }
181
182
tests/mocks/Unity/fake_scope.cpp+7
@@ -141,6 +141,13 @@ void Scope::setActive(const bool active) {
141 }
141 }
142}
142}
143
143
144+void Scope::setSearchInProgress(const bool inProg) {
145+ if (inProg != m_searching) {
146+ m_searching = inProg;
147+ Q_EMIT searchInProgressChanged();
148+ }
149+}
150+
144void Scope::setNoResultsHint(const QString& str) {
151void Scope::setNoResultsHint(const QString& str) {
145 if (str != m_noResultsHint) {
152 if (str != m_noResultsHint) {
146 m_noResultsHint = str;
153 m_noResultsHint = str;
tests/mocks/Unity/fake_scope.h+2
@@ -38,6 +38,7 @@ class Scope : public QObject
38 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
38 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
39 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
39 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
40
40
41+ Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
41 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
42 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
42 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
43 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
43 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
44 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
@@ -69,6 +70,7 @@ public:
69 void setNoResultsHint(const QString& hint);
70 void setNoResultsHint(const QString& hint);
70 void setFormFactor(const QString& form_factor);
71 void setFormFactor(const QString& form_factor);
71 void setActive(const bool);
72 void setActive(const bool);
73+ void setSearchInProgress(const bool inProg);
72
74
73 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
75 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
74 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
76 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
tests/qmltests/Components/tst_PageHeader.qml+28
@@ -19,12 +19,17 @@ import QtTest 1.0
19import ".."
19import ".."
20import "../../../Components"
20import "../../../Components"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22+import Unity 0.1
22import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
23
24
24Item {
25Item {
25 width: units.gu(110)
26 width: units.gu(110)
26 height: units.gu(30)
27 height: units.gu(30)
27
28
29+ Scope {
30+ id: scopeMock
31+ }
32+
28 UT.UnityTestCase {
33 UT.UnityTestCase {
29 name: "PageHeaderTest"
34 name: "PageHeaderTest"
30 when: windowShown
35 when: windowShown
@@ -132,6 +137,27 @@ Item {
132 compare(pageHeader.searchHistory.count, 3)
137 compare(pageHeader.searchHistory.count, 3)
133 compare(pageHeader.searchHistory.get(0).query, "humppa4")
138 compare(pageHeader.searchHistory.get(0).query, "humppa4")
134 }
139 }
140+
141+ function test_search_indicator() {
142+ var searchIndicator = findChild(pageHeader, "searchIndicator")
143+ var primaryImage = findChild(pageHeader, "primaryImage")
144+
145+ pageHeader.triggerSearch()
146+
147+ scopeMock.searchInProgress = false
148+ compare(searchIndicator.running, false, "Search indicator is running.")
149+ tryCompare(primaryImage, "visible", true)
150+
151+ scopeMock.searchInProgress = true
152+ compare(searchIndicator.running, true, "Search indicator isn't running.")
153+ tryCompare(primaryImage, "visible", false)
154+
155+ pageHeader.resetSearch()
156+ }
157+
158+ function cleanup() {
159+ scopeMock.searchInProgress = false
160+ }
135 }
161 }
136
162
137 Column {
163 Column {
@@ -145,6 +171,8 @@ Item {
145 right: parent.right
171 right: parent.right
146 }
172 }
147
173
174+ scope: scopeMock
175+
148 searchEntryEnabled: true
176 searchEntryEnabled: true
149 text: "%^$%^%^&%^&%^$%GHR%"
177 text: "%^$%^%^&%^&%^$%GHR%"
150 }
178 }