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 "../Components/Flickables" as Flickables
22 import "Previews" as Previews
23 
24 Item {
25  id: root
26 
27  property int initialIndex: -1
28  property var scope: null
29  property var scopeStyle: null
30 
31  property alias showSignatureLine: header.showSignatureLine
32 
33  property alias open: previewListView.open
34  property alias model: previewListView.model
35  property alias currentIndex: previewListView.currentIndex
36  property alias currentItem: previewListView.currentItem
37  property alias count: previewListView.count
38 
39  readonly property bool processing: currentItem && (!currentItem.previewModel.loaded
40  || currentItem.previewModel.processingAction)
41 
42  signal backClicked()
43 
44  PageHeader {
45  id: header
46  objectName: "pageHeader"
47  width: parent.width
48  title: root.scope ? root.scope.name : ""
49  showBackButton: true
50  searchEntryEnabled: false
51  scopeStyle: root.scopeStyle
52 
53  onBackClicked: root.backClicked()
54  }
55 
56  Flickables.ListView {
57  id: previewListView
58  objectName: "listView"
59  anchors {
60  top: header.bottom
61  bottom: parent.bottom
62  left: parent.left
63  right: parent.right
64  }
65  orientation: ListView.Horizontal
66  highlightRangeMode: ListView.StrictlyEnforceRange
67  snapMode: ListView.SnapOneItem
68  boundsBehavior: Flickable.DragAndOvershootBounds
69  highlightMoveDuration: 250
70  cacheBuffer: 0
71 
72  property bool open: false
73 
74  onOpenChanged: {
75  if (!open) {
76  // Cancel any pending preview requests or actions
77  if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
78  previewListView.currentItem.previewData.cancelAction();
79  }
80  root.scope.cancelActivation();
81  model = undefined;
82  }
83  }
84 
85  onCountChanged: {
86  if (count > 0 && initialIndex >= 0) {
87  currentIndex = initialIndex;
88  initialIndex = -1;
89  }
90  }
91 
92  delegate: Previews.Preview {
93  id: preview
94  objectName: "preview" + index
95  height: previewListView.height
96  width: previewListView.width
97 
98  isCurrent: 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 
108  MouseArea {
109  id: processingMouseArea
110  objectName: "processingMouseArea"
111  anchors {
112  left: parent.left
113  right: parent.right
114  top: header.bottom
115  bottom: parent.bottom
116  }
117 
118  enabled: root.processing
119  }
120 }