on e72ae66 help sign in
unity8/Dash/GenericScopeView.qml
254 lines 8.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 if (item.expandable) {
77 item.filter = Qt.binding(function() { return index != categoryView.expandedIndex; });
78 }
79 }
81 Connections {
82 target: rendererLoader.item
83 onClicked: {
84 effect.positionPx = mapToItem(categoryView, 0, itemY).y
85 scopeView.scope.activate(delegateItem.model.uri,
86 delegateItem.model.icon,
87 delegateItem.model.category,
88 0,
89 delegateItem.model.mimetype,
90 delegateItem.model.title,
91 delegateItem.model.comment,
92 delegateItem.model.dndUri,
93 delegateItem.model.metadata)
94 }
95 onPressAndHold: {
96 effect.positionPx = mapToItem(categoryView, 0, itemY).y
97 scopeView.scope.preview( delegateItem.model.uri,
98 delegateItem.model.icon,
99 delegateItem.model.category,
100 0,
101 delegateItem.model.mimetype,
102 delegateItem.model.title,
103 delegateItem.model.comment,
104 delegateItem.model.dndUri,
105 delegateItem.model.metadata)
106 }
107 onFilterChanged: {
108 if (!target.filter) {
109 categoryView.maximizeVisibleArea(index);
110 }
111 }
112 }
113 }
114 }
116 sectionProperty: "name"
117 sectionDelegate: ListItems.Header {
118 property var delegate: categoryView.item(delegateIndex)
119 width: categoryView.width
120 text: section
121 image: {
122 if (delegate && delegate.expandable)
123 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
124 return "";
125 }
126 onClicked: {
127 if (categoryView.expandedIndex != delegateIndex)
128 categoryView.expandedIndex = delegateIndex;
129 else
130 categoryView.expandedIndex = -1;
131 }
132 }
133 pageHeader: PageHeader {
134 id: pageHeader
135 objectName: "pageHeader"
136 width: categoryView.width
137 text: scopeView.scope.name
138 searchEntryEnabled: true
139 }
140 }
142 function getDefaultRendererId(contentType) {
143 switch (contentType) {
144 default: return "grid";
145 }
146 }
148 function getRenderer(rendererId, contentType) {
149 if (rendererId == "default") {
150 rendererId = getDefaultRendererId(contentType);
151 }
152 switch (rendererId) {
153 case "grid": {
154 switch (contentType) {
155 case "video": return "Generic/GenericFilterGridPotrait.qml";
156 default: return "Generic/GenericFilterGrid.qml";
157 }
158 }
159 case "carousel": return "Generic/GenericCarousel.qml";
160 default: return "Generic/GenericFilterGrid.qml";
161 }
162 }
164 OpenEffect {
165 id: effect
166 anchors {
167 fill: parent
168 bottomMargin: -bottomOverflow
169 }
170 sourceItem: categoryView
172 enabled: gap > 0.0
174 topGapPx: (1 - gap) * positionPx
175 topOpacity: (1 - gap * 1.2)
176 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
177 bottomOverflow: units.gu(20)
178 bottomOpacity: 1 - (gap * 0.8)
180 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
181 property real gap: previewLoader.open ? 1.0 : 0.0
183 Behavior on gap {
184 NumberAnimation {
185 duration: 200
186 easing.type: Easing.InOutQuad
187 onRunningChanged: {
188 if (!previewLoader.open && !running) {
189 previewLoader.onScreen = false
190 }
191 }
192 }
193 }
194 }
196 Connections {
197 target: scopeView.scope
198 onPreviewReady: {
199 previewLoader.previewData = preview
200 previewLoader.open = true
201 }
202 }
204 PreviewDelegateMapper {
205 id: previewDelegateMapper
206 }
208 Connections {
209 ignoreUnknownSignals: true
210 target: previewLoader.valid ? previewLoader.item : null
211 onClose: {
212 previewLoader.open = false
213 }
214 }
216 Loader {
217 id: previewLoader
218 property var previewData
219 height: effect.bottomGapPx - effect.topGapPx
220 anchors {
221 top: parent.top
222 topMargin: effect.topGapPx
223 left: parent.left
224 right: parent.right
225 }
226 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
228 property bool open: false
229 property bool onScreen: false
230 property bool valid: item !== null
232 onOpenChanged: {
233 if (open) {
234 onScreen = true
235 }
236 }
238 onLoaded: {
239 item.previewData = previewLoader.previewData
240 }
241 }
243 // TODO: Move as InverseMouseArea to DashPreview
244 MouseArea {
245 enabled: previewLoader.onScreen
246 anchors {
247 fill: parent
248 topMargin: effect.bottomGapPx
249 }
250 onClicked: {
251 previewLoader.open = false;
252 }
253 }