Unity 8
 All Classes Functions
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 int initialIndex: -1
27  property var scope: null
28  property var scopeStyle: null
29 
30  property alias showSignatureLine: header.showSignatureLine
31 
32  property alias open: previewListView.open
33  property alias model: previewListView.model
34  property alias currentIndex: previewListView.currentIndex
35  property alias currentItem: previewListView.currentItem
36  property alias count: previewListView.count
37 
38  readonly property bool processing: currentItem && (!currentItem.previewModel.loaded
39  || currentItem.previewModel.processingAction)
40 
41  signal backClicked()
42 
43  PageHeader {
44  id: header
45  objectName: "pageHeader"
46  width: parent.width
47  title: root.scope ? root.scope.name : ""
48  showBackButton: true
49  searchEntryEnabled: false
50  scopeStyle: root.scopeStyle
51 
52  onBackClicked: root.backClicked()
53  }
54 
55  ListView {
56  id: previewListView
57  objectName: "listView"
58  anchors {
59  top: header.bottom
60  bottom: parent.bottom
61  left: parent.left
62  right: parent.right
63  }
64  orientation: ListView.Horizontal
65  highlightRangeMode: ListView.StrictlyEnforceRange
66  snapMode: ListView.SnapOneItem
67  boundsBehavior: Flickable.DragAndOvershootBounds
68  highlightMoveDuration: 250
69  flickDeceleration: units.gu(625)
70  maximumFlickVelocity: width * 5
71  cacheBuffer: 0
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  root.scope.cancelActivation();
82  model = undefined;
83  }
84  }
85 
86  onCountChanged: {
87  if (count > 0 && initialIndex >= 0) {
88  currentIndex = initialIndex;
89  initialIndex = -1;
90  }
91  }
92 
93  delegate: Previews.Preview {
94  id: preview
95  objectName: "preview" + index
96  height: previewListView.height
97  width: previewListView.width
98 
99  isCurrent: ListView.isCurrentItem
100 
101  previewModel: {
102  var previewStack = root.scope.preview(result);
103  return previewStack.getPreviewModel(0);
104  }
105  scopeStyle: root.scopeStyle
106  }
107  }
108 
109  MouseArea {
110  id: processingMouseArea
111  objectName: "processingMouseArea"
112  anchors {
113  left: parent.left
114  right: parent.right
115  top: header.bottom
116  bottom: parent.bottom
117  }
118 
119  enabled: root.processing
120  }
121 }