Fix menu not working, and warning about anchors
[quandoparte] / application / resources / harmattan / qml / StationPage.qml
1 import QtQuick 1.1
2 import QtWebKit 1.0
3 import com.nokia.meego 1.0
4 import net.cirulla.quandoparte 1.0
5 import "uiconstants.js" as UiConstants
6
7 Page {
8     property alias name: schedule.name
9
10     tools: ToolBarLayout {
11         id: toolBar
12         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop() }
13         ToolIcon { iconId: "icon-m-toolbar-view-menu"; onClicked: menu.open() }
14     }
15     PageHeader {
16         id: header
17         anchors.top: parent.top
18         selectedIndex: schedule.type
19         options: ListModel {
20             id: dialogOptions
21             ListElement {
22                 name: QT_TR_NOOP("Departures")
23             }
24             ListElement {
25                 name: QT_TR_NOOP("Arrivals")
26             }
27         }
28     }
29     InfoBar {
30         id: infoBar
31         anchors.top: header.bottom
32         text: parent.name
33     }
34     Binding {
35         target: schedule
36         property: "type"
37         value: header.selectedIndex
38     }
39     LabelStyle {
40         id: labelStyle
41     }
42     Item {
43         id: view
44         anchors {
45             top: infoBar.bottom
46             bottom: parent.bottom
47             left: parent.left
48             right: parent.right
49         }
50         DroppedShadow {
51             id: shadow
52             anchors.top: view.top
53         }
54         ListView {
55             id: stationScheduleView
56             clip: true
57             visible: false
58             width: parent.width
59             anchors {
60                 top: shadow.top
61                 bottom: parent.bottom
62             }
63             model:  schedule
64             delegate: Item {
65                 id: listItem
66                 height: UiConstants.ListItemHeightDefault
67                 width: parent.width
68                 BorderImage {
69                     id: background
70                     anchors.fill: parent
71                     // Fill page borders
72                     visible: mouseArea.pressed
73                     source: "image://theme/meegotouch-list-background-pressed-center"
74                 }
75                 Row {
76                     id: bodyRow
77                     anchors.fill: parent
78                     spacing: UiConstants.ButtonSpacing
79                     DelayIndicator {
80                         level: delayClass
81                     }
82                     Column {
83                         anchors.verticalCenter: parent.verticalCenter
84                         Row {
85                             spacing: UiConstants.ButtonSpacing
86                             Label {
87                                 text: arrivalTime
88                                 font.bold: UiConstants.SpecialFontBoldness
89                                 font.pixelSize: UiConstants.SpecialFontPixelSize
90                                 visible: schedule.type === StationScheduleModel.ArrivalSchedule
91                             }
92                             Label {
93                                 text: departureTime
94                                 font.bold: UiConstants.SpecialFontBoldness
95                                 font.pixelSize: UiConstants.SpecialFontPixelSize
96                                 visible: schedule.type === StationScheduleModel.DepartureSchedule
97                             }
98                             Label {
99                                 text: train
100                                 font.bold: UiConstants.SpecialFontBoldness
101                                 font.pixelSize: UiConstants.SpecialFontPixelSize
102                                 color: UiConstants.AccentColor
103                             }
104                         }
105                         Label {
106                             text: qsTr("from ") + arrivalStation
107                             font.bold: UiConstants.DefaultFontBoldness
108                             font.pixelSize: UiConstants.DefaultFontPixelSize
109                             visible: schedule.type === StationScheduleModel.ArrivalSchedule
110                         }
111                         Label {
112                             text: qsTr("to ") + departureStation
113                             font.bold: UiConstants.DefaultFontBoldness
114                             font.pixelSize: UiConstants.DefaultFontPixelSize
115                             visible: schedule.type === StationScheduleModel.DepartureSchedule
116                         }
117                         Label {
118                             id: delayLabel
119                             text: delay
120                             font.bold: UiConstants.SubtitleFontBoldness
121                             font.pixelSize: UiConstants.SubtitleFontPixelSize
122                         }
123                     }
124                 }
125                 Label {
126                     anchors {
127                         bottom: bodyRow.bottom
128                         right: bodyRow.right
129                         rightMargin: UiConstants.DefaultMargin
130                     }
131                     text: qsTr("Platform ") + actualPlatform
132                     font.bold: UiConstants.SubtitleFontBoldness
133                     font.pixelSize: UiConstants.SubtitleFontPixelSize
134                 }
135                 Image {
136                     anchors {
137                         left: parent.left
138                         right: parent.right
139                     }
140                     source: "image://theme/meegotouch-separator-background-horizontal"
141                 }
142                 MouseArea {
143                     id: mouseArea
144                     anchors.fill: background
145                     onClicked: {
146                         // Load an external page about the train, for now
147                         Qt.openUrlExternally(settings.queryBaseUrl + "/" + detailsUrl)
148                         console.log(settings.queryBaseUrl + "/" + detailsUrl)
149                     }
150                 }
151             }
152         }
153         ScrollDecorator {
154             id: decorator
155             flickableItem: stationScheduleView
156         }
157         BusyIndicator {
158             id: busyIndicator
159             platformStyle: BusyIndicatorStyle {
160                 size: "large"
161             }
162             anchors.centerIn: parent
163             visible: !stationScheduleView.visible
164             running: visible
165         }
166         states: [
167             State {
168                 name: "loading"
169                 PropertyChanges {
170                     target: stationScheduleView
171                     visible: false
172                 }
173             },
174             State {
175                 name: "ready"
176                 PropertyChanges {
177                     target: stationScheduleView
178                     visible: true
179                 }
180             }
181         ]
182     }
183     StationScheduleModel {
184         id: schedule
185         onNameChanged: schedule.fetch(name)
186         onLayoutChanged: view.state = "ready"
187     }
188     Settings {
189         id: settings
190     }
191  }