on 3ebd182 help sign in
unity8/Dash/GenericScopeView.qml
256 lines 8.4 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 property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
62 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) {
123 if (delegate.expandable)
124 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
125 }
126 return "";
127 }
128 onClicked: {
129 if (categoryView.expandedIndex != delegateIndex)
130 categoryView.expandedIndex = delegateIndex;
131 else
132 categoryView.expandedIndex = -1;
133 }
134 }
135 pageHeader: PageHeader {
136 id: pageHeader
137 objectName: "pageHeader"
138 width: categoryView.width
139 text: scopeView.scope.name
140 searchEntryEnabled: true
141 }
142 }
144 function getDefaultRendererId(contentType) {
145 switch (contentType) {
146 default: return "grid";
147 }
148 }
150 function getRenderer(rendererId, contentType) {
151 if (rendererId == "default") {
152 rendererId = getDefaultRendererId(contentType);
153 }
154 switch (rendererId) {
155 case "grid": {
156 switch (contentType) {
157 case "video": return "Generic/GenericFilterGridPotrait.qml";
158 default: return "Generic/GenericFilterGrid.qml";
159 }
160 }
161 case "carousel": return "Generic/GenericCarousel.qml";
162 default: return "Generic/GenericFilterGrid.qml";
163 }
164 }
166 OpenEffect {
167 id: effect
168 anchors {
169 fill: parent
170 bottomMargin: -bottomOverflow
171 }
172 sourceItem: categoryView
174 enabled: gap > 0.0
176 topGapPx: (1 - gap) * positionPx
177 topOpacity: (1 - gap * 1.2)
178 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
179 bottomOverflow: units.gu(20)
180 bottomOpacity: 1 - (gap * 0.8)
182 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
183 property real gap: previewLoader.open ? 1.0 : 0.0
185 Behavior on gap {
186 NumberAnimation {
187 duration: 200
188 easing.type: Easing.InOutQuad
189 onRunningChanged: {
190 if (!previewLoader.open && !running) {
191 previewLoader.onScreen = false
192 }
193 }
194 }
195 }
196 }
198 Connections {
199 target: scopeView.scope
200 onPreviewReady: {
201 previewLoader.previewData = preview
202 previewLoader.open = true
203 }
204 }
206 PreviewDelegateMapper {
207 id: previewDelegateMapper
208 }
210 Connections {
211 ignoreUnknownSignals: true
212 target: previewLoader.valid ? previewLoader.item : null
213 onClose: {
214 previewLoader.open = false
215 }
216 }
218 Loader {
219 id: previewLoader
220 property var previewData
221 height: effect.bottomGapPx - effect.topGapPx
222 anchors {
223 top: parent.top
224 topMargin: effect.topGapPx
225 left: parent.left
226 right: parent.right
227 }
228 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
230 property bool open: false
231 property bool onScreen: false
232 property bool valid: item !== null
234 onOpenChanged: {
235 if (open) {
236 onScreen = true
237 }
238 }
240 onLoaded: {
241 item.previewData = previewLoader.previewData
242 }
243 }
245 // TODO: Move as InverseMouseArea to DashPreview
246 MouseArea {
247 enabled: previewLoader.onScreen
248 anchors {
249 fill: parent
250 topMargin: effect.bottomGapPx
251 }
252 onClicked: {
253 previewLoader.open = false;
254 }
255 }