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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import QtQuick 2.3
import Ubuntu.Components 1.1

Flickable {
    id: flickable
    anchors.fill: parent
    contentHeight: columnMain.height
    contentWidth: parent.width


    Column {
        id: columnMain
		objectName: "columnMain"
        width: parent.width
        spacing: 10

        TextArea {
            id: textAreaMain
			objectName: "textAreaMain"

            width: parent.width

            autoSize: true
            maximumLineCount: 0
            readOnly: true
            //activeFocusOnPress: true;
            highlighted: true

            text: "Loading..."

            signal loadCompleted()

            Component.onCompleted: {
                var xhr = new XMLHttpRequest;

                xhr.open("GET", file.path);
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === XMLHttpRequest.DONE) {
                        textAreaMain.text = xhr.responseText;
                        textAreaMain.loadCompleted();
                    }
                }

                xhr.send();
            }
        }
    }

    Keys.onPressed: {
        if (event.key === Qt.Key_PageDown) {
            if (!flickable.atYEnd)
                flickable.contentY = flickable.contentY + height / 2;
            event.accepted = true;
        } else if (event.key === Qt.Key_PageUp) {
            if (!flickable.atYBeginning)
                flickable.contentY = flickable.contentY - height / 2;
            event.accepted = true;
        }
    }
    Keys.onLeftPressed: {
        flickable.flick( -width / 2, 0)
    }
    Keys.onRightPressed: {
        flickable.flick( width / 2, 0)
    }
    Keys.onUpPressed: {
        flickable.flick( 0, height / 2)
    }
    Keys.onDownPressed: {
        flickable.flick( 0, -height / 2)
    }
}