on xenial help sign in
Merge lp:~nicolas-doffay/unity8/search-indicator
commitc0728c4884a5e9b4691d0ce1452af78174123615 authorMichal Hruby <michal.mhr@gmail.com> dateTue 1 Oct 2013, 22:56 (13 years ago) parent6b4d52f8de2ed0
5 files changed+62−1
Components/PageHeader.qml+24−1 Dash/GenericScopeView.qml+1 tests/mocks/Unity/fake_scope.cpp+7 tests/mocks/Unity/fake_scope.h+2 tests/qmltests/Components/tst_PageHeader.qml+28
Components/PageHeader.qml+24−1
@@ -18,6 +18,7 @@ import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Ubuntu.Components.Popups 0.1
2020import Ubuntu.Components.ListItems 0.1 as ListItem
21+import Unity 0.1
2122
2223Item {
2324 /*!
@@ -30,6 +31,7 @@ Item {
3031 property bool searchEntryEnabled: false
3132 property alias searchQuery: searchField.text
3233 property ListModel searchHistory: SearchHistoryModel {}
34+ property Scope scope
3335
3436 height: units.gu(8.5)
3537 implicitHeight: units.gu(8.5)
@@ -148,7 +150,7 @@ Item {
148150 hasClearButton: false
149151
150152 primaryItem: AbstractButton {
151− enabled: searchField.text != ""
153+ enabled: searchField.text != "" && !searchIndicator.running
152154 onClicked: {
153155 if (searchField.text != "") {
154156 searchHistory.addQuery(searchField.text)
@@ -158,8 +160,25 @@ Item {
158160 height: parent.height
159161 width: height
160162
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+
161179 Image {
162180 id: primaryImage
181+ objectName: "primaryImage"
163182 anchors {
164183 verticalCenter: parent.verticalCenter
165184 left: parent.left
@@ -167,6 +186,10 @@ Item {
167186 }
168187 width: units.gu(3)
169188 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 } }
170193 }
171194
172195 Item {
Dash/GenericScopeView.qml+1
@@ -176,6 +176,7 @@ ScopeView {
176176 width: categoryView.width
177177 text: scopeView.scope.name
178178 searchEntryEnabled: true
179+ scope: scopeView.scope
179180 }
180181 }
181182
tests/mocks/Unity/fake_scope.cpp+7
@@ -141,6 +141,13 @@ void Scope::setActive(const bool active) {
141141 }
142142}
143143
144+void Scope::setSearchInProgress(const bool inProg) {
145+ if (inProg != m_searching) {
146+ m_searching = inProg;
147+ Q_EMIT searchInProgressChanged();
148+ }
149+}
150+
144151void Scope::setNoResultsHint(const QString& str) {
145152 if (str != m_noResultsHint) {
146153 m_noResultsHint = str;
tests/mocks/Unity/fake_scope.h+2
@@ -38,6 +38,7 @@ class Scope : public QObject
3838 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
3939 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
4040
41+ Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
4142 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
4243 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
4344 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
@@ -69,6 +70,7 @@ public:
6970 void setNoResultsHint(const QString& hint);
7071 void setFormFactor(const QString& form_factor);
7172 void setActive(const bool);
73+ void setSearchInProgress(const bool inProg);
7274
7375 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
7476 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
1919import ".."
2020import "../../../Components"
2121import Ubuntu.Components 0.1
22+import Unity 0.1
2223import Unity.Test 0.1 as UT
2324
2425Item {
2526 width: units.gu(110)
2627 height: units.gu(30)
2728
29+ Scope {
30+ id: scopeMock
31+ }
32+
2833 UT.UnityTestCase {
2934 name: "PageHeaderTest"
3035 when: windowShown
@@ -132,6 +137,27 @@ Item {
132137 compare(pageHeader.searchHistory.count, 3)
133138 compare(pageHeader.searchHistory.get(0).query, "humppa4")
134139 }
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+ }
135161 }
136162
137163 Column {
@@ -145,6 +171,8 @@ Item {
145171 right: parent.right
146172 }
147173
174+ scope: scopeMock
175+
148176 searchEntryEnabled: true
149177 text: "%^$%^%^&%^&%^$%GHR%"
150178 }