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/>.
21import Lomiri.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 useLomiriShape: true
40 property bool pressed: false
45 if (state === "ready") {
47 image.nextSource = source;
49 image.source = source;
55 objectName: "placeholder"
57 active: useLomiriShape
59 sourceComponent: LomiriShape {
60 aspect: LomiriShape.Flat
61 backgroundColor: "#22FFFFFF"
66 anchors.centerIn: parent
75 objectName: "errorImage"
76 anchors.centerIn: parent
80 source: "graphics/close.png"
81 sourceSize { width: units.gu(3); height: units.gu(3) }
88 height: root.initialHeight
89 width: root.initialWidth
90 anchors.centerIn: root.scaleTo == "fit" ? parent : undefined
91 active: useLomiriShape
94 sourceComponent: LomiriShapeOverlay {
95 property bool pressed: false
96 aspect: LomiriShape.Flat
97 overlayColor: Qt.rgba(0, 0, 0, pressed ? 0.1 : 0)
98 overlayRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
102 item.pressed = Qt.binding(function() { return root.pressed; });
109 property url nextSource
110 property string format: image.implicitWidth > image.implicitHeight ? "landscape" : "portrait"
113 visible: !useLomiriShape
114 fillMode: Image.PreserveAspectFit
117 sourceSize.width: root.scaleTo == "width" ? root.width
118 : root.scaleTo == "fit" && root.width <= root.height ? root.width
120 sourceSize.height: root.scaleTo == "height" ? root.height
121 : root.scaleTo == "fit" && root.height <= root.width ? root.height
129 when: image.source == ""
130 PropertyChanges { target: root; implicitWidth: root.initialWidth; implicitHeight: root.initialHeight }
131 PropertyChanges { target: errorImage; opacity: 0 }
136 when: image.status === Image.Loading
137 PropertyChanges { target: activity; opacity: 1 }
141 when: image.status === Image.Ready && image.source != ""
142 PropertyChanges { target: root; implicitWidth: shape.width; implicitHeight: shape.height }
143 PropertyChanges { target: placeholder; opacity: 0 }
144 PropertyChanges { target: shape; opacity: 1
145 width: root.scaleTo == "width" || (root.scaleTo == "fit" && image.format == "landscape") ? root.width
146 : root.scaleTo == "" ? image.implicitWidth : image.implicitWidth * height / image.implicitHeight
147 height: root.scaleTo == "height" || (root.scaleTo == "fit" && image.format == "portrait") ? root.height
148 : root.scaleTo == "" ? image.implicitHeight : image.implicitHeight * width / image.implicitWidth
154 when: image.status === Image.Error
155 PropertyChanges { target: errorImage; opacity: 1.0 }
162 objectName: "readyTransition"
163 SequentialAnimation {
164 PropertyAction { target: shape; property: "visible" }
166 NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
167 LomiriNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
168 LomiriNumberAnimation { target: shape; properties: "width,height" }
170 targets: [placeholder, activity, errorImage]; property: "opacity";
171 easing.type: Easing.Linear; duration: LomiriAnimation.SnapDuration
174 ScriptAction { script: { lastScaledDimension = scaleTo == "height" || scaleTo == "fit" ? root.width : root.height } }
180 objectName: "genericTransition"
181 SequentialAnimation {
183 NumberAnimation { target: shape; property: "opacity"; easing.type: Easing.Linear }
185 targets: [placeholder, activity, errorImage]; property: "opacity";
186 easing.type: Easing.Linear; duration: LomiriAnimation.SnapDuration
188 LomiriNumberAnimation { target: root; properties: "implicitWidth,implicitHeight" }
189 LomiriNumberAnimation { target: shape; properties: "width,height" }
191 PropertyAction { target: shape; property: "visible" }
195 if (!running && state === "default" && image.nextSource !== "") {
196 image.source = image.nextSource;
197 image.nextSource = "";