on b43eafa help sign in
unity8/Dash/GenericScopeView.qml
215 lines 6.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 delegate: ListItems.Base {
57 highlightWhenPressed: false
59 FilterGrid {
60 id: filtergrid
61 model: results
63 anchors {
64 top: parent.top
65 left: parent.left
66 right: parent.right
67 }
69 filter: false
70 minimumHorizontalSpacing: units.gu(0.5)
71 delegateWidth: units.gu(11)
72 delegateHeight: units.gu(18)
73 verticalSpacing: units.gu(2)
75 delegate: Tile {
76 width: filtergrid.cellWidth
77 height: filtergrid.cellHeight
78 text: title
79 imageWidth: units.gu(11)
80 imageHeight: units.gu(16)
82 source: IconUtil.from_gicon(icon)
84 MouseArea {
85 anchors {
86 fill: parent
87 }
88 onClicked: {
89 mouse.accepted = true
90 effect.positionPx = mapToItem(categoryView, 0, 0).y
91 scopeView.scope.activate(uri, icon,
92 category, 0,
93 mimetype, title,
94 comment, dndUri,
95 metadata)
96 }
97 onPressAndHold: {
98 mouse.accepted = true
99 effect.positionPx = mapToItem(categoryView, 0, 0).y
100 scopeView.scope.preview(uri, icon,
101 category, 0,
102 mimetype, title,
103 comment, dndUri,
104 metadata)
105 }
106 }
107 }
108 }
109 }
111 sectionProperty: "name"
112 sectionDelegate: ListItems.Header {
113 width: categoryView.width
114 text: section
115 }
116 pageHeader: PageHeader {
117 id: pageHeader
118 objectName: "pageHeader"
119 width: categoryView.width
120 text: scopeView.scope.name
121 searchEntryEnabled: true
122 }
123 }
125 OpenEffect {
126 id: effect
127 anchors {
128 fill: parent
129 bottomMargin: -bottomOverflow
130 }
131 sourceItem: categoryView
133 enabled: gap > 0.0
135 topGapPx: (1 - gap) * positionPx
136 topOpacity: (1 - gap * 1.2)
137 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
138 bottomOverflow: units.gu(20)
139 bottomOpacity: 1 - (gap * 0.8)
141 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
142 property real gap: previewLoader.open ? 1.0 : 0.0
144 Behavior on gap {
145 NumberAnimation {
146 duration: 200
147 easing.type: Easing.InOutQuad
148 onRunningChanged: {
149 if (!previewLoader.open && !running) {
150 previewLoader.onScreen = false
151 }
152 }
153 }
154 }
155 }
157 Connections {
158 target: scopeView.scope
159 onPreviewReady: {
160 previewLoader.previewData = preview
161 previewLoader.open = true
162 }
163 }
165 PreviewDelegateMapper {
166 id: previewDelegateMapper
167 }
169 Connections {
170 ignoreUnknownSignals: true
171 target: previewLoader.valid ? previewLoader.item : null
172 onClose: {
173 previewLoader.open = false
174 }
175 }
177 Loader {
178 id: previewLoader
179 property var previewData
180 height: effect.bottomGapPx - effect.topGapPx
181 anchors {
182 top: parent.top
183 topMargin: effect.topGapPx
184 left: parent.left
185 right: parent.right
186 }
187 source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
189 property bool open: false
190 property bool onScreen: false
191 property bool valid: item !== null
193 onOpenChanged: {
194 if (open) {
195 onScreen = true
196 }
197 }
199 onLoaded: {
200 item.previewData = previewLoader.previewData
201 }
202 }
204 // TODO: Move as InverseMouseArea to DashPreview
205 MouseArea {
206 enabled: previewLoader.onScreen
207 anchors {
208 fill: parent
209 topMargin: effect.bottomGapPx
210 }
211 onClicked: {
212 previewLoader.open = false;
213 }
214 }