diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-10 18:17:11 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-13 14:53:22 +0000 |
commit | 306ba72d81e50ccb21271fc961581d0de5ba5f49 (patch) | |
tree | 11835c89de31983eaed9d5c52d587a88a72795b1 | |
parent | 85de68468d1097a456fd3fa1009a54562795b6e3 (diff) | |
download | qtlocation-306ba72d81e50ccb21271fc961581d0de5ba5f49.tar.gz |
Replace messagebox in mapviewer with message form.
Change-Id: I19c5ac1e02aa9528c5390f4c8a934e2862400bbd
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | examples/location/mapviewer/Message.qml (renamed from examples/location/mapviewer/content/dialogs/Message.qml) | 76 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.pro | 1 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 141 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewerwrapper.qrc | 2 |
4 files changed, 62 insertions, 158 deletions
diff --git a/examples/location/mapviewer/content/dialogs/Message.qml b/examples/location/mapviewer/Message.qml index d6a5b99a..8bf01530 100644 --- a/examples/location/mapviewer/content/dialogs/Message.qml +++ b/examples/location/mapviewer/Message.qml @@ -38,72 +38,22 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtLocation.examples 5.0 +import QtQuick 2.4 +import "forms" -Item { - id: dialog +MessageForm { + property string title + property string message + property variant backPage - anchors.fill: parent + signal closeForm(variant backPage) - property alias title: titleBar.text - property alias text: message.text - property int gap: 10 - - signal okButtonClicked - signal cancelButtonClicked - opacity: 0 - enabled: opacity > 0 ? true : false - - Fader {} - - Rectangle { - id: dialogRectangle - - color: "#ECECEC" - width: parent.width - gap; - height: titleBar.height + message.height + okButton.height + gap*3 - anchors { - verticalCenter: parent.verticalCenter - left: parent.left - leftMargin: gap/2 - } - - radius: 5 - - TitleBar { - id: titleBar; - width: parent.width; height: 40; - anchors.top: parent.top; anchors.left: parent.left; - opacity: 0.9; - onClicked: { dialog.cancelButtonClicked() } - } - - Text { - id: message - anchors.horizontalCenter: parent.horizontalCenter - horizontalAlignment: Text.AlignHCenter - anchors.top: titleBar.bottom - width: dialogRectangle.width - gap - anchors.topMargin: gap - textFormat: Text.RichText - wrapMode: Text.Wrap - onLinkActivated: { - Qt.openUrlExternally(link) - } - font.pixelSize: 14 - } + button.onClicked: { + closeForm(backPage) + } - Button { - id: okButton - text: "Ok" - anchors.top: message.bottom - anchors.topMargin: gap - width: 80; height: 32 - anchors.horizontalCenter: parent.horizontalCenter - onClicked: { - dialog.okButtonClicked () - } - } + Component.onCompleted: { + messageText.text = message + messageTitle.text = title } } diff --git a/examples/location/mapviewer/mapviewer.pro b/examples/location/mapviewer/mapviewer.pro index c6839d2f..4ab8c30d 100644 --- a/examples/location/mapviewer/mapviewer.pro +++ b/examples/location/mapviewer/mapviewer.pro @@ -24,7 +24,6 @@ qmlcontentmap.files += \ OTHER_FILES += $$qmlcontentmap.files qmlcontentdialogs.files += \ - content/dialogs/Message.qml \ content/dialogs/RouteDialog.qml OTHER_FILES += $$qmlcontentdialogs.files diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index f782e08d..cbd46c55 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -65,10 +65,12 @@ ApplicationWindow { for (var i = 0; i < providerMenu.items.length; i++) { providerMenu.items[i].checked = providerMenu.items[i].text === providerName } + if (minimap) { minimap.destroy() minimap = null } + createMap(providerName) if (map.error === Map.NoError) { selectMapType(map.activeMapType) @@ -113,6 +115,20 @@ ApplicationWindow { } } + function showMessage(title,message,backPage) { + stackView.push({ item: Qt.resolvedUrl("Message.qml") , + properties: { + "title" : title, + "message" : message, + "backPage" : backPage + }}) + stackView.currentItem.closeForm.connect(closeMessage) + } + + function closeMessage(backPage) { + stackView.pop(backPage) + } + function geocodeMessage(){ var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text latitude = Math.round(map.geocodeModel.get(0).coordinate.latitude * 10000) / 10000 @@ -161,49 +177,49 @@ ApplicationWindow { onFollowmeChanged: {mainMenu.isFollowMe = map.followme}\ onSupportedMapTypesChanged: {mainMenu.mapTypeMenu.createMenu(map)}\ onCoordinatesCaptured: {\ - messageDialog.state = "Coordinates";\ - messageDialog.text = "<b>Latitude:</b> " + roundNumber(latitude,4) + "<br/><b>Longitude:</b> " + roundNumber(longitude,4);\ - page.state = "Message";\ + var text = "<b>" + qsTr("Latitude:") + "</b> " + roundNumber(latitude,4) + "<br/><b>" + qsTr("Longitude:") + "</b> " + roundNumber(longitude,4);\ + showMessage(qsTr("Coordinates"),text);\ }\ onGeocodeFinished:{\ - if (map.geocodeModel.status == GeocodeModel.Ready){\ - if (map.geocodeModel.count == 0) {messageDialog.state = "UnknownGeocodeError";}\ - else if (map.geocodeModel.count > 1) {messageDialog.state = "AmbiguousGeocode";}\ - else {messageDialog.state = "LocationInfo";}\ + if (map.geocodeModel.status == GeocodeModel.Ready) {\ + if (map.geocodeModel.count == 0) {\ + showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode"));\ + } else if (map.geocodeModel.count > 1) { \ + showMessage(qsTr("Ambiguous geocode"), map.geocodeModel.count + " " + \ + qsTr("results found for the given address, please specify location"));\ + } else { \ + showMessage(qsTr("Location"), geocodeMessage());\ + ;}\ + } else if (map.geocodeModel.status == GeocodeModel.Error) {\ + showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode")); \ }\ - else if (map.geocodeModel.status == GeocodeModel.Error) {messageDialog.state = "GeocodeError";}\ - page.state = "Message";\ }\ onShowDistance:{\ - messageDialog.state = "Distance";\ - messageDialog.text = "<b>Distance:</b> " + distance;\ - page.state = "Message";\ + showMessage(qsTr("Distance"),"<b>" + qsTr("Distance:") + "</b> " + distance);\ }\ onMoveMarker: {\ page.state = "Coordinates";\ }\ onRouteError: {\ - messageDialog.state = "RouteError";\ - page.state = "Message";\ + showMessage(qsTr("Route Error"),qsTr("Unable to find a route for the given points"));\ }\ onRequestLocale:{\ page.state = "Locale";\ }\ onShowGeocodeInfo:{\ - messageDialog.state = "LocationInfo";\ - page.state = "Message";\ + showMessage(qsTr("Location"),geocodeMessage());\ }\ onResetState: {\ page.state = "";\ }\ onErrorChanged: {\ if (map.error != Map.NoError) {\ - messageDialog.state = "ProviderError";\ - messageDialog.text = map.errorString + "<br/><br/><b>Try to select other provider</b>";\ + var title = qsTr("ProviderError");\ + var message = map.errorString + "<br/><br/><b>" + qsTr("Try to select other provider") + "</b>";\ if (map.error == Map.MissingRequiredParameterError) \ - messageDialog.text += "<br/>or see \'mapviewer --help\'\ - how to pass plugin parameters.";\ - page.state = "Message";\ + message += "<br/>" + qsTr("or see") + " \'mapviewer --help\' "\ + + qsTr("how to pass plugin parameters.");\ + showMessage(title,message);\ }\ }\ }',page) @@ -256,56 +272,6 @@ ApplicationWindow { } //=====================Dialogs===================== - Message { - id: messageDialog - z: backgroundRect.z + 2 - onOkButtonClicked: { - page.state = "" - } - onCancelButtonClicked: { - page.state = "" - } - - states: [ - State{ - name: "GeocodeError" - PropertyChanges { target: messageDialog; title: "Geocode Error" } - PropertyChanges { target: messageDialog; text: "No data available for the specified location" } - }, - State{ - name: "UnknownGeocodeError" - PropertyChanges { target: messageDialog; title: "Geocode Error" } - PropertyChanges { target: messageDialog; text: "Unsuccessful geocode" } - }, - State{ - name: "AmbiguousGeocode" - PropertyChanges { target: messageDialog; title: "Ambiguous geocode" } - PropertyChanges { target: messageDialog; text: map.geocodeModel.count + " results found for the given address, please specify location" } - }, - State{ - name: "RouteError" - PropertyChanges { target: messageDialog; title: "Route Error" } - PropertyChanges { target: messageDialog; text: "Unable to find a route for the given points"} - }, - State{ - name: "Coordinates" - PropertyChanges { target: messageDialog; title: "Coordinates" } - }, - State{ - name: "LocationInfo" - PropertyChanges { target: messageDialog; title: "Location" } - PropertyChanges { target: messageDialog; text: geocodeMessage() } - }, - State{ - name: "Distance" - PropertyChanges { target: messageDialog; title: "Distance" } - }, - State{ - name: "ProviderError" - PropertyChanges { target: messageDialog; title: "Provider Error" } - } - ] - } //Route Dialog //! [routedialog0] @@ -349,26 +315,27 @@ ApplicationWindow { } else if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)){ var st = (success == 0 ) ? "start" : "end" - messageDialog.state = "" - if ((status == GeocodeModel.Ready) && (count == 0 )) messageDialog.state = "UnknownGeocodeError" + success = 0 + map.routeModel.clearAll() + if ((status == GeocodeModel.Ready) && (count == 0 )) { + showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode")); + } else if (status == GeocodeModel.Error) { - messageDialog.state = "GeocodeError" - messageDialog.text = "Unable to find location for the " + st + " point" + showMessage(qsTr("Geocode Error"), + qsTr("Unable to find location for the") + " " + + st + " " +qsTr("point")) } else if ((status == GeocodeModel.Ready) && (count > 1 )){ - messageDialog.state = "AmbiguousGeocode" - messageDialog.text = count + " results found for the " + st + " point, please specify location" + showMessage(qsTr("Ambiguous geocode"), + count + " " + qsTr("results found for the") + + " " + st + " " +qsTr("point, please specify location")) } - success = 0 - page.state = "Message" - map.routeModel.clearAll() } } } onGoButtonClicked: { tempGeocodeModel.reset() - messageDialog.state = "" if (routeDialog.byCoordinates) { startCoordinate = QtPositioning.coordinate(parseFloat(routeDialog.startLatitude), parseFloat(routeDialog.startLongitude)); @@ -450,7 +417,6 @@ ApplicationWindow { onGoButtonClicked: { // manage the UI state transitions page.state = "" - messageDialog.state = "" // fill out the Address element geocodeAddress.street = dialogModel.get(0).inputText @@ -485,7 +451,6 @@ ApplicationWindow { onGoButtonClicked: { page.state = "" - messageDialog.state = "" map.geocodeModel.query = QtPositioning.coordinate(parseFloat(dialogModel.get(0).inputText), parseFloat(dialogModel.get(1).inputText)); map.geocodeModel.update(); @@ -509,7 +474,6 @@ ApplicationWindow { onGoButtonClicked: { page.state = "" - messageDialog.state = "" var newLat = parseFloat(dialogModel.get(0).inputText) var newLong = parseFloat(dialogModel.get(1).inputText) @@ -540,7 +504,6 @@ ApplicationWindow { onGoButtonClicked: { page.state = "" - messageDialog.state = "" map.setLanguage(dialogModel.get(0).inputText.split(Qt.locale().groupSeparator)); } @@ -568,10 +531,6 @@ ApplicationWindow { PropertyChanges { target: coordinatesDialog; opacity: 1 } }, State { - name: "Message" - PropertyChanges { target: messageDialog; opacity: 1 } - }, - State { name : "Locale" PropertyChanges { target: localeDialog; opacity: 1 } } @@ -596,10 +555,6 @@ ApplicationWindow { NumberAnimation { properties: "opacity" ; duration: 500; easing.type: Easing.Linear } }, Transition { - to: "Message" - NumberAnimation { properties: "opacity" ; duration: 500; easing.type: Easing.Linear } - }, - Transition { to: "" NumberAnimation { properties: "opacity" ; duration: 500; easing.type: Easing.Linear } } diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc index 2c1573d0..050fa7fa 100644 --- a/examples/location/mapviewer/mapviewerwrapper.qrc +++ b/examples/location/mapviewer/mapviewerwrapper.qrc @@ -8,7 +8,6 @@ <file>content/map/RectangleItem.qml</file> <file>content/map/CircleItem.qml</file> <file>content/map/PolygonItem.qml</file> - <file>content/dialogs/Message.qml</file> <file>content/dialogs/RouteDialog.qml</file> <file>content/map/ImageItem.qml</file> <file>content/map/MiniMap.qml</file> @@ -19,5 +18,6 @@ <file>forms/RouteCoordinateForm.ui.qml</file> <file>forms/RouteAddressForm.ui.qml</file> <file>forms/LocaleForm.ui.qml</file> + <file>Message.qml</file> </qresource> </RCC> |