on a142f21 help sign in
unity8/qml/Dash/PreviewListView.qml
132 lines 4.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 Unity 0.2
20import "../Components"
21import "Previews" as Previews
23Item {
24 id: root
26 property int initialIndex: -1
27 property var initialIndexPreviewStack: null
28 property var scope: null
29 property var scopeStyle: null
30 property string categoryId
31 property bool usedInitialIndex: false
33 property alias showSignatureLine: header.showSignatureLine
35 property alias open: previewListView.open
36 property alias model: previewListView.model
37 property alias currentIndex: previewListView.currentIndex
38 property alias currentItem: previewListView.currentItem
39 property alias count: previewListView.count
41 readonly property bool processing: currentItem && (!currentItem.previewModel.loaded
42 || currentItem.previewModel.processingAction)
44 signal backClicked()
46 PageHeader {
47 id: header
48 objectName: "pageHeader"
49 width: parent.width
50 title: root.scope ? root.scope.name : ""
51 showBackButton: true
52 searchEntryEnabled: false
53 scopeStyle: root.scopeStyle
55 onBackClicked: root.backClicked()
56 }
58 ListView {
59 id: previewListView
60 objectName: "listView"
61 anchors {
62 top: header.bottom
63 bottom: parent.bottom
64 left: parent.left
65 right: parent.right
66 }
67 orientation: ListView.Horizontal
68 highlightRangeMode: ListView.StrictlyEnforceRange
69 snapMode: ListView.SnapOneItem
70 boundsBehavior: Flickable.DragAndOvershootBounds
71 highlightMoveDuration: 250
72 flickDeceleration: units.gu(625)
73 maximumFlickVelocity: width * 5
74 cacheBuffer: 0
76 property bool open: false
78 onOpenChanged: {
79 if (!open) {
80 // Cancel any pending preview requests or actions
81 if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
82 previewListView.currentItem.previewData.cancelAction();
83 }
84 root.scope.cancelActivation();
85 model = undefined;
86 }
87 }
89 onModelChanged: {
90 if (count > 0 && initialIndex >= 0 && !usedInitialIndex) {
91 usedInitialIndex = true;
92 previewListView.positionViewAtIndex(initialIndex, ListView.SnapPosition);
93 }
94 }
96 delegate: Previews.Preview {
97 id: preview
98 objectName: "preview" + index
99 height: previewListView.height
100 width: previewListView.width
102 isCurrent: ListView.isCurrentItem
104 previewModel: {
105 if (root.open) {
106 if (index === root.initialIndex) {
107 return root.initialIndexPreviewStack.getPreviewModel(0);
108 } else {
109 var previewStack = root.scope.preview(result, root.categoryId);
110 return previewStack.getPreviewModel(0);
111 }
112 } else {
113 return null;
114 }
115 }
116 scopeStyle: root.scopeStyle
117 }
118 }
120 MouseArea {
121 id: processingMouseArea
122 objectName: "processingMouseArea"
123 anchors {
124 left: parent.left
125 right: parent.right
126 top: header.bottom
127 bottom: parent.bottom
128 }
130 enabled: root.processing
131 }