on 84b5cd5 help sign in
unity8/Dash/DashContent.qml
148 lines 5.5 kB history raw
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 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Unity 0.1
21Item {
22 id: dashContent
24 property var model: null
25 property var scopes: null
26 property real contentProgress: Math.max(0, Math.min(dashContentList.contentX / (dashContentList.contentWidth - dashContentList.width), units.dp(1)))
27 property alias currentIndex: dashContentList.currentIndex
29 property ScopeDelegateMapper scopeMapper : ScopeDelegateMapper {}
31 signal movementStarted()
32 signal movementEnded()
33 signal contentFlickStarted()
34 signal contentEndReached()
35 signal previewShown()
36 signal scopeLoaded(string scopeId)
37 signal positionedAtBeginning()
39 // If we set the current scope index before the scopes have been added,
40 // then we need to wait until the loaded signals gets emitted from the scopes
41 property var set_current_index: undefined
42 Connections {
43 target: scopes
44 onLoadedChanged: {
45 if (scopes.loaded && set_current_index != undefined) {
46 setCurrentScopeAtIndex(set_current_index[0], set_current_index[1], set_current_index[2]);
47 set_current_index = undefined;
48 }
49 }
50 }
52 function setCurrentScopeAtIndex(index, animate, reset) {
53 var storedMoveDuration = dashContentList.highlightMoveDuration
54 var storedMoveSpeed = dashContentList.highlightMoveVelocity
55 if (!animate) {
56 dashContentList.highlightMoveVelocity = units.gu(4167)
57 dashContentList.highlightMoveDuration = 0
58 }
60 // if the scopes haven't loaded yet, then wait until they are.
61 if (!scopes.loaded) {
62 set_current_index = [ index, animate, reset ]
63 return;
64 }
65 set_current_index = undefined;
67 if (dashContentList.count > index)
68 {
69 dashContentList.currentIndex = index
71 if (reset) {
72 dashContent.positionedAtBeginning()
73 }
74 }
76 if (!animate) {
77 dashContentList.highlightMoveDuration = storedMoveDuration
78 dashContentList.highlightMoveVelocity = storedMoveSpeed
79 }
80 }
82 ListView {
83 id: dashContentList
84 objectName: "dashContentList"
86 interactive: dashContent.scopes.loaded
88 anchors.fill: parent
89 model: dashContent.model
90 orientation: ListView.Horizontal
91 boundsBehavior: Flickable.DragAndOvershootBounds
92 flickDeceleration: units.gu(625)
93 maximumFlickVelocity: width * 5
94 snapMode: ListView.SnapOneItem
95 highlightMoveDuration: 250
96 highlightRangeMode: ListView.StrictlyEnforceRange
97 /* FIXME: workaround rendering issue due to use of ShaderEffectSource in
98 UbuntuShape. While switching from the home scope to the People scope the
99 rendering would block midway.
100 */
101 cacheBuffer: 2147483647
102 onMovementStarted: dashContent.movementStarted()
103 onMovementEnded: dashContent.movementEnded()
105 // If the number of items is less than the current index, then need to reset to another item.
106 onCountChanged: {
107 if (currentIndex >= count)
108 dashContent.setCurrentScopeAtIndex(count-1, true, true)
109 }
111 delegate:
112 Loader {
113 width: ListView.view.width
114 height: ListView.view.height
115 asynchronous: true
116 source: scopeMapper.map(scope.id)
118 // these are needed for autopilot tests
119 readonly property string scopeId: scope.id
120 readonly property bool isCurrent: ListView.isCurrentItem
121 readonly property bool isLoaded: status == Loader.Ready
123 onLoaded: {
124 item.scope = Qt.binding(function() { return scope })
125 item.isCurrent = Qt.binding(function() { return ListView.isCurrentItem })
126 item.searchHistory = Qt.binding(function() { return shell.searchHistory })
127 dashContentList.movementStarted.connect(item.movementStarted)
128 dashContent.positionedAtBeginning.connect(item.positionedAtBeginning)
129 dashContent.scopeLoaded(item.scope.id)
130 }
131 Connections {
132 target: item
133 ignoreUnknownSignals: true
134 onEndReached: contentEndReached()
135 onPreviewShownChanged: {
136 if (item.previewShown) {
137 previewShown()
138 dashContentList.interactive = false
139 } else {
140 dashContentList.interactive = true
141 }
142 }
143 }
145 Component.onDestruction: active = false
146 }
147 }