on xenial help sign in
Use activate and openScope as mhr3 wants
commitbc9befc081b3f515839878499eef3b36d57368b1 authorAlbert Astals <albert.astals@canonical.com> dateFri 18 Jul 2014, 15:25 (12 years ago) parent033eafa
6 files changed+57−21
qml/Dash/Dash.qml+3−11 qml/Dash/ScopesOverview.qml+18−7 tests/mocks/Unity/fake_scopes.cpp+16−1 tests/mocks/Unity/fake_scopes.h+11 tests/mocks/Unity/fake_scopesoverview.cpp+8−2 tests/mocks/Unity/fake_scopesoverview.h+1
qml/Dash/Dash.qml+3−11
@@ -62,11 +62,6 @@ Showable {
6262 id: filteredScopes
6363 model: Scopes {
6464 id: scopes
65− onLoadedChanged: {
66− if (loaded) {
67− scopesOverview.scope = scopes.getScope("scopesOverview");
68− }
69− }
7065 }
7166 dynamicSortFilter: true
7267
@@ -88,7 +83,7 @@ Showable {
8883 ScopesOverview {
8984 id: scopesOverview
9085 anchors.fill: parent
91− scope: scopes ? scopes.getScope("scopesOverview") : null
86+ scope: scopes.overviewScope
9287 progress: overviewController.progress
9388 scopeScale: scopeItem.scope ? 0.4 : (1 - overviewController.progress * 0.6)
9489 visible: scopeScale != 1
@@ -108,9 +103,6 @@ Showable {
108103 animateDashFromAll(dashContent.currentScopeId);
109104 hide();
110105 }
111− onAllSelected: {
112− showTemporaryScope(scopes.getScope(scopeId), pos, allCardSize);
113− }
114106 onSearchSelected: {
115107 var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId);
116108 if (scopeIndex >= 0) {
@@ -119,8 +111,8 @@ Showable {
119111 showDashFromPos(pos, size);
120112 hide();
121113 } else {
122− // Is not a favorite one
123− showTemporaryScope(scopes.getScope(scopeId), pos, size)
114+ // Is not a favorite one, activate and get openScope
115+ scope.activate(result);
124116 }
125117 }
126118 function hide() {
qml/Dash/ScopesOverview.qml+18−7
@@ -64,12 +64,16 @@ Item {
6464 signal done()
6565 signal favoriteSelected(var scopeId)
6666 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)
6968
70− function showTemporaryScope(scope, itemPos, itemSize) {
71− scopesOverviewXYScaler.restorePosition = itemPos;
72− scopesOverviewXYScaler.restoreSize = itemSize;
69+ Connections {
70+ target: scope
71+ onOpenScope: showTemporaryScope(scope);
72+ }
73+
74+ function showTemporaryScope(scope) {
75+ var itemPos = scopesOverviewXYScaler.restorePosition;
76+ var itemSize = scopesOverviewXYScaler.restoreSize;
7377 scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
7478 scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
7579 scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
@@ -276,7 +280,10 @@ Item {
276280 if (scopeIndex >= 0) {
277281 root.allFavoriteSelected(itemModel.scopeId);
278282 } 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);
280287 }
281288 }
282289 }
@@ -309,7 +316,10 @@ Item {
309316 clickOverride: function (index, result, item, itemModel) {
310317 pageHeader.closeSearchHistory();
311318 if (itemModel.scopeId) {
312− root.searchSelected(itemModel.scopeId, item.mapToItem(null, 0, 0), Qt.size(item.width, item.height));
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);
322+ root.searchSelected(itemModel.scopeId, result, item.mapToItem(null, 0, 0), Qt.size(item.width, item.height));
313323 } else {
314324 // Not a scope, just activate it
315325 searchResultsViewer.scope.activate(result);
@@ -407,6 +417,7 @@ Item {
407417 onRunningChanged: {
408418 if (!running) {
409419 if (root.showingNonFavoriteScope && scopesOverviewXYScaler.scale != 1) {
420+ root.scope.closeScope(tempScopeItem.scope);
410421 tempScopeItem.scope = null;
411422 } else if (root.growingDashFromPos) {
412423 root.growingDashFromPos = false;
tests/mocks/Unity/fake_scopes.cpp+16−1
@@ -59,6 +59,7 @@ void Scopes::updateScopes()
5959 if (!m_loaded) {
6060 m_loaded = true;
6161 Q_EMIT loadedChanged();
62+ Q_EMIT overviewScopeChanged();
6263 }
6364}
6465
@@ -122,7 +123,16 @@ unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
122123
123124unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
124125{
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+{
126136 for (Scope *scope : m_scopes) {
127137 if (scope->id() == scope_id)
128138 return scope;
@@ -140,6 +150,11 @@ bool Scopes::loaded() const
140150 return m_loaded;
141151}
142152
153+unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
154+{
155+ return m_scopesOverview;
156+}
157+
143158QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
144159{
145160 QList<unity::shell::scopes::ScopeInterface *> res;
tests/mocks/Unity/fake_scopes.h+11
@@ -32,6 +32,9 @@ class Scopes : public unity::shell::scopes::ScopesInterface
3232{
3333 Q_OBJECT
3434
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+
3538public:
3639 explicit Scopes(QObject *parent = 0);
3740 ~Scopes();
@@ -50,8 +53,16 @@ public:
5053 QModelIndex parent ( const QModelIndex & index ) const;
5154
5255 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;
5358
59+ // This is used as part of implementation of the other C++ code, not API
5460 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();
5566
5667private Q_SLOTS:
5768 void updateScopes();
tests/mocks/Unity/fake_scopesoverview.cpp+8−2
@@ -41,6 +41,12 @@ void ScopesOverview::setSearchQuery(const QString& search_query)
4141 Q_EMIT categoriesChanged();
4242}
4343
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+}
4450
4551ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
4652 : unity::shell::scopes::CategoriesInterface(parent)
@@ -152,9 +158,9 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
152158 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
153159 QList<unity::shell::scopes::ScopeInterface *> scopes;
154160 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");
156162 } 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");
158164 }
159165 resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
160166 m_resultsModels[index.row()] = resultsModel;
tests/mocks/Unity/fake_scopesoverview.h+1
@@ -30,6 +30,7 @@ public:
3030 ScopesOverview(Scopes* parent = 0);
3131
3232 void setSearchQuery(const QString& search_query) override;
33+ Q_INVOKABLE void activate(QVariant const& result) override;
3334
3435private:
3536 unity::shell::scopes::CategoriesInterface *m_scopesOverviewCategories;