7d943b78f9c6b6778afd233f6d8f21d90b827e3c
[quandoparte] / application / resources / sailfish / qml / pages / components / StationScheduleDelegate.qml
1 import QtQuick 2.0
2 import QtWebKit 3.0
3 import Sailfish.Silica 1.0
4 import net.cirulla.quandoparte 1.0
5
6 BackgroundItem {
7     id: root
8     property variant type
9     property alias arrivalTime: arrivalTimeLabel.text
10     property alias departureTime: departureTimeLabel.text
11     property alias train: trainLabel.text
12     property string arrivalStation
13     property string departureStation
14     property alias delay: delayLabel.text
15     property string actualPlatform
16     property string expectedPlatfrom
17
18     implicitHeight: Theme.itemSizeExtraLarge
19     height: Theme.itemSizeExtraLarge
20     Item {
21         id: bodyRow
22         anchors {
23             fill: parent
24             margins: Theme.paddingSmall
25         }
26         DelayIndicator {
27             id: indicator
28             level: delayClass
29         }
30         Item {
31             anchors {
32                 left: indicator.right
33                 right: bodyRow.right
34                 leftMargin: Theme.paddingMedium
35             }
36             Row {
37                 id: firstRow
38                 anchors.top: parent.top
39                 spacing: Theme.paddingMedium
40                 Label {
41                     id: arrivalTimeLabel
42                     font.pixelSize: Theme.fontSizeMedium
43                     visible: type === StationScheduleModel.ArrivalSchedule
44                 }
45                 Label {
46                     id: departureTimeLabel
47                     font.pixelSize: Theme.fontSizeMedium
48                     visible: type === StationScheduleModel.DepartureSchedule
49                 }
50                 Label {
51                     id: trainLabel
52                     font.pixelSize: Theme.fontSizeMedium
53                     color: Theme.highlightColor
54                 }
55             }
56             Item {
57                 id: secondRow
58                 height: Theme.fontSizeMedium
59                 anchors.top: firstRow.bottom
60                 Label {
61                     text: qsTr("from %1").arg(root.arrivalStation)
62                     font.pixelSize: Theme.fontSizeMedium
63                     visible: type === StationScheduleModel.ArrivalSchedule
64                 }
65                 Label {
66                     text: qsTr("to %1").arg(root.departureStation)
67                     font.pixelSize: Theme.fontSizeMedium
68                     visible: type === StationScheduleModel.DepartureSchedule
69                 }
70             }
71             Item {
72                 height: Theme.fontSizeSmall
73                 anchors {
74                     top: secondRow.bottom
75                     left: parent.left
76                     right: parent.right
77                 }
78                 Label {
79                     id: delayLabel
80                     anchors.top: parent.top
81                     font.pixelSize: Theme.fontSizeSmall
82                 }
83                 Label {
84                     anchors {
85                         top: parent.top
86                         right: parent.right
87                         rightMargin: Theme.paddingMedium
88                     }
89                     text: displayPlatform(root.expectedPlatfrom, root.actualPlatform)
90                     font.pixelSize: Theme.fontSizeSmall
91                     textFormat: Text.RichText
92                 }
93             }
94         }
95     }
96     Separator {
97         anchors {
98             left: parent.left
99             right: parent.right
100         }
101     }
102     onClicked: {
103         // Load an external page about the train, for now
104         Qt.openUrlExternally(settings.queryBaseUrl + "/" + detailsUrl)
105         console.log(settings.queryBaseUrl + "/" + detailsUrl)
106     }
107     function displayPlatform(expected, actual)
108     {
109         if (actual === "--") {
110             return qsTr("Platform %1").arg(expected)
111         } else if (actual === expected || expected === "--") {
112             return qsTr("Platform <span style='font-weight:bold;color:%2'>%1</span>").arg(actual).arg("#0f0")
113         } else {
114             return qsTr("Platform " +
115                         "<span style='text-decoration:line-through'>%1</span> " +
116                         "<span style='font-weight:bold;color:%3'>%2</span>").arg(expected).arg(actual).arg("#f00")
117         }
118     }
119 }