on xenial help sign in
Implement search
commit3a12793826ab62d52092e85e23a2fb7ca7f5928d authorAlbert Astals <albert.astals@canonical.com> dateWed 16 Jul 2014, 17:03 (12 years ago) parentf2580fa
9 files changed+103−60
qml/Components/PageHeader.qml+1−1 qml/Dash/Dash.qml+1−1 qml/Dash/GenericScopeView.qml+34−23 qml/Dash/ScopesOverview.qml+40−19 qml/Dash/ScopesOverviewFavourites.qml → qml/Dash/ScopesOverviewFavorites.qml qml/Dash/ScopesOverviewTab.qml+6−6 tests/mocks/Unity/fake_scope.cpp+1 tests/mocks/Unity/fake_scopesoverview.cpp+15−9 tests/mocks/Unity/fake_scopesoverview.h+5−1
qml/Components/PageHeader.qml+1−1
@@ -24,7 +24,7 @@ import "SearchHistoryModel"
2424Item {
2525 id: root
2626 objectName: "pageHeader"
27− implicitHeight: headerContainer.height + units.gu(2) + bottomContainer.height
27+ implicitHeight: headerContainer.height + bottomContainer.height + (showSignatureLine ? units.gu(2) : 0)
2828
2929 property bool showBackButton: false
3030 property string title
qml/Dash/Dash.qml+1−1
@@ -278,7 +278,7 @@ Showable {
278278 z: 1
279279 direction: Direction.Upwards
280280 // TODO this needs to be disabled in a few more cases
281− enabled: !dashContent.previewShown && dashContent.currentScope.searchQuery == "" && (overviewController.progress == 0 || dragging)
281+ enabled: !dashContent.previewShown && dashContent.currentScope && dashContent.currentScope.searchQuery == "" && (overviewController.progress == 0 || dragging)
282282
283283 readonly property real fullMovement: units.gu(20)
284284
qml/Dash/GenericScopeView.qml+34−23
@@ -33,6 +33,7 @@ FocusScope {
3333 property bool hasBackAction: false
3434 property bool enableHeightBehaviorOnNextCreation: false
3535 property var categoryView: categoryView
36+ property bool showPageHeader: true
3637 readonly property alias previewShown: previewListView.open
3738
3839 property var scopeStyle: ScopeStyle {
@@ -79,22 +80,24 @@ FocusScope {
7980 }
8081
8182 onIsCurrentChanged: {
82− pageHeader.resetSearch();
83+ if (showPageHeader) {
84+ pageHeaderLoader.item.resetSearch();
85+ }
8386 previewListView.open = false;
8487 }
8588
8689 Binding {
8790 target: scopeView.scope
8891 property: "searchQuery"
89− value: pageHeader.searchQuery
90− when: isCurrent
92+ value: pageHeaderLoader.item.searchQuery
93+ when: isCurrent && showPageHeader
9194 }
9295
9396 Binding {
94− target: pageHeader
97+ target: pageHeaderLoader.item
9598 property: "searchQuery"
9699 value: scopeView.scope ? scopeView.scope.searchQuery : ""
97− when: isCurrent
100+ when: isCurrent && showPageHeader
98101 }
99102
100103 Connections {
@@ -330,26 +333,34 @@ FocusScope {
330333 }
331334 }
332335
333− pageHeader: PageHeader {
334− id: pageHeader
335− objectName: "scopePageHeader"
336+ pageHeader: scopeView.showPageHeader ? pageHeaderLoader : null
337+ Loader {
338+ id: pageHeaderLoader
336339 width: parent.width
337− title: scopeView.scope ? scopeView.scope.name : ""
338− showBackButton: scopeView.hasBackAction
339− searchEntryEnabled: true
340− searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
341− scopeStyle: scopeView.scopeStyle
342−
343− bottomItem: DashDepartments {
344− scope: scopeView.scope
345− width: parent.width <= units.gu(60) ? parent.width : units.gu(40)
346− anchors.right: parent.right
347− windowHeight: scopeView.height
348− windowWidth: scopeView.width
349− scopeStyle: scopeView.scopeStyle
350− }
340+ sourceComponent: scopeView.showPageHeader ? pageHeaderComponent : undefined
341+ Component {
342+ id: pageHeaderComponent
343+ PageHeader {
344+ objectName: "scopePageHeader"
345+ width: parent.width
346+ title: scopeView.scope ? scopeView.scope.name : ""
347+ showBackButton: scopeView.hasBackAction
348+ searchEntryEnabled: true
349+ searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
350+ scopeStyle: scopeView.scopeStyle
351+
352+ bottomItem: DashDepartments {
353+ scope: scopeView.scope
354+ width: parent.width <= units.gu(60) ? parent.width : units.gu(40)
355+ anchors.right: parent.right
356+ windowHeight: scopeView.height
357+ windowWidth: scopeView.width
358+ scopeStyle: scopeView.scopeStyle
359+ }
351360
352− onBackClicked: scopeView.backClicked()
361+ onBackClicked: scopeView.backClicked()
362+ }
363+ }
353364 }
354365 }
355366
qml/Dash/ScopesOverview.qml+40−19
@@ -26,7 +26,7 @@ Item {
2626 property real progress: 0
2727 property var scope: null
2828 property var dashItemEater: {
29− if (tabBarHolder.currentTab == 0 && middleItems.count > 0) {
29+ if (tabBar.currentTab == 0 && middleItems.count > 0) {
3030 var loaderItem = middleItems.itemAt(0).item;
3131 return loaderItem && loaderItem.currentItem ? loaderItem.currentItem : null;
3232 }
@@ -38,6 +38,7 @@ Item {
3838 property QtObject scopeStyle: QtObject {
3939 property string headerLogo: ""
4040 property color foreground: "white"
41+ property color background: "transparent"
4142 }
4243 property size allCardSize: {
4344 if (middleItems.count > 1) {
@@ -67,7 +68,7 @@ Item {
6768
6869 onProgressChanged: {
6970 if (progress == 0) {
70− tabBarHolder.currentTab = 0;
71+ tabBar.currentTab = 0;
7172 }
7273 }
7374
@@ -96,7 +97,7 @@ Item {
9697 Item {
9798 id: topBar
9899 width: parent.width
99− height: childrenRect.height
100+ height: pageHeader.height + (tabBar.opacity == 1 ? tabBar.height + tabBar.anchors.margins : 0)
100101
101102 y: {
102103 if (root.progress < 0.5) {
@@ -118,7 +119,7 @@ Item {
118119 }
119120
120121 ScopesOverviewTab {
121− id: tabBarHolder
122+ id: tabBar
122123 anchors {
123124 left: parent.left
124125 right: parent.right
@@ -126,27 +127,31 @@ Item {
126127 margins: units.gu(2)
127128 }
128129 height: units.gu(4)
130+
131+ enabled: opacity == 1
132+ opacity: !scope || scope.searchQuery == "" ? 1 : 0
133+ Behavior on opacity { }
129134 }
130135 }
131136
132137 Repeater {
133138 id: middleItems
134− model: scope ? scope.categories : null
139+ model: scope && scope.searchQuery == "" ? scope.categories : null
135140 delegate: Loader {
136141 id: loader
137142
138143 height: {
139144 if (index == 0) {
140− return parent.height;
145+ return root.height;
141146 } else {
142− return parent.height - topBar.height - units.gu(2)
147+ return root.height - topBar.height - units.gu(2)
143148 }
144149 }
145150 width: {
146151 if (index == 0) {
147− return parent.width / scopeScale
152+ return root.width / scopeScale
148153 } else {
149− return parent.width
154+ return root.width
150155 }
151156 }
152157 x: {
@@ -157,7 +162,7 @@ Item {
157162 }
158163 }
159164 anchors {
160− bottom: parent.bottom
165+ bottom: scopesOverviewContent.bottom
161166 }
162167
163168 scale: index == 0 ? scopeScale : 1
@@ -166,7 +171,7 @@ Item {
166171 if (root.overrideOpacity >= 0)
167172 return root.overrideOpacity;
168173
169− if (tabBarHolder.currentTab != index)
174+ if (tabBar.currentTab != index)
170175 return 0;
171176
172177 return index == 0 ? 1 : root.progress;
@@ -189,12 +194,9 @@ Item {
189194 }
190195
191196 source: {
192− if (index == 0) return "ScopesOverviewFavourites.qml";
193− else if (index == 1) return "ScopesOverviewAll.qml";
194− else {
195− console.log("WARNING: ScopesOverview scope is not supposed to have more than 2 categories");
196− return "";
197− }
197+ if (index == 0 && categoryId == "favorites") return "ScopesOverviewFavorites.qml";
198+ else if (index == 1 && categoryId == "all") return "ScopesOverviewAll.qml";
199+ else return "";
198200 }
199201
200202 onLoaded: {
@@ -213,7 +215,7 @@ Item {
213215 Connections {
214216 target: loader.item
215217 onClicked: {
216− if (tabBarHolder.currentTab == 0) {
218+ if (tabBar.currentTab == 0) {
217219 root.favoriteSelected(index)
218220 } else {
219221 var favoriteScopesItem = middleItems.itemAt(0).item;
@@ -235,12 +237,31 @@ Item {
235237 }
236238 }
237239
240+ GenericScopeView {
241+ id: searchResultsViewer
242+ anchors {
243+ top: topBar.bottom
244+ right: parent.right
245+ left: parent.left
246+ bottom: parent.bottom
247+ }
248+ scope: root.scope && root.scope.searchQuery != "" ? root.scope : null
249+ scopeStyle: root.scopeStyle
250+ enabled: opacity == 1
251+ showPageHeader: false
252+ clip: true
253+ opacity: searchResultsViewer.scope ? 1 : 0
254+ Behavior on opacity { UbuntuNumberAnimation {} }
255+ }
256+
238257 Rectangle {
239258 id: bottomBar
240259 color: "black"
241260 height: units.gu(6)
242261 width: parent.width
243− opacity: 0.4
262+ enabled: opacity == 0.4
263+ opacity: scope && scope.searchQuery == "" ? 0.4 : 0
264+ Behavior on opacity { UbuntuNumberAnimation {} }
244265 y: {
245266 if (root.progress < 0.5) {
246267 return parent.height;
qml/Dash/ScopesOverviewFavourites.qml → qml/Dash/ScopesOverviewFavorites.qmlrenamed

The content is the same.

qml/Dash/ScopesOverviewTab.qml+6−6
@@ -28,13 +28,13 @@ Item {
2828 width: parent.width / 2
2929 Rectangle {
3030 anchors.fill: parent
31− color: root.currentTab == 0 ? "white" : "transparent"
31+ color: root.currentTab == 0 && root.enabled ? "white" : "transparent"
3232 radius: units.dp(10)
3333 }
3434 Label {
3535 anchors.centerIn: parent
36− text: i18n.tr("Favourites")
37− color: root.currentTab == 0 ? "black" : "white"
36+ text: i18n.tr("Favorites")
37+ color: root.currentTab == 0 && root.enabled ? "black" : "white"
3838 }
3939 onClicked: root.currentTab = 0
4040 }
@@ -45,19 +45,19 @@ Item {
4545 width: parent.width / 2
4646 Rectangle {
4747 anchors.fill: parent
48− color: root.currentTab == 1 ? "white" : "transparent"
48+ color: root.currentTab == 1 && root.enabled ? "white" : "transparent"
4949 radius: units.dp(10)
5050 }
5151 Label {
5252 anchors.centerIn: parent
5353 text: i18n.tr("All")
54− color: root.currentTab == 1 ? "black" : "white"
54+ color: root.currentTab == 1 && root.enabled ? "black" : "white"
5555 }
5656 onClicked: root.currentTab = 1
5757 }
5858 Rectangle {
5959 id: centerPiece
60− width: units.dp(10)
60+ width: root.enabled ? units.dp(10) : units.dp(1)
6161 height: parent.height
6262 color: "white"
6363 x: root.currentTab == 1 ? tab2.x : tab2.x - width
tests/mocks/Unity/fake_scope.cpp+1
@@ -167,6 +167,7 @@ void Scope::cancelActivation()
167167
168168void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
169169{
170+ qFatal("Scope::closeScope is not implemented");
170171}
171172
172173QString Scope::currentDepartmentId() const
tests/mocks/Unity/fake_scopesoverview.cpp+15−9
@@ -23,16 +23,22 @@
2323ScopesOverview::ScopesOverview(Scopes* parent)
2424 : Scope("scopesOverview", "Scopes Overview", false, parent)
2525{
26− delete m_categories;
27− m_categories = new ScopesOverviewCategories(parent, this);
26+ m_searchCategories = m_categories; // save the usual categories as search result
27+ m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
28+ m_categories = m_scopesOverviewCategories;
2829}
2930
30−void ScopesOverview::activate(QVariant const& result)
31+void ScopesOverview::setSearchQuery(const QString& search_query)
3132{
32− Scopes *scopes = dynamic_cast<Scopes*>(parent());
33− Q_EMIT openScope(scopes->getScope(result.toString()));
34−}
33+ Scope::setSearchQuery(search_query);
34+
35+ auto origCategories = m_categories;
36+ if (search_query.isEmpty()) m_categories = m_scopesOverviewCategories;
37+ else m_categories = m_searchCategories;
3538
39+ if (m_categories != origCategories)
40+ Q_EMIT categoriesChanged();
41+}
3642
3743
3844ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
@@ -71,9 +77,9 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
7177 }
7278 switch (role) {
7379 case RoleCategoryId:
74− return index.row() == 0 ? "favourites" : "all";
80+ return index.row() == 0 ? "favorites" : "all";
7581 case RoleName:
76− return index.row() == 0 ? "Favourites" : "All";
82+ return index.row() == 0 ? "Favorites" : "All";
7783 case RoleIcon:
7884 return QVariant();
7985 case RoleRawRendererTemplate:
@@ -117,7 +123,7 @@ ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFa
117123
118124QString ScopesOverviewResultsModel::categoryId() const
119125{
120− return m_isFavoriteCategory ? "favourites" : "all";
126+ return m_isFavoriteCategory ? "favorites" : "all";
121127}
122128
123129void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
tests/mocks/Unity/fake_scopesoverview.h+5−1
@@ -29,7 +29,11 @@ class ScopesOverview : public Scope
2929public:
3030 ScopesOverview(Scopes* parent = 0);
3131
32− Q_INVOKABLE void activate(QVariant const& result) override;
32+ void setSearchQuery(const QString& search_query) override;
33+
34+private:
35+ unity::shell::scopes::CategoriesInterface *m_scopesOverviewCategories;
36+ unity::shell::scopes::CategoriesInterface *m_searchCategories;
3337};
3438
3539class ScopesOverviewCategories : public unity::shell::scopes::CategoriesInterface