on xenial help sign in
Unity ScopeView and GenericScopeView
commit955ccf3add5fc147e2c6c0fc12d5ae40fb5f6a21 authorAlbert Astals <albert.astals@canonical.com> dateFri 8 Nov 2013, 13:09 (13 years ago) parenta6883d5
8 files changed+78−192
Dash/GenericScopeView.qml+47−2 Dash/ScopeView.qml−65 plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+8−4 tests/qmltests/CMakeLists.txt−1 tests/qmltests/Dash/qml/FakeScopeView.qml+4−68 tests/qmltests/Dash/tst_DashContent.qml+12 tests/qmltests/Dash/tst_GenericScopeView.qml+7 tests/qmltests/Dash/tst_ScopeView.qml−52
Dash/GenericScopeView.qml+47−2
@@ -16,15 +16,60 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import Utils 0.1
20+import Unity 0.1
1921import "../Components"
2022import "../Components/ListItems" as ListItems
2123
22−ScopeView {
24+FocusScope {
2325 id: scopeView
26+
27+ property Scope scope
28+ property SortFilterProxyModel categories: categoryFilter
29+ property bool isCurrent
30+ property ListModel searchHistory
31+ property alias moving: categoryView.moving
32+
33+ signal endReached
34+ signal movementStarted
35+ signal positionedAtBeginning
36+
2437 readonly property alias previewShown: previewListView.onScreen
2538 property bool enableHeightBehaviorOnNextCreation: false
2639
27− moving: categoryView.moving
40+ // FIXME delay the search so that daemons have time to settle, note that
41+ // removing this will break ScopeView::test_changeScope
42+ onScopeChanged: {
43+ if (scope) {
44+ timer.restart();
45+ scope.activateApplication.connect(activateApp);
46+ }
47+ }
48+
49+ function activateApp(desktopFilePath) {
50+ shell.activateApplication(desktopFilePath);
51+ }
52+
53+ Binding {
54+ target: scope
55+ property: "isActive"
56+ value: isCurrent
57+ }
58+
59+ Timer {
60+ id: timer
61+ interval: 2000
62+ onTriggered: scope.searchQuery = ""
63+ }
64+
65+ SortFilterProxyModel {
66+ id: categoryFilter
67+ model: scope ? scope.categories : null
68+ dynamicSortFilter: true
69+ filterRole: Categories.RoleCount
70+ filterRegExp: /^0$/
71+ invertMatch: true
72+ }
2873
2974 onIsCurrentChanged: {
3075 pageHeader.resetSearch();
Dash/ScopeView.qmldeleted−65
@@ -1,65 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import Utils 0.1
19−import Unity 0.1
20−
21−FocusScope {
22− property Scope scope
23− property SortFilterProxyModel categories: categoryFilter
24− property bool isCurrent
25− property ListModel searchHistory
26− property bool moving: false
27−
28− signal endReached
29− signal movementStarted
30− signal positionedAtBeginning
31−
32− // FIXME delay the search so that daemons have time to settle, note that
33− // removing this will break ScopeView::test_changeScope
34− onScopeChanged: {
35− if (scope) {
36− timer.restart();
37− scope.activateApplication.connect(activateApp);
38− }
39− }
40−
41− function activateApp(desktopFilePath) {
42− shell.activateApplication(desktopFilePath);
43− }
44−
45− Binding {
46− target: scope
47− property: "isActive"
48− value: isCurrent
49− }
50−
51− Timer {
52− id: timer
53− interval: 2000
54− onTriggered: scope.searchQuery = ""
55− }
56−
57− SortFilterProxyModel {
58− id: categoryFilter
59− model: scope ? scope.categories : null
60− dynamicSortFilter: true
61− filterRole: Categories.RoleCount
62− filterRegExp: /^0$/
63− invertMatch: true
64− }
65−}
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+8−4
@@ -1196,11 +1196,15 @@ void ListViewWithPageHeader::layout()
11961196 }
11971197 }
11981198 QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1199− const qreal clipFrom = visibleFrom + (!item->m_sectionItem && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1200− if (!cull && pos < clipFrom) {
1201− context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
1199+ if (context) {
1200+ const qreal clipFrom = visibleFrom + (!item->m_sectionItem && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1201+ if (!cull && pos < clipFrom) {
1202+ context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
1203+ } else {
1204+ context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
1205+ }
12021206 } else {
1203− context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
1207+ qWarning() << "ListViewWithPageHeader::layout::No context for item found, if you see this outside tests please report";
12041208 }
12051209// qDebug() << "ListViewWithPageHeader::layout" << item->m_item;
12061210 pos += item->height();
tests/qmltests/CMakeLists.txt−1
@@ -47,7 +47,6 @@ add_qml_test(Dash DashContent IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest
4747add_qml_test(Dash DashPreview)
4848add_qml_test(Dash GenericPreview)
4949add_qml_test(Dash GenericScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
50−add_qml_test(Dash ScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
5150add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins
5251 ${CMAKE_BINARY_DIR}/tests/mocks)
5352add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/qml/FakeScopeView.qml+4−68
@@ -19,13 +19,14 @@ import Unity 0.1
1919
2020import "../../../../Dash"
2121
22−ScopeView {
22+GenericScopeView {
2323 id: fakeScopeView
2424
2525 property alias backColor : back.color
2626
2727 onEndReached: {
28− if (shell != undefined && shell.scopeStatus != undefined) {
28+ if (scope != undefined && shell != undefined && shell.scopeStatus != undefined) {
29+ console.log("scope", scope)
2930 shell.scopeStatus[scope.id].endReached++;
3031 }
3132 }
@@ -44,71 +45,6 @@ ScopeView {
4445 id: back
4546 anchors.fill: parent
4647 color: "grey"
47− }
48−
49− function randomBg()
50− {
51− var hex1=new Array("4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
52− var bg="#"+hex1[Math.floor(Math.random()*hex1.length)]+
53− hex1[Math.floor(Math.random()*hex1.length)]+
54− hex1[Math.floor(Math.random()*hex1.length)]+
55− hex1[Math.floor(Math.random()*hex1.length)]+
56− hex1[Math.floor(Math.random()*hex1.length)]+
57− hex1[Math.floor(Math.random()*hex1.length)]
58− return bg
59− }
60−
61−
62− ListView {
63− id: listView
64− anchors.fill: parent
65− model: scope ? scope.categories : null
66− orientation: ListView.Vertical
67−
68− delegate: Column {
69− id: column
70− width: listView.width
71− height: childrenRect.height
72−
73− Rectangle {
74− width: listView.width
75− height: units.gu(3)
76− color: randomBg()
77−
78− Text {
79− text: name
80− font.family: "Ubuntu"
81− font.weight: Font.Bold
82− font.pixelSize: 20
83− anchors.horizontalCenter: parent.horizontalCenter
84− }
85− }
86− GridView {
87− id: resultsGrid
88− model: results
89− cellWidth: units.gu(10); cellHeight: units.gu(10)
90− height: childrenRect.height
91− width: listView.width
92− interactive: false
93−
94− delegate: Component {
95− id: resultDelegate
96− Item {
97− width: resultsGrid.cellWidth; height: resultsGrid.cellHeight
98− Column {
99− anchors.verticalCenter: parent.verticalCenter
100− anchors.horizontalCenter: parent.horizontalCenter
101− Image {
102− width: units.gu(5)
103− height: units.gu(5)
104− source: icon
105− anchors.horizontalCenter: parent.horizontalCenter
106− }
107− Text { text: title; anchors.horizontalCenter: parent.horizontalCenter }
108− }
109− }
110− }
111− }
112− }
48+ z: -1
11349 }
11450}
tests/qmltests/Dash/tst_DashContent.qml+12
@@ -28,6 +28,18 @@ Item {
2828
2929 property ListModel searchHistory: ListModel {}
3030
31+ Item {
32+ // Fake. Make a few components less noisy
33+ id: greeter
34+ signal shownChanged
35+ }
36+
37+ Item {
38+ // Fake. Make a few components less noisy
39+ id: panel
40+ signal searchClicked
41+ }
42+
3143 property var scopeStatus: {
3244 'MockScope1': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
3345 'MockScope2': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
tests/qmltests/Dash/tst_GenericScopeView.qml+7
@@ -187,6 +187,13 @@ Item {
187187
188188 closePreview();
189189 }
190+
191+ function test_changeScope() {
192+ genericScopeView.scope.searchQuery = "test"
193+ genericScopeView.scope = scopes.get(1)
194+ genericScopeView.scope = scopes.get(0)
195+ tryCompare(genericScopeView.scope, "searchQuery", "")
196+ }
190197 }
191198 }
192199}
tests/qmltests/Dash/tst_ScopeView.qmldeleted−52
@@ -1,52 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import QtTest 1.0
19−import Unity 0.1
20−import ".."
21−import "../../../Dash"
22−import Ubuntu.Components 0.1
23−
24−Item {
25− width: units.gu(120)
26− height: units.gu(80)
27−
28− Scopes {
29− id: scopes
30− }
31−
32− ScopeView {
33− id: scopeView
34− anchors.fill: parent
35−
36− TestCase {
37− name: "ScopeView"
38− when: scopes.loaded
39−
40− function init() {
41− scopeView.scope = scopes.get(0)
42− }
43−
44− function test_changeScope() {
45− scopeView.scope.searchQuery = "test"
46− scopeView.scope = scopes.get(1)
47− scopeView.scope = scopes.get(0)
48− tryCompare(scopeView.scope, "searchQuery", "")
49− }
50− }
51− }
52−}