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