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