21 import Ubuntu.Components 0.1
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 fillMode: image.fillMode
35 property alias asynchronous: image.asynchronous
36 property alias cache: image.cache
37 property alias horizontalAlignment: image.horizontalAlignment
38 property alias verticalAlignment: image.verticalAlignment
39 property alias sourceImage: image
44 if (state ===
"ready") {
46 image.nextSource = source;
48 image.source = source;
54 objectName:
"placeholder"
61 anchors.centerIn: parent
70 objectName:
"errorImage"
71 anchors.centerIn: parent
75 source:
"graphics/close.png"
76 sourceSize { width: units.gu(3); height: units.gu(3) }
83 height: root.initialHeight
84 width: root.initialWidth
85 anchors.centerIn: root.scaleTo ==
"fit" ? parent : undefined
94 property url nextSource
95 property string format: image.implicitWidth > image.implicitHeight ?
"landscape" :
"portrait"
97 fillMode: Image.PreserveAspectFit
100 horizontalAlignment: Image.AlignHCenter
101 verticalAlignment: Image.AlignVCenter
102 sourceSize.width: root.scaleTo ==
"width" ? root.width
103 : root.scaleTo ==
"fit" && root.width <= root.height ? root.width
105 sourceSize.height: root.scaleTo ==
"height" ? root.height
106 : root.scaleTo ==
"fit" && root.height <= root.width ? root.height
114 when: image.source ==
""
115 PropertyChanges { target: root; implicitWidth: root.initialWidth; implicitHeight: root.initialHeight }
116 PropertyChanges { target: errorImage; opacity: 0 }
121 when: image.status === Image.Loading
122 PropertyChanges { target: activity; opacity: 1 }
126 when: image.status === Image.Ready && image.source !=
""
127 PropertyChanges { target: root; implicitWidth: shape.width; implicitHeight: shape.height }
128 PropertyChanges { target: placeholder; opacity: 0 }
129 PropertyChanges { target: shape; opacity: 1
130 width: root.scaleTo ==
"width" || (root.scaleTo ==
"fit" && image.format ==
"landscape") ? root.width
131 : root.scaleTo ==
"" ? image.implicitWidth : image.implicitWidth * height / image.implicitHeight
132 height: root.scaleTo ==
"height" || (root.scaleTo ==
"fit" && image.format ==
"portrait") ? root.height
133 : root.scaleTo ==
"" ? image.implicitHeight : image.implicitHeight * width / image.implicitWidth
139 when: image.status === Image.Error
140 PropertyChanges { target: errorImage; opacity: 1.0 }
147 objectName:
"readyTransition"
148 SequentialAnimation {
149 PropertyAction { target: shape;
property:
"visible" }
151 NumberAnimation { target: shape;
property:
"opacity"; easing.type: Easing.Linear }
152 UbuntuNumberAnimation { target: root; properties:
"implicitWidth,implicitHeight" }
153 UbuntuNumberAnimation { target: shape; properties:
"width,height" }
155 targets: [placeholder, activity, errorImage];
property:
"opacity";
156 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
164 objectName:
"genericTransition"
165 SequentialAnimation {
167 NumberAnimation { target: shape;
property:
"opacity"; easing.type: Easing.Linear }
169 targets: [placeholder, activity, errorImage];
property:
"opacity";
170 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
172 UbuntuNumberAnimation { target: root; properties:
"implicitWidth,implicitHeight" }
173 UbuntuNumberAnimation { target: shape; properties:
"width,height" }
175 PropertyAction { target: shape;
property:
"visible" }
179 if (!running && state ===
"default" && image.nextSource !==
"") {
180 image.source = image.nextSource;
181 image.nextSource =
"";