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