on aec6c05 help sign in
unity8/Dash/GenericScopeView.qml
229 lines 7.2 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 Loader {
60 id: rendererLoader
61 anchors {
62 top: parent.top
63 left: parent.left
64 right: parent.right
65 }
67 source: getRenderer(model.renderer, model.contentType)
69 onLoaded: {
70 item.model = results
71 }
73 Connections {
74 target: rendererLoader.item
75 onClicked: {
76 effect.positionPx = mapToItem(categoryView, 0, itemY).y
77 scopeView.scope.activate(delegateItem.model.uri,
78 delegateItem.model.icon,
79 delegateItem.model.category,
80 0,
81 delegateItem.model.mimetype,
82 delegateItem.model.title,
83 delegateItem.model.comment,
84 delegateItem.model.dndUri,
85 delegateItem.model.metadata)
86 }
87 onPressAndHold: {
88 effect.positionPx = mapToItem(categoryView, 0, itemY).y
89 scopeView.scope.preview( 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 }
100 }
101 }
103 sectionProperty: "name"
104 sectionDelegate: ListItems.Header {
105 width: categoryView.width
106 text: section
107 }
108 pageHeader: PageHeader {
109 id: pageHeader
110 objectName: "pageHeader"
111 width: categoryView.width
112 text: scopeView.scope.name
113 searchEntryEnabled: true
114 }
115 }
117 function getDefaultRendererId(contentType) {
118 switch (contentType) {
119 default: return "grid";
120 }
121 }
123 function getRenderer(rendererId, contentType) {
124 if (rendererId == "default") {
125 rendererId = getDefaultRendererId(contentType);
126 }
127 switch (rendererId) {
128 case "grid": {
129 switch (contentType) {
130 case "video": return "Generic/GenericFilterGridPotrait.qml";
131 default: return "Generic/GenericFilterGrid.qml";
132 }
133 }
134 case "carousel": return "Generic/GenericCarousel.qml";
135 default: return "Generic/GenericFilterGrid.qml";
136 }
137 }
139 OpenEffect {
140 id: effect
141 anchors {
142 fill: parent
143 bottomMargin: -bottomOverflow
144 }
145 sourceItem: categoryView
147 enabled: gap > 0.0
149 topGapPx: (1 - gap) * positionPx
150 topOpacity: (1 - gap * 1.2)
151 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
152 bottomOverflow: units.gu(20)
153 bottomOpacity: 1 - (gap * 0.8)
155 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
156 property real gap: previewLoader.open ? 1.0 : 0.0
158 Behavior on gap {
159 NumberAnimation {
160 duration: 200
161 easing.type: Easing.InOutQuad
162 onRunningChanged: {
163 if (!previewLoader.open && !running) {
164 previewLoader.onScreen = false
165 }
166 }
167 }
168 }
169 }
171 Connections {
172 target: scopeView.scope
173 onPreviewReady: {
174 previewLoader.previewData = preview
175 previewLoader.open = true
176 }
177 }
179 PreviewDelegateMapper {
180 id: previewDelegateMapper
181 }
183 Connections {
184 ignoreUnknownSignals: true
185 target: previewLoader.valid ? previewLoader.item : null
186 onClose: {
187 previewLoader.open = false
188 }
189 }
191 Loader {
192 id: previewLoader
193 property var previewData
194 height: effect.bottomGapPx - effect.topGapPx
195 anchors {
196 top: parent.top
197 topMargin: effect.topGapPx
198 left: parent.left
199 right: parent.right
200 }
201 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
203 property bool open: false
204 property bool onScreen: false
205 property bool valid: item !== null
207 onOpenChanged: {
208 if (open) {
209 onScreen = true
210 }
211 }
213 onLoaded: {
214 item.previewData = previewLoader.previewData
215 }
216 }
218 // TODO: Move as InverseMouseArea to DashPreview
219 MouseArea {
220 enabled: previewLoader.onScreen
221 anchors {
222 fill: parent
223 topMargin: effect.bottomGapPx
224 }
225 onClicked: {
226 previewLoader.open = false;
227 }
228 }