~cibersheep/unav/systemcolors

« back to all changes in this revision

Viewing changes to qml/RoutePage.qml

  • Committer: costales
  • Date: 2016-03-26 18:53:17 UTC
  • Revision ID: costales.marcos@gmail.com-20160326185317-4iau3yhe8986h5pg
Init team

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * uNav http://launchpad.net/unav
 
3
 * Copyright (C) 2015-2016 Marcos Alvarez Costales https://launchpad.net/~costales
 
4
 * Copyright (C) 2015-2016 JkB https://launchpad.net/~joergberroth
 
5
 * Copyright (C) 2016 Nekhelesh Ramananthan https://launchpad.net/~nik90
 
6
 *
 
7
 * uNav is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * uNav is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 */
 
17
 
 
18
import QtQuick 2.4
 
19
import Ubuntu.Components 1.3
 
20
 
 
21
Page {
 
22
    id: routePage
 
23
 
 
24
    header: PageHeader {
 
25
        title: i18n.tr("Route")
 
26
        flickable: flickable
 
27
    }
 
28
 
 
29
    Component.onCompleted: mainPageStack.executeJavaScript("qml_set_route_status();")
 
30
 
 
31
    Flickable {
 
32
        id: flickable
 
33
 
 
34
        anchors { fill: parent; margins: units.gu(2) }
 
35
        height: contentItem.childrenRect.height
 
36
        boundsBehavior: (contentHeight > routePage.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
37
 
 
38
        ListModel {
 
39
            id: routePageModel
 
40
            ListElement {section: 0 ; text: "Search"; iconName: "../nav/img/pages/route/search.svg" }
 
41
            ListElement {section: 0 ; text: "Favorites"; iconName: "../nav/img/pages/route/favorites.svg" }
 
42
            ListElement {section: 1 ; text: "Nearby"; iconName: "../nav/img/pages/route/nearby_enabled.svg"}
 
43
            ListElement {section: 2 ; text: "Nearby"; iconName: "../nav/img/pages/route/nearby_disabled.svg"}
 
44
            ListElement {section: 0 ; text: "Coordinates"; iconName: "../nav/img/pages/route/coordinates.svg"}
 
45
            ListElement {section: 0 ; text: "Share"; iconName: "../nav/img/pages/route/share.svg"}
 
46
            ListElement {section: 3 ; text: "Cancel Route"; iconName: "../nav/img/pages/route/cancel.svg" }
 
47
        }
 
48
 
 
49
        Grid {
 
50
            id: routePageGrid
 
51
            //from system-settings (lp:ubuntu-system-settings)
 
52
            property int itemWidth: units.gu(14)
 
53
            // The amount of whitespace, including column spacing
 
54
            property int space: parent.width - columns * itemWidth
 
55
            // The column spacing is 1/n of the left/right margins
 
56
            property int n: 1
 
57
 
 
58
            columnSpacing: space / ((2 * n) + (columns - 1))
 
59
            rowSpacing: units.gu(6)
 
60
            width: (columns * itemWidth) + columnSpacing * (columns - 1)
 
61
            anchors.horizontalCenter: parent.horizontalCenter
 
62
            columns: {
 
63
                var items = Math.floor(parent.width / itemWidth)
 
64
                var count = repeater.count
 
65
                return count < items ? count : items
 
66
            }
 
67
 
 
68
            Repeater {
 
69
                id: repeater
 
70
 
 
71
                model: routePageModel
 
72
 
 
73
                delegate: AbstractButton {
 
74
                    id: button
 
75
 
 
76
                    width: col.width
 
77
                    height: col.height
 
78
                    visible: (    (model.section === 0) ||
 
79
                              (model.section === 1 && mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null") ||
 
80
                              (model.section === 2 && (mainPageStack.currentLat === "null" || mainPageStack.currentLng === "null")) ||
 
81
                              (model.section === 3 && mainPageStack.routeState !== 'no') )
 
82
 
 
83
                    UbuntuShape {
 
84
                        opacity: 0.15
 
85
                        visible: button.pressed
 
86
                        anchors { fill: col; margins: -units.gu(1) }
 
87
                        backgroundColor: UbuntuColors.darkGrey
 
88
                    }
 
89
 
 
90
                    Column {
 
91
                        id: col
 
92
 
 
93
                        spacing: units.gu(2)
 
94
                        width: units.gu (14)
 
95
 
 
96
                        Icon {
 
97
                            width: height
 
98
                            height: units.gu(4)
 
99
                            source: model.iconName
 
100
                            anchors.horizontalCenter: parent.horizontalCenter
 
101
                        }
 
102
 
 
103
                        Label {
 
104
                            width: col.width
 
105
                            fontSize: "small"
 
106
                            text: i18n.tr(model.text)
 
107
                            horizontalAlignment: Text.AlignHCenter
 
108
                            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
109
                            anchors.horizontalCenter: parent.horizontalCenter
 
110
                        }
 
111
                    }
 
112
 
 
113
                    onClicked: {
 
114
                        if (model.text === "Nearby" && (mainPageStack.currentLat === "null" || mainPageStack.currentLng === "null")) {
 
115
                            // Nothing
 
116
                        }
 
117
 
 
118
                        else {
 
119
                            mainPageStack.pop(routePage)
 
120
                            if (model.text === "Favorites") {
 
121
                                mainPageStack.push(Qt.resolvedUrl("FavoritesPage.qml"))
 
122
                            } else if (model.text === "Search") {
 
123
                                mainPageStack.push(Qt.resolvedUrl("SearchPage.qml"))
 
124
                            } else if (model.text === "Nearby") {
 
125
                                mainPageStack.push(Qt.resolvedUrl("PoiPage.qml"), {"fromPage": "RoutePage.qml", "lat": mainPageStack.currentLat, "lng": mainPageStack.currentLng})
 
126
                            } else if (model.text === "Coordinates") {
 
127
                                mainPageStack.push(Qt.resolvedUrl("Coordinate.qml"))
 
128
                            } else if (model.text === "Share") {
 
129
                                mainPageStack.push(Qt.resolvedUrl("SharePage.qml"))
 
130
                            } else if (model.text === "Cancel Route") {
 
131
                                mainPageStack.routeState = 'no';
 
132
                                mainPageStack.executeJavaScript("click_cancel_route();")
 
133
                            }
 
134
                        }
 
135
                    }
 
136
                }
 
137
            }
 
138
        }
 
139
    }
 
140
}
 
141