on cb6d2b2 help sign in
unity8/Dash/GenericScopeView.qml
287 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
21import "../Components/IconUtil.js" as IconUtil
23ScopeView {
24 id: scopeView
25 property alias previewShown: previewLoader.onScreen
27 onIsCurrentChanged: {
28 pageHeader.resetSearch();
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 = results.firstModel
78 item.secondModel = results.secondModel
79 } else {
80 item.model = results
81 }
82 item.objectName = 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 default: return "Generic/GenericFilterGrid.qml";
184 }
185 }
186 case "carousel": return "Generic/GenericCarousel.qml";
187 case "special": {
188 switch (contentType) {
189 case "apps": return "Apps/RunningApplicationsGrid.qml";
190 default: return "Generic/GenericFilterGrid.qml";
191 }
192 }
193 default: return "Generic/GenericFilterGrid.qml";
194 }
195 }
197 OpenEffect {
198 id: effect
199 anchors {
200 fill: parent
201 bottomMargin: -bottomOverflow
202 }
203 sourceItem: categoryView
205 enabled: gap > 0.0
207 topGapPx: (1 - gap) * positionPx
208 topOpacity: (1 - gap * 1.2)
209 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
210 bottomOverflow: units.gu(20)
211 bottomOpacity: 1 - (gap * 0.8)
213 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
214 property real gap: previewLoader.open ? 1.0 : 0.0
216 Behavior on gap {
217 NumberAnimation {
218 duration: 200
219 easing.type: Easing.InOutQuad
220 onRunningChanged: {
221 if (!previewLoader.open && !running) {
222 previewLoader.onScreen = false
223 }
224 }
225 }
226 }
227 }
229 Connections {
230 target: scopeView.scope
231 onPreviewReady: {
232 previewLoader.previewData = preview
233 previewLoader.open = true
234 }
235 }
237 PreviewDelegateMapper {
238 id: previewDelegateMapper
239 }
241 Connections {
242 ignoreUnknownSignals: true
243 target: previewLoader.valid ? previewLoader.item : null
244 onClose: {
245 previewLoader.open = false
246 }
247 }
249 Loader {
250 id: previewLoader
251 property var previewData
252 height: effect.bottomGapPx - effect.topGapPx
253 anchors {
254 top: parent.top
255 topMargin: effect.topGapPx
256 left: parent.left
257 right: parent.right
258 }
259 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
261 property bool open: false
262 property bool onScreen: false
263 property bool valid: item !== null
265 onOpenChanged: {
266 if (open) {
267 onScreen = true
268 }
269 }
271 onLoaded: {
272 item.previewData = Qt.binding(function() { return previewLoader.previewData })
273 }
274 }
276 // TODO: Move as InverseMouseArea to DashPreview
277 MouseArea {
278 enabled: previewLoader.onScreen
279 anchors {
280 fill: parent
281 topMargin: effect.bottomGapPx
282 }
283 onClicked: {
284 previewLoader.open = false;
285 }
286 }