Merge branch 'master' of github.com:kelvan/gotoVienna
[pywienerlinien] / qml / MainPage.qml
index 9f1a7f7..b3582c7 100644 (file)
@@ -7,11 +7,26 @@ import "ExtrasConstants.js" as ExtrasConstants
 
 Page {
     tools: commonTools
+    orientationLock: PageOrientation.LockPortrait
 
     property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
     //property alias stationSelect: stationSelector
     property variant nearbyStations
 
+    function showFavorites() {
+        favSelector.model.clear();
+        for (var i=0; i<favManager.getCount(); i++) {
+            var data = eval('(' + favManager.getItem(i) + ')');
+            favSelector.model.append(data);
+        }
+        favSelector.model.sync();
+        favSelector.open();
+    }
+
+    function search() {
+        lineSearchButton.clicked()
+    }
+
     function refresh() {
         realtimeResult.refresh()
     }
@@ -23,13 +38,74 @@ Page {
     function showNearby() {
         console.log("show nearby")
 
-        var stations = nearbyStations
-        stationSelectorModel.clear()
+        var stations = nearbyStations;
+        stationSelectorModel.clear();
         for (var idx in stations) {
-            stationSelectorModel.append({'name': stations[idx]})
+            stationSelectorModel.append({'name': stations[idx]});
         }
 
-        stationSelector.open()
+        stationSelector.open();
+    }
+
+    Text {
+        visible: !parent.canRefresh
+        anchors.centerIn: parent
+        font.pixelSize: 30
+        text: '<p><strong>Welcome, traveller!<br></strong></p><p>Press <img src="image://theme/icon-m-toolbar-search"> to search for<br>departure information.</p><p>Press <img src="image://theme/icon-m-toolbar-view-menu"> for nearby stations.<br></p><p><strong>Have a safe journey.</strong></p>'
+    }
+
+    Rectangle {
+        id: header
+        anchors {
+            top: parent.top
+            left: parent.left
+            right: parent.right
+            margins: -1
+        }
+        border {
+            color: 'black'
+            width: 1
+        }
+
+        gradient: Gradient {
+            GradientStop { position: 0; color: '#777' }
+            GradientStop { position: 1; color: '#aaa' }
+        }
+
+        height: 80
+        color: 'white'
+
+        Image {
+            id: logo
+            source: 'logo.png'
+
+            anchors {
+                verticalCenter: parent.verticalCenter
+                left: parent.left
+                leftMargin: 10
+            }
+        }
+
+
+        ToolIcon {
+            property int increaseMeGently: 0
+            anchors {
+                verticalCenter: parent.verticalCenter
+                right: parent.right
+                rightMargin: 10
+            }
+            platformIconId: {
+                if (favManager.isFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation, increaseMeGently)) {
+                    'icon-m-toolbar-favorite-mark'
+                } else {
+                    'icon-m-toolbar-favorite-unmark'
+                }
+            }
+            onClicked: {
+                favManager.toggleFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation);
+                increaseMeGently = increaseMeGently + 1;
+            }
+        }
     }
 
     PositionSource {
@@ -53,16 +129,17 @@ Page {
 
         onAccepted: {
             realtimeResult.isStation = true
-            realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
             realtimeResult.gline = ''
             realtimeResult.sourceUrl = ''
             gline.text = ''
             gstation.text = stationSelectorModel.get(selectedIndex).name
+            realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
             console.log('station to get: ' + realtimeResult.gstation)
         }
     }
 
     TextField {
+        visible: false
         placeholderText: 'Line'
 
         id: gline
@@ -77,11 +154,6 @@ Page {
 
         onTextChanged: {
             gstation.text = ''
-
-            if (lineSelector.selectedIndex === -1) {
-                text = text.toUpperCase()
-                return
-            }
         }
 
          MouseArea {
@@ -95,11 +167,17 @@ Page {
 
     LineSheet {
         id: lineSheet
-        onAccepted: gline.text = currentLine
+        onAccepted: {
+            gline.text = currentLine
+
+            /* We usually want to select a station after selecting a line */
+            stationPickerButton.clicked()
+        }
     }
 
     Button {
         id: lineSearchButton
+        visible: false
 
         anchors {
             top: gline.top
@@ -111,12 +189,16 @@ Page {
         width: 60
         iconSource: 'image://theme/icon-m-common-search'
 
-        onClicked: lineSheet.open()
+        onClicked: {
+            lineSheet.currentLine = ''
+            lineSheet.open()
+        }
     }
 
     TextField {
         placeholderText: 'Station'
         id: gstation
+        visible: false
 
         anchors {
             top: gline.bottom
@@ -130,6 +212,18 @@ Page {
 
     StationSheet {
         id: stationSheet
+        onAccepted: {
+            gstation.text = stationSheet.currentStation
+
+            realtimeResult.gline = stationSheet.currentLine
+            realtimeResult.gdirection = stationSheet.currentDirection
+            realtimeResult.isStation = false
+            realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
+            realtimeResult.gstation = stationSheet.currentStation
+            
+            console.debug('url to get: ' + realtimeResult.sourceUrl)
+            realtimeResult.refresh()
+        }
     }
 
     Button {
@@ -142,9 +236,7 @@ Page {
             rightMargin: 10
         }
 
-        Behavior on opacity { PropertyAnimation { } }
-
-        opacity: gline.text !== '' // XXX: Check if the line is valid
+        visible: false
 
         width: lineSearchButton.width * opacity
         //iconSource: 'image://theme/icon-m-common-location-picker'
@@ -161,7 +253,7 @@ Page {
 
         anchors {
             margins: 10
-            top: gstation.bottom
+            top: header.bottom
             left: parent.left
             bottom: parent.bottom
             right: parent.right
@@ -175,5 +267,21 @@ Page {
 
         sourceUrl: stationSheet.currentUrl
     }
+
+    SelectionDialog {
+        id: favSelector
+        titleText: 'Your favorites'
+
+        model: ListModel {}
+
+        onAccepted: {
+            realtimeResult.isStation = model.get(selectedIndex).isstation
+            realtimeResult.gline = model.get(selectedIndex).gline
+            realtimeResult.gdirection = model.get(selectedIndex).gdirection
+            realtimeResult.sourceUrl = model.get(selectedIndex).sourceurl
+            realtimeResult.gstation = model.get(selectedIndex).gstation
+            realtimeResult.refresh()
+        }
+    }
 }