Unity 8
PreviewImageGallery.qml
1 /*
2  * Copyright (C) 2014 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 1.1
19 import "../../Components"
20 
21 /*! This preview widget shows a horizontal list of images.
22  * The URIs for the images should be an array in widgetData["sources"].
23  */
24 
25 PreviewWidget {
26  id: root
27  implicitHeight: units.gu(22)
28 
29  property Item rootItem: QuickUtils.rootItem(root)
30 
31  ListView {
32  id: previewImageListView
33  objectName: "previewImageListView"
34  spacing: units.gu(1)
35  anchors.fill: parent
36  orientation: ListView.Horizontal
37  cacheBuffer: width * 3
38  model: root.widgetData["sources"]
39  clip: true
40 
41  LazyImage {
42  objectName: "placeholderScreenshot"
43  anchors {
44  top: parent.top
45  bottom: parent.bottom
46  }
47  scaleTo: "height"
48  source: "broken_image"
49  initialWidth: units.gu(13)
50  visible: previewImageListView.count == 0
51  }
52 
53  delegate: LazyImage {
54  objectName: "previewImage" + index
55  anchors {
56  top: parent.top
57  bottom: parent.bottom
58  }
59  source: modelData ? modelData : ""
60  scaleTo: "height"
61  initialWidth: units.gu(13)
62  borderSource: mouseArea.pressed ? "radius_pressed.sci" : "radius_idle.sci"
63 
64  MouseArea {
65  id: mouseArea
66  anchors.fill: parent
67  onClicked: {
68  overlay.delegateItem.currentIndex = index;
69  overlay.initialX = rootItem.mapFromItem(parent, 0, 0).x;
70  overlay.initialY = rootItem.mapFromItem(parent, 0, 0).y;
71  overlay.show();
72  }
73  }
74  }
75  }
76 
77  PreviewOverlay {
78  id: overlay
79  objectName: "overlay"
80  parent: rootItem
81  width: parent.width
82  height: parent.height
83  initialScale: previewImageListView.height / rootItem.height
84 
85  delegate: ListView {
86  id: overlayListView
87  objectName: "overlayListView"
88  anchors.fill: parent
89  orientation: ListView.Horizontal
90  highlightRangeMode: ListView.StrictlyEnforceRange
91  highlightMoveDuration: 0
92  snapMode: ListView.SnapOneItem
93  boundsBehavior: Flickable.DragAndOvershootBounds
94  model: root.widgetData["sources"]
95 
96  delegate: Image {
97  id: screenshot
98  anchors {
99  top: parent.top
100  bottom: parent.bottom
101  }
102  width: overlay.width
103  source: modelData ? modelData : ""
104  fillMode: Image.PreserveAspectFit
105  sourceSize { width: screenshot.width; height: screenshot.height }
106  }
107 
108  MouseArea {
109  anchors.fill: parent
110  onClicked: overlay.headerShown = !overlay.headerShown
111  }
112  }
113  }
114 }