on b700d05 help sign in
unity8/Dash/GenericScopeView.qml
281 lines 9.9 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 }
85 Connections {
86 target: rendererLoader.item
87 onClicked: {
88 effect.positionPx = mapToItem(categoryView, 0, itemY).y
89 scopeView.scope.activate(delegateItem.model.uri,
90 delegateItem.model.icon,
91 delegateItem.model.category,
92 0,
93 delegateItem.model.mimetype,
94 delegateItem.model.title,
95 delegateItem.model.comment,
96 delegateItem.model.dndUri,
97 delegateItem.model.metadata)
98 }
99 onPressAndHold: {
100 effect.positionPx = mapToItem(categoryView, 0, itemY).y
101 scopeView.scope.preview( delegateItem.model.uri,
102 delegateItem.model.icon,
103 delegateItem.model.category,
104 0,
105 delegateItem.model.mimetype,
106 delegateItem.model.title,
107 delegateItem.model.comment,
108 delegateItem.model.dndUri,
109 delegateItem.model.metadata)
110 }
111 }
112 Connections {
113 target: categoryView
114 onExpandedIndexChanged: {
115 var item = rendererLoader.item;
116 if (item.expandable) {
117 var shouldFilter = index != categoryView.expandedIndex;
118 if (shouldFilter != item.filter) {
119 // If the filter animation will be seen start it, otherwise, just flip the switch
120 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
121 var growingVisible = !shouldFilter && y + height < categoryView.height;
122 if (shrinkingVisible || growingVisible) {
123 item.startFilterAnimation(shouldFilter)
124 } else {
125 item.filter = shouldFilter;
126 }
127 if (!shouldFilter) {
128 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
129 }
130 }
131 }
132 }
133 }
134 }
135 }
137 sectionProperty: "name"
138 sectionDelegate: ListItems.Header {
139 property var delegate: categoryView.item(delegateIndex)
140 width: categoryView.width
141 text: section
142 image: {
143 if (delegate && delegate.expandable)
144 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
145 return "";
146 }
147 onClicked: {
148 if (categoryView.expandedIndex != delegateIndex)
149 categoryView.expandedIndex = delegateIndex;
150 else
151 categoryView.expandedIndex = -1;
152 }
153 }
154 pageHeader: PageHeader {
155 id: pageHeader
156 objectName: "pageHeader"
157 width: categoryView.width
158 text: scopeView.scope.name
159 searchEntryEnabled: true
160 }
161 }
163 function getDefaultRendererId(contentType) {
164 switch (contentType) {
165 default: return "grid";
166 }
167 }
169 function getRenderer(rendererId, contentType) {
170 if (rendererId == "default") {
171 rendererId = getDefaultRendererId(contentType);
172 }
173 switch (rendererId) {
174 case "grid": {
175 switch (contentType) {
176 case "video": return "Generic/GenericFilterGridPotrait.qml";
177 default: return "Generic/GenericFilterGrid.qml";
178 }
179 }
180 case "carousel": return "Generic/GenericCarousel.qml";
181 case "special": {
182 switch (contentType) {
183 case "apps": return "Apps/RunningApplicationsGrid.qml";
184 default: return "Generic/GenericFilterGrid.qml";
185 }
186 }
187 default: return "Generic/GenericFilterGrid.qml";
188 }
189 }
191 OpenEffect {
192 id: effect
193 anchors {
194 fill: parent
195 bottomMargin: -bottomOverflow
196 }
197 sourceItem: categoryView
199 enabled: gap > 0.0
201 topGapPx: (1 - gap) * positionPx
202 topOpacity: (1 - gap * 1.2)
203 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
204 bottomOverflow: units.gu(20)
205 bottomOpacity: 1 - (gap * 0.8)
207 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
208 property real gap: previewLoader.open ? 1.0 : 0.0
210 Behavior on gap {
211 NumberAnimation {
212 duration: 200
213 easing.type: Easing.InOutQuad
214 onRunningChanged: {
215 if (!previewLoader.open && !running) {
216 previewLoader.onScreen = false
217 }
218 }
219 }
220 }
221 }
223 Connections {
224 target: scopeView.scope
225 onPreviewReady: {
226 previewLoader.previewData = preview
227 previewLoader.open = true
228 }
229 }
231 PreviewDelegateMapper {
232 id: previewDelegateMapper
233 }
235 Connections {
236 ignoreUnknownSignals: true
237 target: previewLoader.valid ? previewLoader.item : null
238 onClose: {
239 previewLoader.open = false
240 }
241 }
243 Loader {
244 id: previewLoader
245 property var previewData
246 height: effect.bottomGapPx - effect.topGapPx
247 anchors {
248 top: parent.top
249 topMargin: effect.topGapPx
250 left: parent.left
251 right: parent.right
252 }
253 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
255 property bool open: false
256 property bool onScreen: false
257 property bool valid: item !== null
259 onOpenChanged: {
260 if (open) {
261 onScreen = true
262 }
263 }
265 onLoaded: {
266 item.previewData = Qt.binding(function() { return previewLoader.previewData })
267 }
268 }
270 // TODO: Move as InverseMouseArea to DashPreview
271 MouseArea {
272 enabled: previewLoader.onScreen
273 anchors {
274 fill: parent
275 topMargin: effect.bottomGapPx
276 }
277 onClicked: {
278 previewLoader.open = false;
279 }
280 }