on 4e77f91 help sign in
unity8/qml/Dash/PreviewListView.qml
123 lines 3.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 Unity 0.2
20import "../Components"
21import "Previews" as Previews
23Item {
24 id: root
26 property var scope: null
27 property var scopeStyle: null
29 property alias open: previewListView.open
30 property alias model: previewListView.model
31 property alias currentIndex: previewListView.currentIndex
32 property alias currentItem: previewListView.currentItem
33 property alias count: previewListView.count
35 PageHeader {
36 id: header
37 objectName: "pageHeader"
38 width: parent.width
39 title: scope ? scope.name : ""
40 showBackButton: true
41 searchEntryEnabled: false
42 scopeStyle: root.scopeStyle
44 onBackClicked: root.open = false
45 }
47 ListView {
48 id: previewListView
49 objectName: "listView"
50 anchors {
51 top: header.bottom
52 bottom: parent.bottom
53 left: parent.left
54 right: parent.right
55 }
56 orientation: ListView.Horizontal
57 highlightRangeMode: ListView.StrictlyEnforceRange
58 snapMode: ListView.SnapOneItem
59 boundsBehavior: Flickable.DragAndOvershootBounds
60 highlightMoveDuration: 250
61 flickDeceleration: units.gu(625)
62 maximumFlickVelocity: width * 5
63 cacheBuffer: 0
65 // To be set before opening the preview
66 property string categoryId: ""
68 // because the ListView is built asynchronous, setting the
69 // currentIndex directly won't work. We need to refresh it
70 // when the first preview is ready to be displayed.
71 property bool init: true
73 property bool open: false
75 onOpenChanged: {
76 if (open) {
77 pageHeader.unfocus();
78 } else {
79 // Cancel any pending preview requests or actions
80 if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
81 previewListView.currentItem.previewData.cancelAction();
82 }
83 scope.cancelActivation();
84 model = undefined;
85 }
86 }
88 delegate: Item {
89 objectName: "previewItem" + index
90 height: previewListView.height
91 width: previewListView.width
93 readonly property bool ready: preview.previewModel.loaded
95 Previews.Preview {
96 id: preview
97 objectName: "preview" + index
98 anchors.fill: parent
100 isCurrent: parent.ListView.isCurrentItem
102 previewModel: {
103 var previewStack = root.scope.preview(result);
104 return previewStack.getPreviewModel(0);
105 }
106 scopeStyle: root.scopeStyle
107 }
109 MouseArea {
110 id: processingMouseArea
111 objectName: "processingMouseArea"
112 anchors.fill: parent
113 enabled: !preview.previewModel.loaded || preview.previewModel.processingAction
115 ActivityIndicator {
116 anchors.centerIn: parent
117 visible: root.open && parent.enabled
118 running: visible
119 }
120 }
121 }
122 }