on 5bc8421 help sign in
unity8/Dash/GenericScopeView.qml
302 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 }
180 }
182 function getDefaultRendererId(contentType) {
183 switch (contentType) {
184 default: return "grid";
185 }
186 }
188 function getRenderer(rendererId, contentType) {
189 if (rendererId == "default") {
190 rendererId = getDefaultRendererId(contentType);
191 }
192 switch (rendererId) {
193 case "grid": {
194 switch (contentType) {
195 case "video": return "Generic/GenericFilterGridPotrait.qml";
196 case "music": return "Music/MusicFilterGrid.qml";
197 default: return "Generic/GenericFilterGrid.qml";
198 }
199 }
200 case "carousel": return "Generic/GenericCarousel.qml";
201 case "special": {
202 switch (contentType) {
203 case "apps": return "Apps/RunningApplicationsGrid.qml";
204 default: return "Generic/GenericFilterGrid.qml";
205 }
206 }
207 default: return "Generic/GenericFilterGrid.qml";
208 }
209 }
211 OpenEffect {
212 id: effect
213 anchors {
214 fill: parent
215 bottomMargin: -bottomOverflow
216 }
217 sourceItem: categoryView
219 enabled: gap > 0.0
221 topGapPx: (1 - gap) * positionPx
222 topOpacity: (1 - gap * 1.2)
223 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
224 bottomOverflow: units.gu(20)
225 bottomOpacity: 1 - (gap * 0.8)
227 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
228 property real gap: previewLoader.open ? 1.0 : 0.0
230 Behavior on gap {
231 NumberAnimation {
232 duration: 200
233 easing.type: Easing.InOutQuad
234 onRunningChanged: {
235 if (!previewLoader.open && !running) {
236 previewLoader.onScreen = false
237 }
238 }
239 }
240 }
241 }
243 Connections {
244 target: scopeView.scope
245 onPreviewReady: {
246 previewLoader.previewData = preview
247 previewLoader.open = true
248 }
249 }
251 PreviewDelegateMapper {
252 id: previewDelegateMapper
253 }
255 Connections {
256 ignoreUnknownSignals: true
257 target: previewLoader.valid ? previewLoader.item : null
258 onClose: {
259 previewLoader.open = false
260 }
261 }
263 Loader {
264 objectName: "previewLoader"
265 id: previewLoader
266 property var previewData
267 height: effect.bottomGapPx - effect.topGapPx
268 anchors {
269 top: parent.top
270 topMargin: effect.topGapPx
271 left: parent.left
272 right: parent.right
273 }
274 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
276 property bool open: false
277 property bool onScreen: false
278 property bool valid: item !== null
280 onOpenChanged: {
281 if (open) {
282 onScreen = true
283 }
284 }
286 onLoaded: {
287 item.previewData = Qt.binding(function() { return previewLoader.previewData })
288 }
289 }
291 // TODO: Move as InverseMouseArea to DashPreview
292 MouseArea {
293 enabled: previewLoader.onScreen
294 anchors {
295 fill: parent
296 topMargin: effect.bottomGapPx
297 }
298 onClicked: {
299 previewLoader.open = false;
300 }
301 }