on a67c059 help sign in
unity8/Dash/GenericScopeView.qml
220 lines 6.9 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 getRenderer(rendererId, contentType) {
118 switch (rendererId) {
119 case "grid": {
120 switch (contentType) {
121 case "video": return "Generic/GenericFilterGridPotrait.qml";
122 default: return "Generic/GenericFilterGrid.qml";
123 }
124 }
125 case "carousel": return "Generic/GenericCarousel.qml";
126 default: return "Generic/GenericFilterGrid.qml";
127 }
128 }
130 OpenEffect {
131 id: effect
132 anchors {
133 fill: parent
134 bottomMargin: -bottomOverflow
135 }
136 sourceItem: categoryView
138 enabled: gap > 0.0
140 topGapPx: (1 - gap) * positionPx
141 topOpacity: (1 - gap * 1.2)
142 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
143 bottomOverflow: units.gu(20)
144 bottomOpacity: 1 - (gap * 0.8)
146 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
147 property real gap: previewLoader.open ? 1.0 : 0.0
149 Behavior on gap {
150 NumberAnimation {
151 duration: 200
152 easing.type: Easing.InOutQuad
153 onRunningChanged: {
154 if (!previewLoader.open && !running) {
155 previewLoader.onScreen = false
156 }
157 }
158 }
159 }
160 }
162 Connections {
163 target: scopeView.scope
164 onPreviewReady: {
165 previewLoader.previewData = preview
166 previewLoader.open = true
167 }
168 }
170 PreviewDelegateMapper {
171 id: previewDelegateMapper
172 }
174 Connections {
175 ignoreUnknownSignals: true
176 target: previewLoader.valid ? previewLoader.item : null
177 onClose: {
178 previewLoader.open = false
179 }
180 }
182 Loader {
183 id: previewLoader
184 property var previewData
185 height: effect.bottomGapPx - effect.topGapPx
186 anchors {
187 top: parent.top
188 topMargin: effect.topGapPx
189 left: parent.left
190 right: parent.right
191 }
192 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
194 property bool open: false
195 property bool onScreen: false
196 property bool valid: item !== null
198 onOpenChanged: {
199 if (open) {
200 onScreen = true
201 }
202 }
204 onLoaded: {
205 item.previewData = previewLoader.previewData
206 }
207 }
209 // TODO: Move as InverseMouseArea to DashPreview
210 MouseArea {
211 enabled: previewLoader.onScreen
212 anchors {
213 fill: parent
214 topMargin: effect.bottomGapPx
215 }
216 onClicked: {
217 previewLoader.open = false;
218 }
219 }