~verzegnassi-stefano/+junk/docviewer-tmp-001

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): David Planella, Daniel Holbach, Fabio Colella, Stefano Verzegnassi, Arto Jalkanen
  • Date: 2014-10-29 07:39:08 UTC
  • mfrom: (31.1.22 add-plugin)
  • Revision ID: tarmac-20141029073908-8s6r18syexjo37ga
Adds the file plugin to the source tree.

Approved by Stefano Verzegnassi, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.3
 
2
import Ubuntu.Components 1.1
 
3
 
 
4
import "utils.js" as Utils
 
5
 
 
6
Page {
 
7
    id: pageMain
 
8
    title: Utils.getNameOfFile(file.path);
 
9
 
 
10
    head.actions: [
 
11
        Action {
 
12
            text: i18n.tr("Details")
 
13
            iconName: "info"
 
14
            onTriggered: pageStack.push(Qt.resolvedUrl("DetailsPage.qml"))
 
15
        }
 
16
    ]
 
17
 
 
18
    Flickable {
 
19
        id: flickImg
 
20
        anchors.fill: parent
 
21
        contentHeight: image.height
 
22
 
 
23
        PinchArea {
 
24
            id: pinchy
 
25
            anchors.fill: image
 
26
            enabled: true
 
27
 
 
28
            property real lastWidth
 
29
            property real lastHeight
 
30
            property double p1toC_X
 
31
            property double p1toC_Y
 
32
            property double contentInitX
 
33
            property double contentInitY
 
34
 
 
35
            onPinchStarted: {
 
36
                lastWidth = image.width
 
37
                lastHeight = image.height
 
38
 
 
39
                contentInitX = flickImg.contentX
 
40
                contentInitY = flickImg.contentY
 
41
 
 
42
            }
 
43
 
 
44
            onPinchUpdated: {
 
45
 
 
46
                var newWidth = 0;
 
47
 
 
48
                newWidth = lastWidth*pinch.scale;
 
49
 
 
50
                if (newWidth < image.startWidth)
 
51
                    newWidth = image.startWidth;
 
52
                else if (newWidth > image.sourceSize.width)
 
53
                    newWidth = image.sourceSize.width;
 
54
 
 
55
                flickImg.contentWidth = newWidth;
 
56
 
 
57
                flickImg.contentX = contentInitX-(lastWidth-newWidth)/2
 
58
                flickImg.contentY = contentInitY-(lastHeight-image.height)/2
 
59
 
 
60
            }
 
61
        }
 
62
 
 
63
        Image {
 
64
 
 
65
            property real startWidth
 
66
 
 
67
            id: image
 
68
            objectName: "imageItem"
 
69
 
 
70
            source: file.path
 
71
            smooth: true
 
72
            fillMode: Image.PreserveAspectFit
 
73
            width: parent.width
 
74
 
 
75
            Component.onCompleted: {
 
76
                if (width > sourceSize.width)
 
77
                    startWidth = sourceSize.width
 
78
                else
 
79
                    startWidth = width
 
80
 
 
81
 
 
82
            }
 
83
        }
 
84
 
 
85
    }
 
86
}