From: Luciano Montanaro Date: Wed, 6 Nov 2013 00:00:55 +0000 (+0100) Subject: Finished initial QML porting X-Git-Tag: tags/0.6.0~7 X-Git-Url: https://vcs.maemo.org/git/?p=quandoparte;a=commitdiff_plain;h=70e8f56a1bc285ba4c2a056cde2151836fa5f1bb Finished initial QML porting --- diff --git a/application/resources/sailfish/qml/main.qml b/application/resources/sailfish/qml/main.qml index b3d3ca9..3463613 100644 --- a/application/resources/sailfish/qml/main.qml +++ b/application/resources/sailfish/qml/main.qml @@ -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 index 0000000..a41cd3b --- /dev/null +++ b/application/resources/sailfish/qml/pages/AboutPage.qml @@ -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("

" + + "Quando Parte" + "

" +"

version ") + + settings.versionString + + "

" + + qsTr("

" + + "

Copyright (c) 2010, 2011, 2012, 2013

" + + "

Luciano Montanaro " + + "(mikelima@cirulla.net)

" + + "

Licensed under the GNU Public License v2 or above

" + + "

Station geolocation data from " + + "OpenStreetMap

" + + "

Realtime train data from " + + "Viaggiatreno

") + + "
" + onLinkActivated: Qt.openUrlExternally(link) + } + } + + } diff --git a/application/resources/sailfish/qml/pages/StationPage.qml b/application/resources/sailfish/qml/pages/StationPage.qml index 555582a..a47f69a 100644 --- a/application/resources/sailfish/qml/pages/StationPage.qml +++ b/application/resources/sailfish/qml/pages/StationPage.qml @@ -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 index 0000000..cfccfae --- /dev/null +++ b/application/resources/sailfish/qml/pages/components/DelayIndicator.qml @@ -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 index 0000000..7d943b7 --- /dev/null +++ b/application/resources/sailfish/qml/pages/components/StationScheduleDelegate.qml @@ -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 %1").arg(actual).arg("#0f0") + } else { + return qsTr("Platform " + + "%1 " + + "%2").arg(expected).arg(actual).arg("#f00") + } + } +}