~boghison/lang/trunk

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import QtQuick 2.0
import Ubuntu.Components 1.1

Page {
    id: wordPage
    property string word
    property string definition
    property string name
    property string color

    function modelIndex(type, content){
        var model = type == "d" ? definitionModel : translationModel;
        var index;
        for (var i = 0; i < model.count; i++){
            if (model == definitionModel && model.get(i).word == content.word && model.get(i).definition == content.definition){
                index = i;
                break;
            }
            else if (model == translationModel && model.get(i).from == content.from && model.get(i).definition == content.definition){
                index = i;
                break;
            }
        }
        return index;
    }

    head.actions: [
        Action {
            text: i18n.tr("Delete")
            iconName: "delete"
            onTriggered: {
                var myContent = vocabDB.contents;
                var tempContents = {};
                var i = 0;
                for (; i < myContent.vocabularies.length; i++){
                    if (myContent.vocabularies[i].name == wordPage.name && myContent.vocabularies[i].color == wordPage.color){ tempContents = myContent.vocabularies[i]; break;}
                }
                var myJSon = {};
                var newArray = [];
                if (wordPage.title == "Definition"){
                    myJSon = {"word": wordPage.word, "definition": wordPage.definition};
                    definitionModel.remove(modelIndex("d", myJSon));
                    for (var x = 0; x < tempContents.definitions.length; x++){
                        if (JSON.stringify(tempContents.definitions[x]) == JSON.stringify(myJSon)) continue
                        newArray.push(tempContents.definitions[x]);
                    }
                    tempContents.definitions = newArray;
                }
                else {
                    myJSon = {"from": wordPage.word, "to": wordPage.definition};
                    translationModel.remove(modelIndex("t", myJSon));
                    for (var x = 0; x < tempContents.translations.length; x++){
                        if (JSON.stringify(tempContents.translations[x]) == JSON.stringify(myJSon)) continue
                        newArray.push(tempContents.translations[x]);
                    }
                    tempContents.translations = newArray;
                }
                myContent.vocabularies[i] = tempContents;
                vocabDB.contents = myContent;
                mainStack.pop(Qt.resolvedUrl("wordPage.qml"));

            }
        }
    ]

    Flipable {
        anchors.centerIn: parent
        width: parent.width
        height: parent.height/2
        id: wordFlipable
        property bool flipped: false
        front: UbuntuShape {
            width: parent.width
            height: parent.height
            color: "white"

            Label {
                text: parent.parent.parent.word
                anchors.centerIn: parent
                fontSize: "x-large"
            }
        }
        back: UbuntuShape {
            width: parent.width
            height: parent.height
            color: "white"

            Label {
                text: parent.parent.parent.definition
                anchors.centerIn: parent
                fontSize: "x-large"
            }
        }
        transform: Rotation {
            id: rotation
            origin.x: wordFlipable.width/2
            origin.y: wordFlipable.height/2
            axis.x: 0; axis.y: 1; axis.z: 0
            angle: 0
        }
        states: State {
            name: "back"
            PropertyChanges {
                target: rotation
                angle: 180
            }
            when: wordFlipable.flipped
        }
        transitions: Transition {
            NumberAnimation {
                target: rotation
                property: "angle"
                duration: 1000
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: wordFlipable.flipped = !wordFlipable.flipped
        }
    }
}