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

« back to all changes in this revision

Viewing changes to TextView.qml

  • Committer: Tarmac
  • Author(s): David Planella, Stefano Verzegnassi
  • Date: 2014-10-29 08:08:25 UTC
  • mfrom: (31.1.28 add-plugin)
  • Revision ID: tarmac-20141029080825-3z9xameaqsd28rgp
New UI design for plain text viewer.

Approved by Ubuntu Phone Apps Jenkins Bot, Stefano Verzegnassi.

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
 
Flickable {
5
 
    id: flickable
6
 
    anchors.fill: parent
7
 
    contentHeight: columnMain.height
8
 
    contentWidth: parent.width
9
 
 
10
 
 
11
 
    Column {
12
 
        id: columnMain
13
 
                objectName: "columnMain"
14
 
        width: parent.width
15
 
        spacing: 10
16
 
 
17
 
        TextArea {
18
 
            id: textAreaMain
19
 
                        objectName: "textAreaMain"
20
 
 
21
 
            width: parent.width
22
 
 
23
 
            autoSize: true
24
 
            maximumLineCount: 0
25
 
            readOnly: true
26
 
            //activeFocusOnPress: true;
27
 
            highlighted: true
28
 
 
29
 
            text: "Loading..."
30
 
 
31
 
            signal loadCompleted()
32
 
 
33
 
            Component.onCompleted: {
34
 
                var xhr = new XMLHttpRequest;
35
 
 
36
 
                xhr.open("GET", file.path);
37
 
                xhr.onreadystatechange = function() {
38
 
                    if (xhr.readyState === XMLHttpRequest.DONE) {
39
 
                        textAreaMain.text = xhr.responseText;
40
 
                        textAreaMain.loadCompleted();
41
 
                    }
42
 
                }
43
 
 
44
 
                xhr.send();
45
 
            }
46
 
        }
47
 
    }
48
 
 
49
 
    Keys.onPressed: {
50
 
        if (event.key === Qt.Key_PageDown) {
51
 
            if (!flickable.atYEnd)
52
 
                flickable.contentY = flickable.contentY + height / 2;
53
 
            event.accepted = true;
54
 
        } else if (event.key === Qt.Key_PageUp) {
55
 
            if (!flickable.atYBeginning)
56
 
                flickable.contentY = flickable.contentY - height / 2;
57
 
            event.accepted = true;
58
 
        }
59
 
    }
60
 
    Keys.onLeftPressed: {
61
 
        flickable.flick( -width / 2, 0)
62
 
    }
63
 
    Keys.onRightPressed: {
64
 
        flickable.flick( width / 2, 0)
65
 
    }
66
 
    Keys.onUpPressed: {
67
 
        flickable.flick( 0, height / 2)
68
 
    }
69
 
    Keys.onDownPressed: {
70
 
        flickable.flick( 0, -height / 2)
71
 
    }
72
 
}
73