on xenial help sign in
Add support for category header links.
commit63f226997379a82412664b4cff7c681ce1a19987 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 11 Jul 2014, 18:39 (12 years ago) parentee858d0
8 files changed+60−35
debian/control+1−1 qml/Components/ListItems/Header.qml+16−26 qml/Dash/GenericScopeView.qml+7−2 tests/mocks/Unity/fake_categories.cpp+9 tests/mocks/Unity/fake_categories.h+2 tests/mocks/Unity/fake_scope.cpp−5 tests/mocks/Unity/fake_scope.h+1−1 tests/qmltests/Dash/tst_GenericScopeView.qml+24
debian/control+1−1
@@ -108,7 +108,7 @@ Depends: qtdeclarative5-ubuntu-thumbnailer0.1 | ubuntu-thumbnailer-impl,
108108 unity-application-impl-2,
109109 unity-notifications-impl-3,
110110 unity-plugin-scopes | unity-scopes-impl,
111− unity-scopes-impl-0,
111+ unity-scopes-impl-2,
112112 unity8-fake-env | unity-application-impl,
113113 ${misc:Depends},
114114Breaks: unity8 (<< 7.86),
qml/Components/ListItems/Header.qml+16−26
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013,2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -18,51 +18,41 @@ import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919
2020Item {
21− /*!
22− \preliminary
23− The text that is shown as the header text.
24− \qmlproperty string text
25− */
2621 property alias text: label.text
27− property alias textColor: label.color
28− property alias image: image.source
22+ property alias color: label.color
23+ property alias iconName: icon.name
2924
3025 signal clicked(variant mouse)
3126
3227 height: units.gu(5)
3328
34− Item {
29+ Row {
30+ spacing: units.gu(.5)
3531 anchors {
3632 left: parent.left
3733 right: parent.right
38− rightMargin: units.gu(0.5)
39− top: parent.top
40− bottom: parent.bottom
34+ verticalCenter: parent.verticalCenter
35+ margins: units.gu(1)
4136 }
4237
4338 Label {
4439 id: label
45− anchors {
46− left: parent.left
47− leftMargin: units.gu(2)
48− verticalCenter: parent.verticalCenter
49− }
5040
51− color: "grey" // TODO karni: Update Ubuntu.Compoonents.Themes.Palette.
5241 font.family: "Ubuntu"
5342 fontSize: "medium"
5443 elide: Text.ElideRight
44+ maximumLineCount: 1
5545 textFormat: Text.PlainText
56− width: parent.width - image.width - image.leftMargin - anchors.leftMargin
46+ width: Math.min(parent.width - units.gu(4), implicitWidth)
5747 }
5848
59− Image {
60− id: image
61− readonly property double leftMargin: units.gu(1)
62− x: label.x + label.contentWidth + leftMargin
63− anchors {
64− verticalCenter: parent.verticalCenter
65− }
49+ Icon {
50+ id: icon
51+ visible: name != ""
52+ anchors.bottom: label.baseline
53+ height: units.gu(1)
54+ width: height
55+ color: label.color
6656 }
6757 }
6858
qml/Dash/GenericScopeView.qml+7−2
@@ -136,6 +136,7 @@ FocusScope {
136136 }
137137 property bool expanded: false
138138 readonly property string category: categoryId
139+ readonly property string headerLink: model.headerLink
139140 readonly property var item: rendererLoader.item
140141
141142 function expand(expand, animate) {
@@ -370,10 +371,14 @@ FocusScope {
370371 sectionProperty: "name"
371372 sectionDelegate: ListItems.Header {
372373 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
373− property var delegate: categoryView.item(delegateIndex)
374+ readonly property var delegate: categoryView.item(delegateIndex)
374375 width: categoryView.width
375376 text: section
376− textColor: scopeStyle ? scopeStyle.foreground : "grey"
377+ color: scopeStyle ? scopeStyle.foreground : "grey"
378+ iconName: delegate.headerLink ? "go-next" : ""
379+ onClicked: {
380+ if (delegate.headerLink) scopeView.scope.performQuery(delegate.headerLink);
381+ }
377382 }
378383
379384 pageHeader: PageHeader {
tests/mocks/Unity/fake_categories.cpp+9
@@ -169,6 +169,9 @@ Categories::data(const QModelIndex& index, int role) const
169169 return map;
170170 }
171171 case RoleHeaderLink:
172+ if (index.row() == 1) {
173+ return QString("scope://query/1");
174+ }
172175 return QString();
173176 case RoleResults:
174177 return QVariant::fromValue(resultsModel);
@@ -180,3 +183,9 @@ Categories::data(const QModelIndex& index, int role) const
180183 }
181184 }
182185}
186+
187+QVariant
188+Categories::data(int row, int role) const
189+{
190+ return data(index(row, 0), role);
191+}
tests/mocks/Unity/fake_categories.h+2
@@ -37,6 +37,8 @@ public:
3737 Q_INVOKABLE void addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject) override;
3838 Q_INVOKABLE bool overrideCategoryJson(QString const& categoryId, QString const& json) override;
3939
40+ Q_INVOKABLE QVariant data(int row, int role) const;
41+
4042private Q_SLOTS:
4143 void countChanged();
4244
tests/mocks/Unity/fake_scope.cpp−5
@@ -216,8 +216,3 @@ void Scope::loadDepartment(const QString& id)
216216 m_currentDeparment = id;
217217 Q_EMIT currentDepartmentIdChanged();
218218}
219−
220−void Scope::performQuery(const QString& query)
221−{
222− Q_UNUSED(query);
223−}
tests/mocks/Unity/fake_scope.h+1−1
@@ -64,7 +64,7 @@ public:
6464 bool hasDepartments() const override;
6565 Q_INVOKABLE unity::shell::scopes::DepartmentInterface* getDepartment(const QString& id) override;
6666 Q_INVOKABLE void loadDepartment(const QString& id) override;
67− Q_INVOKABLE void performQuery(const QString& query) override;
67+ Q_SIGNAL void performQuery(const QString& query) override;
6868
6969 QVariantMap customizations() const override;
7070
tests/qmltests/Dash/tst_GenericScopeView.qml+24
@@ -39,6 +39,10 @@ Item {
3939 id: scopes
4040 }
4141
42+ SignalSpy {
43+ id: spy
44+ }
45+
4246 property Item applicationManager: Item {
4347 signal sideStageFocusedApplicationChanged()
4448 signal mainStageFocusedApplicationChanged()
@@ -62,6 +66,13 @@ Item {
6266 waitForRendering(genericScopeView.categoryView);
6367 }
6468
69+ function cleanup() {
70+ genericScopeView.scope = null;
71+ spy.clear();
72+ spy.target = null;
73+ spy.signalName = "";
74+ }
75+
6576 function test_isActive() {
6677 tryCompare(genericScopeView.scope, "isActive", false)
6778 genericScopeView.isCurrent = true
@@ -152,6 +163,19 @@ Item {
152163 tryCompare(category2, "expanded", false);
153164 }
154165
166+ function test_headerLink() {
167+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader1") != null; }, true);
168+ var header = findChild(genericScopeView, "dashSectionHeader1");
169+
170+ spy.target = genericScopeView.scope;
171+ spy.signalName = "performQuery";
172+
173+ mouseClick(header, header.width / 2, header.height / 2);
174+
175+ spy.wait();
176+ compare(spy.signalArguments[0][0], genericScopeView.scope.categories.data(1, Categories.RoleHeaderLink));
177+ }
178+
155179 function test_narrow_delegate_ranges_expand() {
156180 tryCompareFunction(function() { return findChild(genericScopeView, "dashCategory0") !== null; }, true);
157181 var category = findChild(genericScopeView, "dashCategory0")