2
* Copyright (C) 2013-2016 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)
32
property real lastScaledDimension: scaleTo == "height" || scaleTo == "fit" ? width : height
34
property alias sourceSize: image.sourceSize
35
property alias asynchronous: image.asynchronous
36
property alias cache: image.cache
37
property alias sourceImage: image
39
property bool useUbuntuShape: true
40
property bool pressed: false
45
if (state === "ready") {
47
image.nextSource = source;
49
image.source = source;
55
objectName: "placeholder"
57
active: useUbuntuShape
59
sourceComponent: UbuntuShape {
60
backgroundColor: "#22FFFFFF"
65
anchors.centerIn: parent
74
objectName: "errorImage"
75
anchors.centerIn: parent
79
source: "graphics/close.png"
80
sourceSize { width: units.gu(3); height: units.gu(3) }
87
height: root.initialHeight
88
width: root.initialWidth
89
anchors.centerIn: root.scaleTo == "fit" ? parent : undefined
90
active: useUbuntuShape
93
sourceComponent: UbuntuShapeOverlay {
94
property bool pressed: false
95
overlayColor: Qt.rgba(0, 0, 0, pressed ? 0.1 : 0)
96
overlayRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
100
item.pressed = Qt.binding(function() { return root.pressed; });
107
property url nextSource
108
property string format: image.implicitWidth > image.implicitHeight ? "landscape" : "portrait"
111
visible: !useUbuntuShape
112
fillMode: Image.PreserveAspectFit
115
sourceSize.width: root.scaleTo == "width" ? root.width
116
: root.scaleTo == "fit" && root.width <= root.height ? root.width
118
sourceSize.height: root.scaleTo == "height" ? root.height
119
: root.scaleTo == "fit" && root.height <= root.width ? root.height
127
when: image.source == ""
128
PropertyChanges { target: root; implicitWidth: root.initialWidth; implicitHeight: root.initialHeight }
129
PropertyChanges { target: errorImage; opacity: 0 }
134
when: image.status === Image.Loading
135
PropertyChanges { target: activity; opacity: 1 }
139
when: image.status === Image.Ready && image.source != ""
140
PropertyChanges { target: root; implicitWidth: shape.width; implicitHeight: shape.height }
141
PropertyChanges { target: placeholder; opacity: 0 }
142
PropertyChanges { target: shape; opacity: 1
143
width: root.scaleTo == "width" || (root.scaleTo == "fit" && image.format == "landscape") ? root.width
144
: root.scaleTo == "" ? image.implicitWidth : image.implicitWidth * height / image.implicitHeight
145
height: root.scaleTo == "height" || (root.scaleTo == "fit" && image.format == "portrait") ? root.height
146
: root.scaleTo == "" ? image.implicitHeight : image.implicitHeight * width / image.implicitWidth
152
when: image.status === Image.Error
153
PropertyChanges { target: errorImage; opacity: 1.0 }
160
objectName: "readyTransition"
161
SequentialAnimation {
162
PropertyAction { target: shape; property: "visible" }
164
NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
165
UbuntuNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
166
UbuntuNumberAnimation { target: shape; properties: "width,height" }
168
targets: [placeholder, activity, errorImage]; property: "opacity";
169
easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
172
ScriptAction { script: { lastScaledDimension = scaleTo == "height" || scaleTo == "fit" ? root.width : root.height } }
178
objectName: "genericTransition"
179
SequentialAnimation {
181
NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
183
targets: [placeholder, activity, errorImage]; property: "opacity";
184
easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
186
UbuntuNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
187
UbuntuNumberAnimation { target: shape; properties: "width,height" }
189
PropertyAction { target: shape; property: "visible" }
193
if (!running && state === "default" && image.nextSource !== "") {
194
image.source = image.nextSource;
195
image.nextSource = "";