2 * Copyright (C) 2013 Canonical, Ltd.
5 * MichaĆ Sawicz <michal.sawicz@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import Ubuntu.Components 1.3
27 // TODO convert into enums when available in QML
28 property string scaleTo
30 property real initialWidth: scaleTo == "width" || scaleTo == "fit" ? width : units.gu(10)
31 property real initialHeight: scaleTo == "height" || scaleTo == "fit" ? height : units.gu(10)
33 property alias sourceSize: image.sourceSize
34 property alias asynchronous: image.asynchronous
35 property alias cache: image.cache
36 property alias sourceImage: image
38 property bool useUbuntuShape: true
39 property bool pressed: false
44 if (state === "ready") {
46 image.nextSource = source;
48 image.source = source;
54 objectName: "placeholder"
56 active: useUbuntuShape
58 sourceComponent: UbuntuShape {
59 backgroundColor: "#22FFFFFF"
64 anchors.centerIn: parent
73 objectName: "errorImage"
74 anchors.centerIn: parent
78 source: "graphics/close.png"
79 sourceSize { width: units.gu(3); height: units.gu(3) }
86 height: root.initialHeight
87 width: root.initialWidth
88 anchors.centerIn: root.scaleTo == "fit" ? parent : undefined
89 active: useUbuntuShape
92 sourceComponent: UbuntuShapeOverlay {
93 property bool pressed: false
94 overlayColor: Qt.rgba(0, 0, 0, pressed ? 0.1 : 0)
95 overlayRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
99 item.pressed = Qt.binding(function() { return root.pressed; });
106 property url nextSource
107 property string format: image.implicitWidth > image.implicitHeight ? "landscape" : "portrait"
110 visible: !useUbuntuShape
111 fillMode: Image.PreserveAspectFit
114 sourceSize.width: root.scaleTo == "width" ? root.width
115 : root.scaleTo == "fit" && root.width <= root.height ? root.width
117 sourceSize.height: root.scaleTo == "height" ? root.height
118 : root.scaleTo == "fit" && root.height <= root.width ? root.height
126 when: image.source == ""
127 PropertyChanges { target: root; implicitWidth: root.initialWidth; implicitHeight: root.initialHeight }
128 PropertyChanges { target: errorImage; opacity: 0 }
133 when: image.status === Image.Loading
134 PropertyChanges { target: activity; opacity: 1 }
138 when: image.status === Image.Ready && image.source != ""
139 PropertyChanges { target: root; implicitWidth: shape.width; implicitHeight: shape.height }
140 PropertyChanges { target: placeholder; opacity: 0 }
141 PropertyChanges { target: shape; opacity: 1
142 width: root.scaleTo == "width" || (root.scaleTo == "fit" && image.format == "landscape") ? root.width
143 : root.scaleTo == "" ? image.implicitWidth : image.implicitWidth * height / image.implicitHeight
144 height: root.scaleTo == "height" || (root.scaleTo == "fit" && image.format == "portrait") ? root.height
145 : root.scaleTo == "" ? image.implicitHeight : image.implicitHeight * width / image.implicitWidth
151 when: image.status === Image.Error
152 PropertyChanges { target: errorImage; opacity: 1.0 }
159 objectName: "readyTransition"
160 SequentialAnimation {
161 PropertyAction { target: shape; property: "visible" }
163 NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
164 UbuntuNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
165 UbuntuNumberAnimation { target: shape; properties: "width,height" }
167 targets: [placeholder, activity, errorImage]; property: "opacity";
168 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
176 objectName: "genericTransition"
177 SequentialAnimation {
179 NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
181 targets: [placeholder, activity, errorImage]; property: "opacity";
182 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
184 UbuntuNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
185 UbuntuNumberAnimation { target: shape; properties: "width,height" }
187 PropertyAction { target: shape; property: "visible" }
191 if (!running && state === "default" && image.nextSource !== "") {
192 image.source = image.nextSource;
193 image.nextSource = "";