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

« back to all changes in this revision

Viewing changes to src/app/qml/PdfView.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
import org.docviewer.poppler 1.0
 
4
 
 
5
import "utils.js" as Utils
 
6
 
 
7
Page {
 
8
    id: pageMain
 
9
    title: Utils.getNameOfFile(file.path);
 
10
 
 
11
    head.actions: [
 
12
        Action {
 
13
            text: i18n.tr("Details")
 
14
            iconName: "info"
 
15
            onTriggered: pageStack.push(Qt.resolvedUrl("DetailsPage.qml"))
 
16
        }
 
17
    ]
 
18
 
 
19
    Flickable {
 
20
        id: flickable
 
21
        anchors.fill: parent
 
22
 
 
23
        contentHeight: columnPages.height + 10
 
24
        contentWidth: parent.width
 
25
 
 
26
        PinchArea {
 
27
            id: pinchy
 
28
            anchors.fill: columnPages
 
29
            enabled: true
 
30
            pinch.target: flickable
 
31
 
 
32
            property real lastWidth
 
33
            /*property real lastHeight
 
34
        property double p1toC_X
 
35
        property double p1toC_Y
 
36
        property double contentInitX
 
37
        property double contentInitY*/
 
38
 
 
39
            onPinchStarted: {
 
40
                lastWidth = flickable.width
 
41
 
 
42
                /*contentInitX = flickImg.contentX
 
43
            contentInitY = flickImg.contentY*/
 
44
 
 
45
            }
 
46
 
 
47
            onPinchUpdated: {
 
48
 
 
49
                var newWidth = 0;
 
50
 
 
51
                newWidth = lastWidth*pinch.scale;
 
52
 
 
53
                /*if (newWidth < image.startWidth)
 
54
                newWidth = image.startWidth;
 
55
            else if (newWidth > image.sourceSize.width)
 
56
                newWidth = image.sourceSize.width;*/
 
57
 
 
58
                flickable.contentWidth = newWidth;
 
59
 
 
60
                /*flickImg.contentX = contentInitX-(lastWidth-newWidth)/2
 
61
            flickImg.contentY = contentInitY-(lastHeight-image.height)/2*/
 
62
 
 
63
            }
 
64
 
 
65
            onPinchFinished: {
 
66
 
 
67
                columnPages.shouldReloadImg = true;
 
68
                console.log("FINISHED");
 
69
            }
 
70
        }
 
71
 
 
72
 
 
73
        Poppler {
 
74
            id: popplerProp
 
75
            path: file.path
 
76
        }
 
77
 
 
78
        Column {
 
79
            id: columnPages
 
80
 
 
81
            property bool shouldReloadImg : false
 
82
 
 
83
            width: parent.width - 10
 
84
            x: 5
 
85
            y: 5
 
86
            spacing: 10
 
87
 
 
88
            onWidthChanged: {
 
89
                if (!pinchy.pinch.active)
 
90
                    shouldReloadImg=true
 
91
                else
 
92
                    shouldReloadImg=false
 
93
            }
 
94
 
 
95
        }
 
96
 
 
97
        Component.onCompleted: {
 
98
 
 
99
            var i=0;
 
100
            for(i=1; i <= popplerProp.numPages; i++)
 
101
            {
 
102
                var component = Qt.createComponent("PdfPage.qml");
 
103
 
 
104
                if (component.status === Component.Error)
 
105
                {
 
106
                    console.debug("Error creating component");
 
107
                }
 
108
                else
 
109
                {
 
110
                    var page = component.createObject(columnPages);
 
111
 
 
112
                    page.source = "image://poppler/page/"+i;
 
113
                }
 
114
            }
 
115
        }
 
116
    }
 
117
}