Unity 8
PreviewZoomableImage.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.4
18 import Ubuntu.Components 1.3
19 import "../../Components"
20 
21 /*! \brief Preview widget for image.
22 
23  This widget shows image contained in widgetData["source"],
24  and falls back to widgetData["fallback"] if loading fails
25  can be zoomable accordingly with widgetData["zoomable"].
26  */
27 
28 PreviewWidget {
29  id: root
30  implicitWidth: units.gu(35)
31  implicitHeight: lazyImage.height
32 
33  singleColumnMarginless: true
34  orientationLock: overlay.visible
35 
36  property Item rootItem: QuickUtils.rootItem(root)
37 
38  readonly property var imageUrl: widgetData["source"] || widgetData["fallback"] || ""
39 
40  LazyImage {
41  id: lazyImage
42  objectName: "lazyImage"
43  anchors {
44  left: parent.left
45  right: parent.right
46  }
47  scaleTo: "width"
48  source: root.imageUrl
49  asynchronous: true
50  useUbuntuShape: false
51  pressed: mouseArea.pressed
52 
53  MouseArea {
54  id: mouseArea
55  anchors.fill: parent
56  onClicked: {
57  overlay.initialX = rootItem.mapFromItem(parent, 0, 0).x;
58  overlay.initialY = rootItem.mapFromItem(parent, 0, 0).y;
59  overlay.show();
60  }
61  }
62 
63  Connections {
64  target: lazyImage.sourceImage
65  onStatusChanged: if (lazyImage.sourceImage.status === Image.Error) lazyImage.sourceImage.source = widgetData["fallback"];
66  }
67  Connections {
68  target: root
69  onImageUrlChanged: lazyImage.sourceImage.source = root.imageUrl;
70  }
71 
72  PreviewMediaToolbar {
73  id: toolbar
74  anchors {
75  left: parent.left
76  right: parent.right
77  bottom: parent.bottom
78  }
79  shareData: widgetData["share-data"]
80  }
81  }
82 
83  PreviewOverlay {
84  id: overlay
85  objectName: "overlay"
86  parent: rootItem
87  anchors.fill: parent
88  initialWidth: lazyImage.width
89  initialHeight: lazyImage.height
90 
91  delegate: ZoomableImage {
92  anchors.fill: parent
93  source: root.imageUrl
94  zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
95  onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];
96 
97  Connections {
98  target: root
99  onImageUrlChanged: source = root.imageUrl;
100  }
101  }
102  }
103 }