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