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 /*! \brief Preview widget for image.
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"].
30 implicitWidth: units.gu(35)
31 implicitHeight: lazyImage.height
33 widgetMargins: -units.gu(1)
35 property Item rootItem: QuickUtils.rootItem(root)
39 objectName: "lazyImage"
45 source: widgetData["source"]
48 pressed: mouseArea.pressed
54 overlay.initialX = rootItem.mapFromItem(parent, 0, 0).x;
55 overlay.initialY = rootItem.mapFromItem(parent, 0, 0).y;
61 target: lazyImage.sourceImage
62 // If modelData would change after failing to load it would not be
63 // reloaded since the source binding is destroyed by the source = fallback
64 // But at the moment the model never changes
65 onStatusChanged: if (lazyImage.sourceImage.status === Image.Error) lazyImage.sourceImage.source = widgetData["fallback"];
75 shareData: widgetData["shareData"]
84 initialWidth: lazyImage.width
85 initialHeight: lazyImage.height
87 delegate: ZoomableImage {
89 source: widgetData["source"]
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
91 // If modelData would change after failing to load it would not be
92 // reloaded since the source binding is destroyed by the source = fallback
93 // But at the moment the model never changes
94 onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];