Unity 8
 All Classes Functions Properties
PreviewListView.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import Unity 0.2
20 import "../Components"
21 import "Previews" as Previews
22 
23 Item {
24  id: root
25 
26  property var scope: null
27  property var scopeStyle: null
28 
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
34 
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
43 
44  onBackClicked: root.open = false
45  }
46 
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
64 
65  // To be set before opening the preview
66  property string categoryId: ""
67 
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
72 
73  property bool open: false
74 
75  onOpenChanged: {
76  if (!open) {
77  // Cancel any pending preview requests or actions
78  if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
79  previewListView.currentItem.previewData.cancelAction();
80  }
81  scope.cancelActivation();
82  model = undefined;
83  }
84  }
85 
86  delegate: Item {
87  objectName: "previewItem" + index
88  height: previewListView.height
89  width: previewListView.width
90 
91  readonly property bool ready: preview.previewModel.loaded
92 
93  Previews.Preview {
94  id: preview
95  objectName: "preview" + index
96  anchors.fill: parent
97 
98  isCurrent: parent.ListView.isCurrentItem
99 
100  previewModel: {
101  var previewStack = root.scope.preview(result);
102  return previewStack.getPreviewModel(0);
103  }
104  scopeStyle: root.scopeStyle
105  }
106 
107  MouseArea {
108  id: processingMouseArea
109  objectName: "processingMouseArea"
110  anchors.fill: parent
111  enabled: !preview.previewModel.loaded || preview.previewModel.processingAction
112 
113  ActivityIndicator {
114  anchors.centerIn: parent
115  visible: root.open && parent.enabled
116  running: visible
117  }
118  }
119  }
120  }
121 }