on 4d5bcae help sign in
unity8/Dash/GenericScopeView.qml
303 lines 11 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 "../Components"
20import "../Components/ListItems" as ListItems
22ScopeView {
23 id: scopeView
24 readonly property alias previewShown: previewLoader.onScreen
26 onIsCurrentChanged: {
27 pageHeader.resetSearch();
28 previewLoader.open = false;
29 }
31 onMovementStarted: categoryView.showHeader()
33 Binding {
34 target: scopeView.scope
35 property: "searchQuery"
36 value: pageHeader.searchQuery
37 }
39 Binding {
40 target: pageHeader
41 property: "searchQuery"
42 value: scopeView.scope.searchQuery
43 }
45 Connections {
46 target: panel
47 onSearchClicked: if (isCurrent) {
48 pageHeader.triggerSearch()
49 categoryView.showHeader()
50 }
51 }
53 Connections {
54 target: scopeView.scope
55 onShowDash: previewLoader.open = false;
56 onHideDash: previewLoader.open = false;
57 }
59 ScopeListView {
60 id: categoryView
61 anchors.fill: parent
62 model: scopeView.categories
63 forceNoClip: previewLoader.onScreen
65 onAtYEndChanged: if (atYEnd) endReached()
66 onMovingChanged: if (moving && atYEnd) endReached()
68 property string expandedCategoryId: ""
70 delegate: ListItems.Base {
71 highlightWhenPressed: false
73 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
74 readonly property bool filtered: rendererLoader.item ? rendererLoader.item.filter : true
75 readonly property string category: categoryId
77 Loader {
78 id: rendererLoader
79 anchors {
80 top: parent.top
81 left: parent.left
82 right: parent.right
83 }
85 source: getRenderer(model.renderer, model.contentType)
87 onLoaded: {
88 if (source.toString().indexOf("Apps/RunningApplicationsGrid.qml") != -1) {
89 // TODO: the running apps grid doesn't support standard scope results model yet
90 item.firstModel = Qt.binding(function() { return results.firstModel })
91 item.secondModel = Qt.binding(function() { return results.secondModel })
92 } else {
93 item.model = Qt.binding(function() { return results })
94 }
95 item.objectName = Qt.binding(function() { return categoryId })
96 if (item.expandable) {
97 var shouldFilter = categoryId != categoryView.expandedCategoryId;
98 if (shouldFilter != item.filter) {
99 item.filter = shouldFilter;
100 }
101 }
102 }
104 Connections {
105 target: rendererLoader.item
106 onClicked: {
107 effect.positionPx = mapToItem(categoryView, 0, itemY).y
108 scopeView.scope.activate(delegateItem.model.uri,
109 delegateItem.model.icon,
110 delegateItem.model.category,
111 0,
112 delegateItem.model.mimetype,
113 delegateItem.model.title,
114 delegateItem.model.comment,
115 delegateItem.model.dndUri,
116 delegateItem.model.metadata)
117 }
118 onPressAndHold: {
119 effect.positionPx = mapToItem(categoryView, 0, itemY).y
120 scopeView.scope.preview( delegateItem.model.uri,
121 delegateItem.model.icon,
122 delegateItem.model.category,
123 0,
124 delegateItem.model.mimetype,
125 delegateItem.model.title,
126 delegateItem.model.comment,
127 delegateItem.model.dndUri,
128 delegateItem.model.metadata)
129 }
130 }
131 Connections {
132 target: categoryView
133 onExpandedCategoryIdChanged: {
134 var item = rendererLoader.item;
135 if (item.expandable) {
136 var shouldFilter = categoryId != categoryView.expandedCategoryId;
137 if (shouldFilter != item.filter) {
138 // If the filter animation will be seen start it, otherwise, just flip the switch
139 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
140 var growingVisible = !shouldFilter && y + height < categoryView.height;
141 if (shrinkingVisible || growingVisible) {
142 item.startFilterAnimation(shouldFilter)
143 } else {
144 item.filter = shouldFilter;
145 }
146 if (!shouldFilter) {
147 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
148 }
149 }
150 }
151 }
152 }
153 }
154 }
156 sectionProperty: "name"
157 sectionDelegate: ListItems.Header {
158 property var delegate: categoryView.item(delegateIndex)
159 width: categoryView.width
160 text: section
161 image: {
162 if (delegate && delegate.expandable)
163 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
164 return "";
165 }
166 onClicked: {
167 if (categoryView.expandedCategoryId != delegate.category)
168 categoryView.expandedCategoryId = delegate.category;
169 else
170 categoryView.expandedCategoryId = "";
171 }
172 }
173 pageHeader: PageHeader {
174 id: pageHeader
175 objectName: "pageHeader"
176 width: categoryView.width
177 text: scopeView.scope.name
178 searchEntryEnabled: true
179 scope: scopeView.scope
180 }
181 }
183 function getDefaultRendererId(contentType) {
184 switch (contentType) {
185 default: return "grid";
186 }
187 }
189 function getRenderer(rendererId, contentType) {
190 if (rendererId == "default") {
191 rendererId = getDefaultRendererId(contentType);
192 }
193 switch (rendererId) {
194 case "grid": {
195 switch (contentType) {
196 case "video": return "Generic/GenericFilterGridPotrait.qml";
197 case "music": return "Music/MusicFilterGrid.qml";
198 default: return "Generic/GenericFilterGrid.qml";
199 }
200 }
201 case "carousel": return "Generic/GenericCarousel.qml";
202 case "special": {
203 switch (contentType) {
204 case "apps": return "Apps/RunningApplicationsGrid.qml";
205 default: return "Generic/GenericFilterGrid.qml";
206 }
207 }
208 default: return "Generic/GenericFilterGrid.qml";
209 }
210 }
212 OpenEffect {
213 id: effect
214 anchors {
215 fill: parent
216 bottomMargin: -bottomOverflow
217 }
218 sourceItem: categoryView
220 enabled: gap > 0.0
222 topGapPx: (1 - gap) * positionPx
223 topOpacity: (1 - gap * 1.2)
224 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
225 bottomOverflow: units.gu(20)
226 bottomOpacity: 1 - (gap * 0.8)
228 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
229 property real gap: previewLoader.open ? 1.0 : 0.0
231 Behavior on gap {
232 NumberAnimation {
233 duration: 200
234 easing.type: Easing.InOutQuad
235 onRunningChanged: {
236 if (!previewLoader.open && !running) {
237 previewLoader.onScreen = false
238 }
239 }
240 }
241 }
242 }
244 Connections {
245 target: scopeView.scope
246 onPreviewReady: {
247 previewLoader.previewData = preview
248 previewLoader.open = true
249 }
250 }
252 PreviewDelegateMapper {
253 id: previewDelegateMapper
254 }
256 Connections {
257 ignoreUnknownSignals: true
258 target: previewLoader.valid ? previewLoader.item : null
259 onClose: {
260 previewLoader.open = false
261 }
262 }
264 Loader {
265 objectName: "previewLoader"
266 id: previewLoader
267 property var previewData
268 height: effect.bottomGapPx - effect.topGapPx
269 anchors {
270 top: parent.top
271 topMargin: effect.topGapPx
272 left: parent.left
273 right: parent.right
274 }
275 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
277 property bool open: false
278 property bool onScreen: false
279 property bool valid: item !== null
281 onOpenChanged: {
282 if (open) {
283 onScreen = true
284 }
285 }
287 onLoaded: {
288 item.previewData = Qt.binding(function() { return previewLoader.previewData })
289 }
290 }
292 // TODO: Move as InverseMouseArea to DashPreview
293 MouseArea {
294 enabled: previewLoader.onScreen
295 anchors {
296 fill: parent
297 topMargin: effect.bottomGapPx
298 }
299 onClicked: {
300 previewLoader.open = false;
301 }
302 }