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 Scope scope: null
27  property var pageHeader: 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: root.objectName + "_pageHeader"
38  width: parent.width
39  searchEntryEnabled: false
40  scope: root.scope
41  height: units.gu(8.5)
42  showBackButton: true
43  onBackClicked: root.open = false
44 
45  childItem: Label {
46  id: label
47  anchors {
48  left: parent.left
49  right: parent.right
50  verticalCenter: parent.verticalCenter
51  }
52  text: scope ? i18n.tr("%1 Preview").arg(scope.name) : ""
53  // TODO Saviq: These should come from updated Ubuntu Palette.
54  color: "#888888"
55  font.family: "Ubuntu"
56  font.weight: Font.Light
57  fontSize: "x-large"
58  elide: Text.ElideRight
59  }
60  }
61 
62  ListView {
63  id: previewListView
64  objectName: root.objectName + "_listView"
65  anchors {
66  top: header.bottom
67  bottom: parent.bottom
68  left: parent.left
69  right: parent.right
70  }
71  orientation: ListView.Horizontal
72  highlightRangeMode: ListView.StrictlyEnforceRange
73  snapMode: ListView.SnapOneItem
74  boundsBehavior: Flickable.DragAndOvershootBounds
75  highlightMoveDuration: 250
76  flickDeceleration: units.gu(625)
77  maximumFlickVelocity: width * 5
78  cacheBuffer: 0
79 
80  // To be set before opening the preview
81  property string categoryId: ""
82 
83  // because the ListView is built asynchronous, setting the
84  // currentIndex directly won't work. We need to refresh it
85  // when the first preview is ready to be displayed.
86  property bool init: true
87 
88  property bool open: false
89 
90  onOpenChanged: {
91  if (open) {
92  pageHeader.unfocus();
93  } else {
94  // Cancel any pending preview requests or actions
95  if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
96  previewListView.currentItem.previewData.cancelAction();
97  }
98  scope.cancelActivation();
99  model = undefined;
100  }
101  }
102 
103  delegate: Item {
104  objectName: "previewItem" + index
105  height: previewListView.height
106  width: previewListView.width
107 
108  readonly property bool ready: preview.previewModel.loaded
109 
110  Previews.Preview {
111  id: preview
112  objectName: "preview" + index
113  anchors.fill: parent
114 
115  isCurrent: parent.ListView.isCurrentItem
116 
117  previewModel: {
118  var previewStack = root.scope.preview(result);
119  return previewStack.get(0);
120  }
121  }
122 
123  MouseArea {
124  id: processingMouseArea
125  objectName: "processingMouseArea"
126  anchors.fill: parent
127  enabled: !preview.previewModel.loaded || preview.previewModel.processingAction
128 
129  ActivityIndicator {
130  anchors.centerIn: parent
131  visible: root.open && parent.enabled
132  running: visible
133  }
134  }
135  }
136  }
137 }