Finished initial QML porting
authorLuciano Montanaro <mikelima@cirulla.net>
Wed, 6 Nov 2013 00:00:55 +0000 (01:00 +0100)
committerLuciano Montanaro <mikelima@cirulla.net>
Wed, 6 Nov 2013 00:00:55 +0000 (01:00 +0100)
application/resources/sailfish/qml/main.qml
application/resources/sailfish/qml/pages/AboutPage.qml [new file with mode: 0644]
application/resources/sailfish/qml/pages/StationPage.qml
application/resources/sailfish/qml/pages/components/DelayIndicator.qml [new file with mode: 0644]
application/resources/sailfish/qml/pages/components/StationScheduleDelegate.qml [new file with mode: 0644]

index b3d3ca9..3463613 100644 (file)
@@ -6,4 +6,8 @@ ApplicationWindow {
     id: window
     initialPage: StationListPage { }
     cover: Qt.resolvedUrl("cover/CoverPage.qml")
+    Timer { /* XXX This is an AlignedTimer in Harmattan, which should be better for battery */
+        id: updateTimer
+        interval: 120
+    }
 }
diff --git a/application/resources/sailfish/qml/pages/AboutPage.qml b/application/resources/sailfish/qml/pages/AboutPage.qml
new file mode 100644 (file)
index 0000000..a41cd3b
--- /dev/null
@@ -0,0 +1,41 @@
+import QtQuick 2.0
+import Sailfish.Silica 1.0
+
+Page {
+    SilicaFlickable {
+       anchors.fill: parent
+       PageHeader {
+           id: header
+           anchors.top: parent.top
+        title: qsTr("About Quando Parte")
+       }
+       Label {
+           anchors {
+               top: header.bottom;
+               left: parent.left;
+               right: parent.right;
+               margins: Theme.paddingLarge
+           }
+            fontSizeMode: Text.Fit
+            textFormat: Text.RichText
+            wrapMode: Text.WordWrap
+            linkColor: Theme.highlightColor
+        text: qsTr("<h2><a href='http://quandoparte.garage.maemo.org'>" +
+                      "Quando Parte" + "</a></h2>" +"<p style='font-size:small;'>version ") +
+                 settings.versionString +
+                  "<div style='font-size:small;'>" +
+                 qsTr("</p>" +
+                       "<p>Copyright (c) 2010, 2011, 2012, 2013</p>" +
+                      "<p>Luciano Montanaro " +
+                      "(<a href='mailto:mikelima@cirulla.net'>mikelima@cirulla.net</a>)</p>" +
+                      "<p>Licensed under the GNU Public License v2 or above</p>" +
+                      "<p/><p>Station geolocation data from " +
+                      "<a href='http://www.openstreetmap.org'>OpenStreetMap</a></p>" +
+                      "<p>Realtime train data from " +
+                       "<a href='http://mobile.viaggiatreno.it'>Viaggiatreno</a></p>") +
+                       "</div>"
+            onLinkActivated: Qt.openUrlExternally(link)
+       }
+    }
+
+ }
index 555582a..a47f69a 100644 (file)
@@ -1,69 +1,40 @@
 import QtQuick 2.0
 import Sailfish.Silica 1.0
 import net.cirulla.quandoparte 1.0
+import "components"
 
 Page {
     property alias name: schedule.name
     property alias code: schedule.code
 
-    tools: ToolBarLayout {
-        id: toolBar
-        ToolIcon {
-            iconId: "icon-m-toolbar-back" + (theme.inverted ? "-white": "")
-            onClicked: pageStack.pop()
-        }
-        ToolIcon {
-            iconId: "icon-m-toolbar-refresh" + (theme.inverted ? "-white": "")
-            onClicked: updateStation() }
-        ToolIcon {
-            iconId: "icon-m-toolbar-view-menu" + (theme.inverted ? "-white": "")
-            onClicked: menu.open()
-        }
-    }
-    PageHeader {
-        id: header
-        anchors.top: parent.top
-        selectedIndex: schedule.type
-        options: [
-            qsTr("Departures"),
-            qsTr("Arrivals")
-        ]
-    }
-    InfoBar {
-        id: infoBar
-        anchors.top: header.bottom
-        text: parent.name
-    }
-    Binding {
-        target: schedule
-        property: "type"
-        value: header.selectedIndex
-    }
-    LabelStyle {
-        id: labelStyle
-    }
-    Item {
+    SilicaFlickable {
         id: view
-        anchors {
-            top: infoBar.bottom
-            bottom: parent.bottom
-            left: parent.left
-            right: parent.right
-        }
-        DroppedShadow {
-            id: shadow
-            anchors.top: view.top
+        anchors.fill: parent
+        PullDownMenu {
+            MenuItem {
+                text: qsTr("Update Schedule")
+                onClicked: updateStation()
+            }
+            MenuItem {
+                text: qsTr("Departures")
+                onClicked: schedule.type = StationScheduleModel.DepartureSchedule
+            }
+            MenuItem {
+                text: qsTr("Arrivals")
+                onClicked: schedule.type = StationScheduleModel.ArrivalSchedule
+            }
         }
-        ListView {
+        SilicaListView {
             id: stationScheduleView
+            anchors.fill: parent
             clip: true
             visible: false
             width: parent.width
             cacheBuffer: 40
-            anchors {
-                top: shadow.top
-                bottom: parent.bottom
-            }
+            header: PageHeader {
+                    id: header
+                    title: (schedule.type === StationScheduleModel.DepartureSchedule ? qsTr("Departures from ") : qsTr("Arrivals to ")) + name
+                }
             model: schedule
             delegate: StationScheduleDelegate {
                 width: stationScheduleView.width
@@ -78,36 +49,28 @@ Page {
                 expectedPlatfrom: model.expectedPlatform
             }
         }
-        ScrollDecorator {
-            id: decorator
-            flickableItem: stationScheduleView
-        }
         BusyIndicator {
             id: busyIndicator
-            platformStyle: BusyIndicatorStyle {
-                size: "large"
-            }
             anchors.centerIn: parent
             running: visible
+            size: BusyIndicatorSize.Large
         }
         Item {
             id: errorDisplay
             anchors.centerIn: parent
             Column {
                 anchors.centerIn: parent
-                spacing: UiConstants.DefaultMargin
+                spacing: Theme.paddingMedium
                 Text {
                     text: qsTr("Error!")
                     width: parent.width
-                    font.pixelSize: UiConstants.HeaderFontPixelSize
-                    font.bold: UiConstants.HeaderFontBoldness
+                    font.pixelSize: Theme.fontSizeHuge
                     horizontalAlignment: Text.AlignHCenter
                 }
                 Text {
                     text: schedule.error
                     width: parent.width
-                    font.pixelSize: UiConstants.HeaderFontPixelSize
-                    font.bold: UiConstants.DefaultFontBoldness
+                    font.pixelSize: Theme.fontSizeHuge
                     horizontalAlignment: Text.AlignHCenter
                 }
             }
@@ -161,20 +124,22 @@ Page {
                 }
             }
         ]
-    }
-    StationScheduleModel {
-        id: schedule
-        onNameChanged: updateStation()
-        onLayoutChanged: if (error) view.state = "error"
-                         else view.state = "ready"
-    }
-    Component.onCompleted: {
-        updateTimer.timeout.connect(updateStation)
-        view.state = "loading"
-    }
-    function updateStation() {
-        view.state = "loading"
-        console.log("Updating station with " + schedule.name + ", " + schedule.code)
-        schedule.fetch(schedule.name, schedule.code)
+
+        function updateStation() {
+            view.state = "loading"
+            console.log("Updating station with " + schedule.name + ", " + schedule.code)
+            schedule.fetch(schedule.name, schedule.code)
+        }
+        StationScheduleModel {
+            id: schedule
+            onNameChanged: view.updateStation()
+            onLayoutChanged: if (error) view.state = "error"
+                             else view.state = "ready"
+        }
+
+        Component.onCompleted: {
+            updateTimer.triggered.connect(view.updateStation)
+            view.state = "loading"
+        }
     }
 }
diff --git a/application/resources/sailfish/qml/pages/components/DelayIndicator.qml b/application/resources/sailfish/qml/pages/components/DelayIndicator.qml
new file mode 100644 (file)
index 0000000..cfccfae
--- /dev/null
@@ -0,0 +1,30 @@
+import QtQuick 2.0
+import Sailfish.Silica 1.0
+
+Item {
+    id: indicator
+    property int level: 0
+    width: 10
+    height: parent.height
+    anchors {
+        top: parent.top
+        bottom: parent.bottom
+        rightMargin: Theme.paddingMedium
+    }
+    Rectangle {
+        id: rect
+        width: 10
+        height: indicator.height - 10
+        anchors.centerIn: parent
+        color: {
+            switch (indicator.level) {
+            case 0: return "#0b0"
+            case 1: return "#dd0"
+            case 2: return "#da0"
+            case 3: return "#d60"
+            case 4: return "#d00"
+            default: return "#b0b"
+            }
+        }
+    }
+}
diff --git a/application/resources/sailfish/qml/pages/components/StationScheduleDelegate.qml b/application/resources/sailfish/qml/pages/components/StationScheduleDelegate.qml
new file mode 100644 (file)
index 0000000..7d943b7
--- /dev/null
@@ -0,0 +1,119 @@
+import QtQuick 2.0
+import QtWebKit 3.0
+import Sailfish.Silica 1.0
+import net.cirulla.quandoparte 1.0
+
+BackgroundItem {
+    id: root
+    property variant type
+    property alias arrivalTime: arrivalTimeLabel.text
+    property alias departureTime: departureTimeLabel.text
+    property alias train: trainLabel.text
+    property string arrivalStation
+    property string departureStation
+    property alias delay: delayLabel.text
+    property string actualPlatform
+    property string expectedPlatfrom
+
+    implicitHeight: Theme.itemSizeExtraLarge
+    height: Theme.itemSizeExtraLarge
+    Item {
+        id: bodyRow
+        anchors {
+            fill: parent
+            margins: Theme.paddingSmall
+        }
+        DelayIndicator {
+            id: indicator
+            level: delayClass
+        }
+        Item {
+            anchors {
+                left: indicator.right
+                right: bodyRow.right
+                leftMargin: Theme.paddingMedium
+            }
+            Row {
+                id: firstRow
+                anchors.top: parent.top
+                spacing: Theme.paddingMedium
+                Label {
+                    id: arrivalTimeLabel
+                    font.pixelSize: Theme.fontSizeMedium
+                    visible: type === StationScheduleModel.ArrivalSchedule
+                }
+                Label {
+                    id: departureTimeLabel
+                    font.pixelSize: Theme.fontSizeMedium
+                    visible: type === StationScheduleModel.DepartureSchedule
+                }
+                Label {
+                    id: trainLabel
+                    font.pixelSize: Theme.fontSizeMedium
+                    color: Theme.highlightColor
+                }
+            }
+            Item {
+                id: secondRow
+                height: Theme.fontSizeMedium
+                anchors.top: firstRow.bottom
+                Label {
+                    text: qsTr("from %1").arg(root.arrivalStation)
+                    font.pixelSize: Theme.fontSizeMedium
+                    visible: type === StationScheduleModel.ArrivalSchedule
+                }
+                Label {
+                    text: qsTr("to %1").arg(root.departureStation)
+                    font.pixelSize: Theme.fontSizeMedium
+                    visible: type === StationScheduleModel.DepartureSchedule
+                }
+            }
+            Item {
+                height: Theme.fontSizeSmall
+                anchors {
+                    top: secondRow.bottom
+                    left: parent.left
+                    right: parent.right
+                }
+                Label {
+                    id: delayLabel
+                    anchors.top: parent.top
+                    font.pixelSize: Theme.fontSizeSmall
+                }
+                Label {
+                    anchors {
+                        top: parent.top
+                        right: parent.right
+                        rightMargin: Theme.paddingMedium
+                    }
+                    text: displayPlatform(root.expectedPlatfrom, root.actualPlatform)
+                    font.pixelSize: Theme.fontSizeSmall
+                    textFormat: Text.RichText
+                }
+            }
+        }
+    }
+    Separator {
+        anchors {
+            left: parent.left
+            right: parent.right
+        }
+    }
+    onClicked: {
+        // Load an external page about the train, for now
+        Qt.openUrlExternally(settings.queryBaseUrl + "/" + detailsUrl)
+        console.log(settings.queryBaseUrl + "/" + detailsUrl)
+    }
+    function displayPlatform(expected, actual)
+    {
+        if (actual === "--") {
+            return qsTr("Platform %1").arg(expected)
+        } else if (actual === expected || expected === "--") {
+            return qsTr("Platform <span style='font-weight:bold;color:%2'>%1</span>").arg(actual).arg("#0f0")
+        } else {
+            return qsTr("Platform " +
+                        "<span style='text-decoration:line-through'>%1</span> " +
+                        "<span style='font-weight:bold;color:%3'>%2</span>").arg(expected).arg(actual).arg("#f00")
+        }
+    }
+}