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.1
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"].
27 implicitHeight: units.gu(22)
29 property Item rootItem: QuickUtils.rootItem(root)
32 id: previewImageListView
33 objectName: "previewImageListView"
36 orientation: ListView.Horizontal
37 cacheBuffer: width * 3
38 model: root.widgetData["sources"]
41 onCurrentIndexChanged: overlay.updateInitialItem()
44 objectName: "placeholderScreenshot"
50 source: "broken_image"
51 initialWidth: units.gu(13)
52 visible: previewImageListView.count == 0
56 objectName: "previewImage" + index
61 source: modelData ? modelData : ""
63 initialWidth: units.gu(13)
64 borderSource: mouseArea.pressed ? "radius_pressed.sci" : "radius_idle.sci"
70 previewImageListView.currentIndex = index;
71 overlay.updateInitialItem();
84 function updateInitialItem() {
85 initialX = rootItem.mapFromItem(previewImageListView.currentItem, 0, 0).x;
86 initialY = rootItem.mapFromItem(previewImageListView.currentItem, 0, 0).y;
87 initialWidth = previewImageListView.currentItem.width;
88 initialHeight = previewImageListView.currentItem.height;
93 objectName: "overlayListView"
95 orientation: ListView.Horizontal
96 highlightRangeMode: ListView.StrictlyEnforceRange
97 highlightMoveDuration: 0
98 snapMode: ListView.SnapOneItem
99 boundsBehavior: Flickable.DragAndOvershootBounds
100 model: root.widgetData["sources"]
101 currentIndex: previewImageListView.currentIndex
103 onCurrentIndexChanged: {
104 // if the index changed while overlay is visible, it was from user interaction,
105 // let's update the index of the original listview
106 if (overlay.visible) {
107 previewImageListView.highlightMoveDuration = 0;
108 previewImageListView.highlightResizeDuration = 0;
109 previewImageListView.currentIndex = currentIndex;
110 previewImageListView.highlightMoveDuration = -1;
111 previewImageListView.highlightResizeDuration = -1;
119 bottom: parent.bottom
122 source: modelData ? modelData : ""
123 fillMode: Image.PreserveAspectFit
124 sourceSize { width: screenshot.width; height: screenshot.height }
129 onClicked: overlay.headerShown = !overlay.headerShown