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
43 if (state ===
"ready") {
45 image.nextSource = source;
47 image.source = source;
53 objectName:
"placeholder"
60 anchors.centerIn: parent
69 objectName:
"errorImage"
70 anchors.centerIn: parent
74 source:
"graphics/close.png"
75 sourceSize { width: units.gu(3); height: units.gu(3) }
82 height: root.initialHeight
83 width: root.initialWidth
84 anchors.centerIn: root.scaleTo ==
"fit" ? parent : undefined
93 property url nextSource
94 property string format: image.implicitWidth > image.implicitHeight ?
"landscape" :
"portrait"
96 fillMode: Image.PreserveAspectFit
99 horizontalAlignment: Image.AlignHCenter
100 verticalAlignment: Image.AlignVCenter
101 sourceSize.width: root.scaleTo ==
"width" ? root.width
102 : root.scaleTo ==
"fit" && root.width <= root.height ? root.width
104 sourceSize.height: root.scaleTo ==
"height" ? root.height
105 : root.scaleTo ==
"fit" && root.height <= root.width ? root.height
113 when: image.source ==
""
114 PropertyChanges { target: root; implicitWidth: root.initialWidth; implicitHeight: root.initialHeight }
115 PropertyChanges { target: errorImage; opacity: 0 }
120 when: image.status === Image.Loading
121 PropertyChanges { target: activity; opacity: 1 }
125 when: image.status === Image.Ready && image.source !=
""
126 PropertyChanges { target: root; implicitWidth: shape.width; implicitHeight: shape.height }
127 PropertyChanges { target: placeholder; opacity: 0 }
128 PropertyChanges { target: shape; opacity: 1
129 width: root.scaleTo ==
"width" || (root.scaleTo ==
"fit" && image.format ==
"landscape") ? root.width
130 : root.scaleTo ==
"" ? image.implicitWidth : image.implicitWidth * height / image.implicitHeight
131 height: root.scaleTo ==
"height" || (root.scaleTo ==
"fit" && image.format ==
"portrait") ? root.height
132 : root.scaleTo ==
"" ? image.implicitHeight : image.implicitHeight * width / image.implicitWidth
138 when: image.status === Image.Error
139 PropertyChanges { target: errorImage; opacity: 1.0 }
146 objectName:
"readyTransition"
147 SequentialAnimation {
148 PropertyAction { target: shape;
property:
"visible" }
150 NumberAnimation { target: shape;
property:
"opacity"; easing.type: Easing.Linear }
151 UbuntuNumberAnimation { target: root; properties:
"implicitWidth,implicitHeight" }
152 UbuntuNumberAnimation { target: shape; properties:
"width,height" }
154 targets: [placeholder, activity, errorImage];
property:
"opacity";
155 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
163 objectName:
"genericTransition"
164 SequentialAnimation {
166 NumberAnimation { target: shape;
property:
"opacity"; easing.type: Easing.Linear }
168 targets: [placeholder, activity, errorImage];
property:
"opacity";
169 easing.type: Easing.Linear; duration: UbuntuAnimation.SnapDuration
171 UbuntuNumberAnimation { target: root; properties:
"implicitWidth,implicitHeight" }
172 UbuntuNumberAnimation { target: shape; properties:
"width,height" }
174 PropertyAction { target: shape;
property:
"visible" }
178 if (!running && state ===
"default" && image.nextSource !==
"") {
179 image.source = image.nextSource;
180 image.nextSource =
"";