aboutsummaryrefslogtreecommitdiff
path: root/src/SetPointPage.qml
blob: c22f0c36efc48c785b2f3d88df731e06d6439ec3 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import QtQuick 2.0
import org.asteroid.controls 1.0 as Asteroid
import QtPositioning 5.15
import QtLocation 5.15
import Nemo.Configuration 1.0

Item {
    id: root
    Asteroid.PageHeader {
        text: "Add waypoint"
    }
    ConfigurationValue {
        id: waypointList
        key: "/map/waypointList"
        defaultValue: ""
        Component.onCompleted: {
            var waypointArray = JSON.parse(waypointList.value)
            if (editMode) {
                var currWaypointData = waypointArray[editIndex]
                root.coord = QtPositioning.coordinate(currWaypointData[1][0],currWaypointData[1][1])
                root.selectedIcon = currWaypointData[0]
                root.selectedColor = currWaypointData[2]
                textbox.text = currWaypointData[3]
            } else {
                editIndex = waypointArray.length
                selectedColor = colours.primary
            }
        }
    }
    property string selectedIcon: "ios-locate-outline"
    property string selectedColor
    property variant coord
    property bool editMode: false
    property int editIndex
    Flickable {
        anchors.fill: parent
        contentHeight: contentColumn.implicitHeight
        anchors.leftMargin: root.width*0.15
        anchors.rightMargin: root.width*0.15
        Column {
            id: contentColumn
            anchors.fill: parent
            Item { width: parent.width ; height: root.width*0.2 }
            Asteroid.TextField {
                id: textBox
                width: parent.width
                height: parent.width*0.2
                previewText: "Waypoint name"
                text: Date.toLocaleString()
            }
            ListView {
                id: iconSelectorView
                width: parent.width
                height: root.height*0.2
                orientation: ListView.Horizontal
                model: iconModel
                delegate: Asteroid.IconButton {
                    iconName: name
                    onClicked: root.selectedIcon = model.name
                    height: iconSelectorView.height
                    width: height
                    iconColor: root.selectedIcon == model.name ? colours.primary : colours.primaryUnselected
                }
                ListModel {
                    id: iconModel
                    ListElement {
                        name: "ios-locate-outline"
                    }
                    ListElement {
                        name: "ios-checkmark"
                    }
                    ListElement {
                        name: "ios-help"
                    }
                    ListElement {
                        name: "ios-information"
                    }
                    ListElement {
                        name: "ios-body-outline"
                    }
                    ListElement {
                        name: "ios-bicycle"
                    }
                    ListElement {
                        name: "ios-car-outline"
                    }
                    ListElement {
                        name: "ios-boat-outline"
                    }
                }
            }
            Row {
                height: root.width*0.2
                anchors.horizontalCenter: parent.horizontalCenter
                Asteroid.IconButton {
                    height: parent.height
                    width: height
                    iconName: "ios-trash-circle"
                    visible: editMode
                    onClicked: removeWaypoint(editIndex)
                }
                Asteroid.IconButton {
                    height: parent.height
                    width: height
                    iconName: "ios-checkmark-circle-outline"
                    onClicked: commitChanges(editIndex)
                }
            }
            Item { width: parent.width ; height: root.width*0.2 }
        }
    }

    function commitChanges(index) {
        var waypointArray = JSON.parse(waypointList.value)
        var writebuffer = {}
        writebuffer[0] = selectedIcon
        writebuffer[1] = [coord.latitude,coord.longitude]
        writebuffer[2] = selectedColor //the colours.primary is currently a placeholder. it would be nice to let users select colours, but I CBA to write a colour picker right now
        writebuffer[3] = textBox.text
        writebuffer[4] = Date
        waypointArray[index] = writebuffer
        waypointList.value = JSON.stringify(waypointArray)
        setPointControls.visible = false
        mapControls.visible = true
        pageStack.pop(pageStack.currentLayer)
    }
    function removeWaypoint(index) {
        var waypointArray = JSON.parse(waypointList.value)
        waypointArray.splice(index)
        waypointList.value = JSON.stringify(waypointArray)
        setPointControls.visible = false
        mapControls.visible = true
        pageStack.pop(pageStack.currentLayer)
    }
}