~mutse-young/ubuntu-docviewer-app/trunk

« back to all changes in this revision

Viewing changes to src/app/qml/ImageView.qml

  • Committer: Tarmac
  • Author(s): Stefano Verzegnassi
  • Date: 2014-11-29 12:22:51 UTC
  • mfrom: (39.2.3 ubuntu-docviewer-app)
  • Revision ID: tarmac-20141129122251-5lc2a70oz1qv31g2
Use ZoomableImage from Unity 8 to show images.

Approved by Riccardo Padovani, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        }
32
32
    ]
33
33
 
34
 
    Flickable {
35
 
        id: flickImg
 
34
    ZoomableImage {
36
35
        anchors.fill: parent
37
 
        contentHeight: image.height
38
 
 
39
 
        PinchArea {
40
 
            id: pinchy
41
 
            anchors.fill: image
42
 
            enabled: true
43
 
 
44
 
            property real lastWidth
45
 
            property real lastHeight
46
 
            property double p1toC_X
47
 
            property double p1toC_Y
48
 
            property double contentInitX
49
 
            property double contentInitY
50
 
 
51
 
            onPinchStarted: {
52
 
                lastWidth = image.width
53
 
                lastHeight = image.height
54
 
 
55
 
                contentInitX = flickImg.contentX
56
 
                contentInitY = flickImg.contentY
57
 
 
58
 
            }
59
 
 
60
 
            onPinchUpdated: {
61
 
 
62
 
                var newWidth = 0;
63
 
 
64
 
                newWidth = lastWidth*pinch.scale;
65
 
 
66
 
                if (newWidth < image.startWidth)
67
 
                    newWidth = image.startWidth;
68
 
                else if (newWidth > image.sourceSize.width)
69
 
                    newWidth = image.sourceSize.width;
70
 
 
71
 
                flickImg.contentWidth = newWidth;
72
 
 
73
 
                flickImg.contentX = contentInitX-(lastWidth-newWidth)/2
74
 
                flickImg.contentY = contentInitY-(lastHeight-image.height)/2
75
 
 
76
 
            }
77
 
        }
78
 
 
79
 
        Image {
80
 
 
81
 
            property real startWidth
82
 
 
83
 
            id: image
84
 
            objectName: "imageItem"
85
 
 
86
 
            source: file.path
87
 
            smooth: true
88
 
            fillMode: Image.PreserveAspectFit
89
 
            width: parent.width
90
 
 
91
 
            Component.onCompleted: {
92
 
                if (width > sourceSize.width)
93
 
                    startWidth = sourceSize.width
94
 
                else
95
 
                    startWidth = width
96
 
 
97
 
 
98
 
            }
99
 
        }
100
 
 
 
36
 
 
37
        zoomable: true
 
38
        source: file.path
101
39
    }
102
40
}