on xenial help sign in
Use activate and openScope as mhr3 wants
bc9befcAlbert Astals
qml/Dash/Dash.qml+3−11
@@ -62,11 +62,6 @@ Showable {
62 id: filteredScopes
62 id: filteredScopes
63 model: Scopes {
63 model: Scopes {
64 id: scopes
64 id: scopes
65− onLoadedChanged: {
66− if (loaded) {
67− scopesOverview.scope = scopes.getScope("scopesOverview");
68− }
69− }
70 }
65 }
71 dynamicSortFilter: true
66 dynamicSortFilter: true
72
67
@@ -88,7 +83,7 @@ Showable {
88 ScopesOverview {
83 ScopesOverview {
89 id: scopesOverview
84 id: scopesOverview
90 anchors.fill: parent
85 anchors.fill: parent
91− scope: scopes ? scopes.getScope("scopesOverview") : null
86+ scope: scopes.overviewScope
92 progress: overviewController.progress
87 progress: overviewController.progress
93 scopeScale: scopeItem.scope ? 0.4 : (1 - overviewController.progress * 0.6)
88 scopeScale: scopeItem.scope ? 0.4 : (1 - overviewController.progress * 0.6)
94 visible: scopeScale != 1
89 visible: scopeScale != 1
@@ -108,9 +103,6 @@ Showable {
108 animateDashFromAll(dashContent.currentScopeId);
103 animateDashFromAll(dashContent.currentScopeId);
109 hide();
104 hide();
110 }
105 }
111− onAllSelected: {
112− showTemporaryScope(scopes.getScope(scopeId), pos, allCardSize);
113− }
114 onSearchSelected: {
106 onSearchSelected: {
115 var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId);
107 var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId);
116 if (scopeIndex >= 0) {
108 if (scopeIndex >= 0) {
@@ -119,8 +111,8 @@ Showable {
119 showDashFromPos(pos, size);
111 showDashFromPos(pos, size);
120 hide();
112 hide();
121 } else {
113 } else {
122− // Is not a favorite one
114+ // Is not a favorite one, activate and get openScope
123− showTemporaryScope(scopes.getScope(scopeId), pos, size)
115+ scope.activate(result);
124 }
116 }
125 }
117 }
126 function hide() {
118 function hide() {
qml/Dash/ScopesOverview.qml+18−7
@@ -64,12 +64,16 @@ Item {
64 signal done()
64 signal done()
65 signal favoriteSelected(var scopeId)
65 signal favoriteSelected(var scopeId)
66 signal allFavoriteSelected(var scopeId)
66 signal allFavoriteSelected(var scopeId)
67− signal allSelected(var scopeId, var pos)
68− signal searchSelected(var scopeId, var pos, var size)
67+ signal searchSelected(var scopeId, var result, var pos, var size)
69
68
69+ Connections {
70+ target: scope
71+ onOpenScope: showTemporaryScope(scope);
72+ }
73+
70− function showTemporaryScope(scope, itemPos, itemSize) {
74+ function showTemporaryScope(scope) {
71− scopesOverviewXYScaler.restorePosition = itemPos;
75+ var itemPos = scopesOverviewXYScaler.restorePosition;
72− scopesOverviewXYScaler.restoreSize = itemSize;
76+ var itemSize = scopesOverviewXYScaler.restoreSize;
73 scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
77 scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
74 scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
78 scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
75 scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
79 scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
@@ -276,7 +280,10 @@ Item {
276 if (scopeIndex >= 0) {
280 if (scopeIndex >= 0) {
277 root.allFavoriteSelected(itemModel.scopeId);
281 root.allFavoriteSelected(itemModel.scopeId);
278 } else {
282 } else {
279− root.allSelected(itemModel.scopeId, item.mapToItem(null, 0, 0));
283+ // Will result in an openScope from root.scope
284+ scopesOverviewXYScaler.restorePosition = item.mapToItem(null, 0, 0);
285+ scopesOverviewXYScaler.restoreSize = allCardSize;
286+ root.scope.activate(result);
280 }
287 }
281 }
288 }
282 }
289 }
@@ -309,7 +316,10 @@ Item {
309 clickOverride: function (index, result, item, itemModel) {
316 clickOverride: function (index, result, item, itemModel) {
310 pageHeader.closeSearchHistory();
317 pageHeader.closeSearchHistory();
311 if (itemModel.scopeId) {
318 if (itemModel.scopeId) {
319+ // This can end up in openScope so save restorePosition and restoreSize
320+ scopesOverviewXYScaler.restorePosition = item.mapToItem(null, 0, 0);
321+ scopesOverviewXYScaler.restoreSize = Qt.size(item.width, item.height);
312− root.searchSelected(itemModel.scopeId, item.mapToItem(null, 0, 0), Qt.size(item.width, item.height));
322+ root.searchSelected(itemModel.scopeId, result, item.mapToItem(null, 0, 0), Qt.size(item.width, item.height));
313 } else {
323 } else {
314 // Not a scope, just activate it
324 // Not a scope, just activate it
315 searchResultsViewer.scope.activate(result);
325 searchResultsViewer.scope.activate(result);
@@ -407,6 +417,7 @@ Item {
407 onRunningChanged: {
417 onRunningChanged: {
408 if (!running) {
418 if (!running) {
409 if (root.showingNonFavoriteScope && scopesOverviewXYScaler.scale != 1) {
419 if (root.showingNonFavoriteScope && scopesOverviewXYScaler.scale != 1) {
420+ root.scope.closeScope(tempScopeItem.scope);
410 tempScopeItem.scope = null;
421 tempScopeItem.scope = null;
411 } else if (root.growingDashFromPos) {
422 } else if (root.growingDashFromPos) {
412 root.growingDashFromPos = false;
423 root.growingDashFromPos = false;
tests/mocks/Unity/fake_scopes.cpp+16−1
@@ -59,6 +59,7 @@ void Scopes::updateScopes()
59 if (!m_loaded) {
59 if (!m_loaded) {
60 m_loaded = true;
60 m_loaded = true;
61 Q_EMIT loadedChanged();
61 Q_EMIT loadedChanged();
62+ Q_EMIT overviewScopeChanged();
62 }
63 }
63}
64}
64
65
@@ -122,7 +123,16 @@ unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
122
123
123unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
124unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
124{
125{
125− if (scope_id == "scopesOverview") return m_scopesOverview;
126+ for (Scope *scope : m_scopes) {
127+ // According to mh3 Scopes::getScope should only return non null for visible scopes
128+ if (scope->id() == scope_id && scope->visible())
129+ return scope;
130+ }
131+ return nullptr;
132+}
133+
134+unity::shell::scopes::ScopeInterface* Scopes::getScopeFromAll(const QString& scope_id) const
135+{
126 for (Scope *scope : m_scopes) {
136 for (Scope *scope : m_scopes) {
127 if (scope->id() == scope_id)
137 if (scope->id() == scope_id)
128 return scope;
138 return scope;
@@ -140,6 +150,11 @@ bool Scopes::loaded() const
140 return m_loaded;
150 return m_loaded;
141}
151}
142
152
153+unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
154+{
155+ return m_scopesOverview;
156+}
157+
143QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
158QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
144{
159{
145 QList<unity::shell::scopes::ScopeInterface *> res;
160 QList<unity::shell::scopes::ScopeInterface *> res;
tests/mocks/Unity/fake_scopes.h+11
@@ -32,6 +32,9 @@ class Scopes : public unity::shell::scopes::ScopesInterface
32{
32{
33 Q_OBJECT
33 Q_OBJECT
34
34
35+ // TODO Remove and depend on lp:~unity-team/unity-api/scopes-v3
36+ Q_PROPERTY(unity::shell::scopes::ScopeInterface* overviewScope READ overviewScope NOTIFY overviewScopeChanged)
37+
35public:
38public:
36 explicit Scopes(QObject *parent = 0);
39 explicit Scopes(QObject *parent = 0);
37 ~Scopes();
40 ~Scopes();
@@ -50,8 +53,16 @@ public:
50 QModelIndex parent ( const QModelIndex & index ) const;
53 QModelIndex parent ( const QModelIndex & index ) const;
51
54
52 bool loaded() const override;
55 bool loaded() const override;
56+ // TODO Add override when dependin on lp:~unity-team/unity-api/scopes-v3
57+ unity::shell::scopes::ScopeInterface* overviewScope() const;
53
58
59+ // This is used as part of implementation of the other C++ code, not API
54 QList<unity::shell::scopes::ScopeInterface *> scopes(bool onlyVisible) const;
60 QList<unity::shell::scopes::ScopeInterface *> scopes(bool onlyVisible) const;
61+ unity::shell::scopes::ScopeInterface* getScopeFromAll(const QString& scope_id) const;
62+
63+Q_SIGNALS:
64+ // TODO Remove and depend on lp:~unity-team/unity-api/scopes-v3
65+ void overviewScopeChanged();
55
66
56private Q_SLOTS:
67private Q_SLOTS:
57 void updateScopes();
68 void updateScopes();
tests/mocks/Unity/fake_scopesoverview.cpp+8−2
@@ -41,6 +41,12 @@ void ScopesOverview::setSearchQuery(const QString& search_query)
41 Q_EMIT categoriesChanged();
41 Q_EMIT categoriesChanged();
42}
42}
43
43
44+Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
45+{
46+ Scopes *scopes = dynamic_cast<Scopes*>(parent());
47+ m_openScope = scopes->getScopeFromAll(result.toString());
48+ Q_EMIT openScope(m_openScope);
49+}
44
50
45ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
51ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
46 : unity::shell::scopes::CategoriesInterface(parent)
52 : unity::shell::scopes::CategoriesInterface(parent)
@@ -152,9 +158,9 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
152 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
158 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
153 QList<unity::shell::scopes::ScopeInterface *> scopes;
159 QList<unity::shell::scopes::ScopeInterface *> scopes;
154 if (index.row() == 0) {
160 if (index.row() == 0) {
155− scopes << m_scopes->getScope("clickscope") << nullptr << m_scopes->getScope("MockScope2");
161+ scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
156 } else {
162 } else {
157− scopes << nullptr << m_scopes->getScope("MockScope7") << nullptr << m_scopes->getScope("MockScope1");
163+ scopes << nullptr << m_scopes->getScopeFromAll("MockScope7") << nullptr << m_scopes->getScopeFromAll("MockScope1");
158 }
164 }
159 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
165 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
160 m_resultsModels[index.row()] = resultsModel;
166 m_resultsModels[index.row()] = resultsModel;
tests/mocks/Unity/fake_scopesoverview.h+1
@@ -30,6 +30,7 @@ public:
30 ScopesOverview(Scopes* parent = 0);
30 ScopesOverview(Scopes* parent = 0);
31
31
32 void setSearchQuery(const QString& search_query) override;
32 void setSearchQuery(const QString& search_query) override;
33+ Q_INVOKABLE void activate(QVariant const& result) override;
33
34
34private:
35private:
35 unity::shell::scopes::CategoriesInterface *m_scopesOverviewCategories;
36 unity::shell::scopes::CategoriesInterface *m_scopesOverviewCategories;