on a3e77fa help sign in
unity8/Dash/GenericScopeView.qml
244 lines 7.7 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 delegate: ListItems.Base {
57 highlightWhenPressed: false
59 function headerClicked() {
60 if (rendererLoader.item.expandable) {
61 rendererLoader.item.filter = !rendererLoader.item.filter;
62 }
63 }
65 Loader {
66 id: rendererLoader
67 anchors {
68 top: parent.top
69 left: parent.left
70 right: parent.right
71 }
73 source: getRenderer(model.renderer, model.contentType)
75 onLoaded: {
76 item.model = results
77 }
79 Connections {
80 target: rendererLoader.item
81 onClicked: {
82 effect.positionPx = mapToItem(categoryView, 0, itemY).y
83 scopeView.scope.activate(delegateItem.model.uri,
84 delegateItem.model.icon,
85 delegateItem.model.category,
86 0,
87 delegateItem.model.mimetype,
88 delegateItem.model.title,
89 delegateItem.model.comment,
90 delegateItem.model.dndUri,
91 delegateItem.model.metadata)
92 }
93 onPressAndHold: {
94 effect.positionPx = mapToItem(categoryView, 0, itemY).y
95 scopeView.scope.preview( 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 onFilterChanged: {
106 if (!target.filter)
107 categoryView.maximizeVisibleArea(index);
108 }
109 }
110 }
111 }
113 sectionProperty: "name"
114 sectionDelegate: ListItems.Header {
115 width: categoryView.width
116 text: section
117 onClicked: {
118 var obj = categoryView.item(delegateIndex);
119 if (obj)
120 obj.headerClicked();
121 }
122 }
123 pageHeader: PageHeader {
124 id: pageHeader
125 objectName: "pageHeader"
126 width: categoryView.width
127 text: scopeView.scope.name
128 searchEntryEnabled: true
129 }
130 }
132 function getDefaultRendererId(contentType) {
133 switch (contentType) {
134 default: return "grid";
135 }
136 }
138 function getRenderer(rendererId, contentType) {
139 if (rendererId == "default") {
140 rendererId = getDefaultRendererId(contentType);
141 }
142 switch (rendererId) {
143 case "grid": {
144 switch (contentType) {
145 case "video": return "Generic/GenericFilterGridPotrait.qml";
146 default: return "Generic/GenericFilterGrid.qml";
147 }
148 }
149 case "carousel": return "Generic/GenericCarousel.qml";
150 default: return "Generic/GenericFilterGrid.qml";
151 }
152 }
154 OpenEffect {
155 id: effect
156 anchors {
157 fill: parent
158 bottomMargin: -bottomOverflow
159 }
160 sourceItem: categoryView
162 enabled: gap > 0.0
164 topGapPx: (1 - gap) * positionPx
165 topOpacity: (1 - gap * 1.2)
166 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
167 bottomOverflow: units.gu(20)
168 bottomOpacity: 1 - (gap * 0.8)
170 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
171 property real gap: previewLoader.open ? 1.0 : 0.0
173 Behavior on gap {
174 NumberAnimation {
175 duration: 200
176 easing.type: Easing.InOutQuad
177 onRunningChanged: {
178 if (!previewLoader.open && !running) {
179 previewLoader.onScreen = false
180 }
181 }
182 }
183 }
184 }
186 Connections {
187 target: scopeView.scope
188 onPreviewReady: {
189 previewLoader.previewData = preview
190 previewLoader.open = true
191 }
192 }
194 PreviewDelegateMapper {
195 id: previewDelegateMapper
196 }
198 Connections {
199 ignoreUnknownSignals: true
200 target: previewLoader.valid ? previewLoader.item : null
201 onClose: {
202 previewLoader.open = false
203 }
204 }
206 Loader {
207 id: previewLoader
208 property var previewData
209 height: effect.bottomGapPx - effect.topGapPx
210 anchors {
211 top: parent.top
212 topMargin: effect.topGapPx
213 left: parent.left
214 right: parent.right
215 }
216 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
218 property bool open: false
219 property bool onScreen: false
220 property bool valid: item !== null
222 onOpenChanged: {
223 if (open) {
224 onScreen = true
225 }
226 }
228 onLoaded: {
229 item.previewData = previewLoader.previewData
230 }
231 }
233 // TODO: Move as InverseMouseArea to DashPreview
234 MouseArea {
235 enabled: previewLoader.onScreen
236 anchors {
237 fill: parent
238 topMargin: effect.bottomGapPx
239 }
240 onClicked: {
241 previewLoader.open = false;
242 }
243 }