Tuned StationScheduleDelegate rendering a bit
[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                     color: Theme.secondaryColor
83                 }
84                 Label {
85                     anchors {
86                         top: parent.top
87                         right: parent.right
88                         rightMargin: Theme.paddingMedium
89                     }
90                     text: displayPlatform(root.expectedPlatfrom, root.actualPlatform)
91                     font.pixelSize: Theme.fontSizeSmall
92                     textFormat: Text.RichText
93                     color: Theme.secondaryColor
94                 }
95             }
96         }
97     }
98     Separator {
99         anchors {
100             left: parent.left
101             right: parent.right
102         }
103         color: Theme.secondaryColor
104     }
105     onClicked: {
106         // Load an external page about the train, for now
107         Qt.openUrlExternally(settings.queryBaseUrl + "/" + detailsUrl)
108         console.log(settings.queryBaseUrl + "/" + detailsUrl)
109     }
110     function displayPlatform(expected, actual)
111     {
112         if (actual === "--") {
113             return qsTr("Platform %1").arg(expected)
114         } else if (actual === expected || expected === "--") {
115             return qsTr("Platform <span style='font-weight:bold;color:%2'>%1</span>").arg(actual).arg("#0f0")
116         } else {
117             return qsTr("Platform " +
118                         "<span style='text-decoration:line-through'>%1</span> " +
119                         "<span style='font-weight:bold;color:%3'>%2</span>").arg(expected).arg(actual).arg("#f00")
120         }
121     }
122 }