Unity 8
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.4
18 import Ubuntu.Components 1.3
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 initialIndexPreviewStack: null
28  property var scope: null
29  property var scopeStyle: null
30  property string categoryId
31  property bool usedInitialIndex: false
32 
33  property alias showSignatureLine: header.showSignatureLine
34 
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
40 
41  readonly property bool processing: currentItem && (!currentItem.previewModel.loaded
42  || currentItem.previewModel.processingAction)
43 
44  signal backClicked()
45 
46  DashPageHeader {
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
54 
55  onBackClicked: root.backClicked()
56  }
57 
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
75 
76  property bool open: false
77 
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  }
88 
89  onModelChanged: {
90  if (count > 0 && initialIndex >= 0 && !usedInitialIndex) {
91  usedInitialIndex = true;
92  previewListView.positionViewAtIndex(initialIndex, ListView.SnapPosition);
93  }
94  }
95 
96  delegate: Previews.Preview {
97  id: preview
98  objectName: "preview" + index
99  height: previewListView.height
100  width: previewListView.width
101 
102  isCurrent: ListView.isCurrentItem
103 
104  readonly property var previewStack: {
105  if (root.open) {
106  if (index === root.initialIndex) {
107  return root.initialIndexPreviewStack;
108  } else {
109  return root.scope.preview(result, root.categoryId);
110  }
111  } else {
112  return null;
113  }
114  }
115 
116  previewModel: {
117  if (previewStack) {
118  return previewStack.getPreviewModel(0);
119  } else {
120  return null;
121  }
122  }
123 
124  scopeStyle: root.scopeStyle
125  }
126  }
127 
128  MouseArea {
129  id: processingMouseArea
130  objectName: "processingMouseArea"
131  anchors {
132  left: parent.left
133  right: parent.right
134  top: header.bottom
135  bottom: parent.bottom
136  }
137 
138  enabled: root.processing
139  }
140 }