X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=qml%2FMainPage.qml;h=a14e48db09c9161f201f0aa1dadfeecf2474d1fc;hb=e069deef85dd16cf7070b5f1d7272a867a2a7fb3;hp=0d5e2c8c7a2c7353d7ff2698541b0f1dafa41467;hpb=76a6fc2d084d8154f7d897e4f34330af3d1c3e0c;p=pywienerlinien diff --git a/qml/MainPage.qml b/qml/MainPage.qml index 0d5e2c8..a14e48d 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -1,51 +1,64 @@ import QtQuick 1.1 import com.nokia.meego 1.0 +import QtMobility.location 1.1 + import "UIConstants.js" as UIConstants import "ExtrasConstants.js" as ExtrasConstants Page { tools: commonTools - property bool canRefresh: realtimeResult.sourceUrl != '' + property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '') + //property alias stationSelect: stationSelector + property variant nearbyStations function refresh() { realtimeResult.refresh() } - Image { - id: logo - source: 'logo.png' + function fillNearbyStations(lat, lon) { + nearbyStations = itip.get_nearby_stations(lat, lon) + } - anchors { - topMargin: 25 - top: parent.top - horizontalCenter: parent.horizontalCenter + function showNearby() { + console.log("show nearby") + + var stations = nearbyStations + stationSelectorModel.clear() + for (var idx in stations) { + stationSelectorModel.append({'name': stations[idx]}) } - } - SelectionDialog { - id: lineSelector - titleText: 'Select line' + stationSelector.open() + } - model: ListModel { - id: lineSelectorModel + PositionSource { + id: positionSource + updateInterval: 10000 - Component.onCompleted: { - var lines = itip.get_lines() + active: true - for (var idx in lines) { - lineSelectorModel.append({'name': lines[idx]}) - } - } + onPositionChanged: { + fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude) } + } + + SelectionDialog { + id: stationSelector + titleText: 'Select nearby station' - // XXX It would be nice if we could make a delegate with - // icons (i.e. U1, U2, ... in the right colors), but we - // would have to "copy" the default delegate style + model: ListModel { + id: stationSelectorModel + } onAccepted: { - console.log('accepted: ' + selectedIndex) - gline.text = lineSelectorModel.get(selectedIndex).name + realtimeResult.isStation = true + realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name + realtimeResult.gline = '' + realtimeResult.sourceUrl = '' + gline.text = '' + gstation.text = stationSelectorModel.get(selectedIndex).name + console.log('station to get: ' + realtimeResult.gstation) } } @@ -54,7 +67,7 @@ Page { id: gline anchors { - top: logo.bottom + top: parent.top left: parent.left topMargin: 20 leftMargin: 10 @@ -63,18 +76,7 @@ Page { } onTextChanged: { - // TODO: Check if text matches an item in lineSelectorModel and - // set selectedIndex in lineSelector to the right item gstation.text = '' - - if (lineSelector.selectedIndex == -1) { - return - } - - // Disable selection in line selector if user changes the text - if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) { - lineSelector.selectedIndex = -1 - } } MouseArea { @@ -86,6 +88,16 @@ Page { } } + LineSheet { + id: lineSheet + onAccepted: { + gline.text = currentLine + + /* We usually want to select a station after selecting a line */ + stationPickerButton.clicked() + } + } + Button { id: lineSearchButton @@ -99,7 +111,10 @@ Page { width: 60 iconSource: 'image://theme/icon-m-common-search' - onClicked: lineSelector.open() + onClicked: { + lineSheet.currentLine = '' + lineSheet.open() + } } TextField { @@ -116,145 +131,8 @@ Page { } } - Sheet { + StationSheet { id: stationSheet - property string currentLine: '' - property string currentDirection: '' - property string currentStation: '' - - acceptButtonText: 'Select' - rejectButtonText: 'Cancel' - - function loadData(lineName) { - stationSheet.currentLine = lineName - - directionChooser.direction1 = '' - directionChooser.direction2 = '' - - directionChooserBusyIndicator.running = true - itip.load_directions(stationSheet.currentLine) - - firstDirection.clicked() - directionChooser.checkedButton = firstDirection - } - - Connections { - target: itip - - onDirectionsLoaded: { - directionChooserBusyIndicator.running = false - - directionChooser.direction1 = itip.get_direction(0) - directionChooser.direction2 = itip.get_direction(1) - - firstDirection.clicked() - directionChooser.checkedButton = firstDirection - } - } - - content: Item { - anchors.fill: parent - - ButtonColumn { - id: directionChooser - property string direction1 - property string direction2 - - visible: !directionChooserBusyIndicator.running - - function chosen(idx) { - console.log('direction chosen: '+ idx) - - stationSelectorListView.selectedIndex = -1 - - if (idx == 1) { - stationSheet.currentDirection = directionChooser.direction1 - } else { - stationSheet.currentDirection = directionChooser.direction2 - } - - directionChooserModel.clear() - var stations = itip.get_stations(stationSheet.currentLine, stationSheet.currentDirection) - - for (var s in stations) { - directionChooserModel.append({'station': stations[s]}) - } - } - - anchors { - margins: 10 - top: parent.top - left: parent.left - right: parent.right - } - - Button { - id: firstDirection - text: 'Richtung ' + directionChooser.direction1 - onClicked: directionChooser.chosen(1) - } - - Button { - id: secondDirection - text: 'Richtung ' + directionChooser.direction2 - onClicked: directionChooser.chosen(2) - } - } - - ListView { - id: stationSelectorListView - visible: !directionChooserBusyIndicator.running - - property int selectedIndex: -1 - onSelectedIndexChanged: { - console.log('current index: ' + selectedIndex) - if (selectedIndex != -1) { - stationSheet.currentStation = directionChooserModel.get(selectedIndex).station - } else { - stationSheet.currentStation = '' - } - } - - anchors { - margins: 10 - top: directionChooser.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } - - clip: true - - model: ListModel { - id: directionChooserModel - } - - delegate: StationListItem { selector: stationSelectorListView } - } - - ScrollDecorator { - flickableItem: stationSelectorListView - } - - BusyIndicator { - id: directionChooserBusyIndicator - anchors.centerIn: parent - visible: running - platformStyle: BusyIndicatorStyle { size: 'large' } - } - } - - onAccepted: { - gstation.text = stationSheet.currentStation - - realtimeResult.gline = stationSheet.currentLine - realtimeResult.gstation = stationSheet.currentStation - realtimeResult.gdirection = stationSheet.currentDirection - - realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation) - console.log('url to get: ' + realtimeResult.sourceUrl) - - } } Button { @@ -269,7 +147,7 @@ Page { Behavior on opacity { PropertyAnimation { } } - opacity: gline.text != '' // XXX: Check if the line is valid + opacity: gline.text !== '' // XXX: Check if the line is valid width: lineSearchButton.width * opacity //iconSource: 'image://theme/icon-m-common-location-picker'