2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import "../../Components"
21 /*! This preview widget shows a horizontal list of images.
22 * The URIs for the images should be an array in widgetData["sources"].
23 * Images fall back to widgetData["fallback"] if loading fails
28 implicitHeight: units.gu(22)
30 property Item rootItem: QuickUtils.rootItem(root)
33 id: previewImageListView
34 objectName: "previewImageListView"
37 orientation: ListView.Horizontal
38 cacheBuffer: width * 3
39 model: root.widgetData["sources"]
41 highlightMoveDuration: 0 // QTBUG-53460
43 onCurrentIndexChanged: overlay.updateInitialItem()
46 objectName: "placeholderScreenshot"
52 source: "broken_image"
53 initialWidth: units.gu(13)
54 visible: previewImageListView.count == 0
58 objectName: "previewImage" + index
63 source: modelData || root.widgetData["fallback"] || ""
65 initialWidth: units.gu(13)
66 pressed: mouseArea.pressed
72 previewImageListView.currentIndex = index;
73 overlay.updateInitialItem();
80 // If modelData would change after failing to load it would not be
81 // reloaded since the source binding is destroyed by the source = fallback
82 // But at the moment the model never changes
83 onStatusChanged: if (sourceImage.status === Image.Error) sourceImage.source = widgetData["fallback"];
94 function updateInitialItem() {
95 initialX = rootItem.mapFromItem(previewImageListView.currentItem, 0, 0).x;
96 initialY = rootItem.mapFromItem(previewImageListView.currentItem, 0, 0).y;
97 initialWidth = previewImageListView.currentItem.width;
98 initialHeight = previewImageListView.currentItem.height;
103 objectName: "overlayListView"
105 orientation: ListView.Horizontal
106 highlightRangeMode: ListView.StrictlyEnforceRange
107 highlightMoveDuration: 0
108 snapMode: ListView.SnapOneItem
109 boundsBehavior: Flickable.DragAndOvershootBounds
110 model: root.widgetData["sources"]
111 currentIndex: previewImageListView.currentIndex
113 onCurrentIndexChanged: {
114 // if the index changed while overlay is visible, it was from user interaction,
115 // let's update the index of the original listview
116 if (overlay.visible) {
117 previewImageListView.highlightMoveDuration = 0;
118 previewImageListView.highlightResizeDuration = 0;
119 previewImageListView.currentIndex = currentIndex;
120 previewImageListView.highlightMoveDuration = -1;
121 previewImageListView.highlightResizeDuration = -1;
129 bottom: parent.bottom
132 source: modelData || root.widgetData["fallback"] || ""
133 fillMode: Image.PreserveAspectFit
134 sourceSize { width: screenshot.width; height: screenshot.height }
136 // If modelData would change after failing to load it would not be
137 // reloaded since the source binding is destroyed by the source = fallback
138 // But at the moment the model never changes
139 onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];
144 onClicked: overlay.headerShown = !overlay.headerShown