1ffda9fd0911bb8f4c28ae87e17776841e05bf3c
[quandoparte] / application / resources / harmattan / qml / StationScheduleDelegate.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 Item {
8     id: root
9     property variant type
10     property alias arrivalTime: arrivalTimeLabel.text
11     property alias departureTime: departureTimeLabel.text
12     property alias train: trainLabel.text
13     property string arrivalStation
14     property string departureStation
15     property alias delay: delayLabel.text
16     property string actualPlatform
17     property string expectedPlatfrom
18
19     implicitHeight: UiConstants.ListItemHeightLarge
20     height: UiConstants.ListItemHeightLarge
21     BorderImage {
22         id: background
23         anchors.fill: parent
24         // Fill page borders
25         visible: mouseArea.pressed
26         source: "image://theme/meegotouch-list-background-pressed-center"
27     }
28     Item {
29         id: bodyRow
30         anchors {
31             fill: parent
32             margins: UiConstants.ButtonSpacing
33         }
34         DelayIndicator {
35             id: indicator
36             anchors {
37                 top: parent.top
38                 left: parent.left
39             }
40             level: delayClass
41         }
42         Item {
43             anchors {
44                 left: indicator.right
45                 right: bodyRow.right
46                 margins: UiConstants.ButtonSpacing
47             }
48             height: UiConstants.TitleFontPixelSize
49             Row {
50                 id: firstRow
51                 anchors.top: parent.top
52                 spacing: UiConstants.ButtonSpacing
53                 Label {
54                     id: arrivalTimeLabel
55                     font.bold: UiConstants.TitleFontBoldness
56                     font.pixelSize: UiConstants.TitleFontPixelSize
57                     visible: type === StationScheduleModel.ArrivalSchedule
58                 }
59                 Label {
60                     id: departureTimeLabel
61                     font.bold: UiConstants.TitleFontBoldness
62                     font.pixelSize: UiConstants.TitleFontPixelSize
63                     visible: type === StationScheduleModel.DepartureSchedule
64                 }
65                 Label {
66                     id: trainLabel
67                     font.bold: UiConstants.TitleFontBoldness
68                     font.pixelSize: UiConstants.TitleFontPixelSize
69                     color: UiConstants.AccentColor
70                 }
71             }
72             Item {
73                 id: secondRow
74                 height: UiConstants.DefaultFontPixelSize
75                 anchors.top: firstRow.bottom
76                 Label {
77                     text: qsTr("from %1").arg(root.arrivalStation)
78                     font.bold: UiConstants.DefaultFontBoldness
79                     font.pixelSize: UiConstants.DefaultFontPixelSize
80                     visible: type === StationScheduleModel.ArrivalSchedule
81                 }
82                 Label {
83                     text: qsTr("to %1").arg(root.departureStation)
84                     font.bold: UiConstants.DefaultFontBoldness
85                     font.pixelSize: UiConstants.DefaultFontPixelSize
86                     visible: type === StationScheduleModel.DepartureSchedule
87                 }
88             }
89             Item {
90                 height: UiConstants.SubtitleFontPixelSize
91                 anchors {
92                     top: secondRow.bottom
93                     left: parent.left
94                     right: parent.right
95                 }
96                 Label {
97                     id: delayLabel
98                     anchors.top: parent.top
99                     font.bold: UiConstants.SubtitleFontBoldness
100                     font.pixelSize: UiConstants.SubtitleFontPixelSize
101                 }
102                 Label {
103                     anchors {
104                         top: parent.top
105                         right: parent.right
106                         rightMargin: UiConstants.DefaultMargin
107                     }
108                     text: displayPlatform(root.expectedPlatfrom, root.actualPlatform)
109                     font.bold: UiConstants.SubtitleFontBoldness
110                     font.pixelSize: UiConstants.SubtitleFontPixelSize
111                 }
112             }
113         }
114     }
115     Image {
116         anchors {
117             leftMargin: UiConstants.DefaultMargin
118             rightMargin: UiConstants.DefaultMargin
119             left: parent.left
120             right: parent.right
121         }
122         source: "image://theme/meegotouch-separator-background-horizontal"
123     }
124     MouseArea {
125         id: mouseArea
126         anchors.fill: background
127         onClicked: {
128             // Load an external page about the train, for now
129             Qt.openUrlExternally(settings.queryBaseUrl + "/" + detailsUrl)
130             console.log(settings.queryBaseUrl + "/" + detailsUrl)
131         }
132     }
133     function displayPlatform(expected, actual)
134     {
135         if (actual === "--") {
136             return qsTr("Platform %1").arg(expected)
137         } else if (actual === expected || expected === "--") {
138             return qsTr("Platform <span style='font-weight:bold;color:#080'>%2</span>").arg(actual)
139         } else {
140             return qsTr("Platform " +
141                         "<span style='text-decoration:line-through'>%1</span> " +
142                         "<span style='font-weight:bold;color:#800'>%2</span>").arg(expected).arg(actual)
143         }
144     }
145 }