@@ -28,14 +28,115 @@ PreviewWidget {
29 implicitHeight: units.gu(22)
29 implicitHeight: units.gu(22)
31− LazyImage {
31+ Flickable {
32− objectName: "image"
33+ objectName: "flickable"
35+ contentHeight: imageContainer.height
36+ contentWidth: imageContainer.width
37+ onHeightChanged: image.calculateSize()
38+ onWidthChanged: image.calculateSize()
33− anchors {
39+ anchors.fill: parent
35− bottom: parent.bottom
41+ Item {
43+ objectName: "imageContainer"
44+ width: Math.max(image.width * image.scale, flickable.width)
45+ height: Math.max(image.height * image.scale, flickable.height)
50+ property real prevScale
51+ smooth: !flickable.movingVertically
52+ anchors.centerIn: parent
53+ fillMode: Image.PreserveAspectFit
54+ source: widgetData["source"]
56+ function calculateSize() {
57+ scale = Math.min(flickable.width / width, flickable.height / height) * 0.98;
58+ pinchArea.minScale = scale;
59+ prevScale = Math.min(scale, 1);
63+ if ((width * scale) > flickable.width) {
64+ var xoff = (flickable.width / 2 + flickable.contentX) * scale / prevScale;
65+ flickable.contentX = xoff - flickable.width / 2;
67+ if ((height * scale) > flickable.height) {
68+ var yoff = (flickable.height / 2 + flickable.contentY) * scale / prevScale;
69+ flickable.contentY = yoff - flickable.height / 2;
76+ if (status == Image.Ready) {
86+ objectName: "pinchArea"
87+ property real minScale: 1.0
88+ property real lastScale: 1.0
90+ enabled: widgetData["zoomable"] ? widgetData["zoomable"] : false
93+ pinch.minimumScale: minScale
95+ onPinchFinished: flickable.returnToBounds()
100+ objectName: "mouseArea"
102+ anchors.fill: parent
103+ property bool doubleClicked: false
104+ property bool swipeDone: false
107+ property real startScale: pinchArea.minScale
108+ enabled: widgetData["zoomable"] ? widgetData["zoomable"] : false
111+ if (wheel.angleDelta.y > 0) {
112+ startScale = image.scale;
113+ image.scale = startScale + 0.1;
114+ } else if (wheel.angleDelta.y < 0) {
115+ startScale = image.scale;
116+ if (image.scale > 0.1) {
117+ image.scale = startScale - 0.1;
120+ wheel.accepted = true;
124+ startX = (mouse.x / image.scale);
125+ startY = (mouse.y / image.scale);
126+ startScale = image.scale;
130+ if (image.scale == startScale) {
131+ var deltaX = (mouse.x / image.scale) - startX;
132+ var deltaY = (mouse.y / image.scale) - startY;
134+ if (image.scale == pinchArea.minScale &&
135+ (Math.abs(deltaX) > 50 || Math.abs(deltaY) > 50)) {
38− source: widgetData["source"]
39− initialWidth: units.gu(13)