From fc0d214c412462cfd463edfe606574daac7a804b Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 10 Feb 2015 18:17:11 +0100 Subject: Replace marker popup menu in mapviewer example. Use qtquickcontrols based one. Change-Id: I36cb46aa9de076f0aea3e102802a87369d7195a7 Reviewed-by: Alex Blasche --- examples/location/mapviewer/MarkerPopupMenu.qml | 64 +++++++++++++++++++ .../mapviewer/content/map/MapComponent.qml | 74 +--------------------- examples/location/mapviewer/content/map/Marker.qml | 2 +- examples/location/mapviewer/mapviewer.qml | 39 +++++++++++- examples/location/mapviewer/mapviewerwrapper.qrc | 1 + 5 files changed, 103 insertions(+), 77 deletions(-) create mode 100644 examples/location/mapviewer/MarkerPopupMenu.qml (limited to 'examples') diff --git a/examples/location/mapviewer/MarkerPopupMenu.qml b/examples/location/mapviewer/MarkerPopupMenu.qml new file mode 100644 index 00000000..46a4ecf2 --- /dev/null +++ b/examples/location/mapviewer/MarkerPopupMenu.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 1.3 + +Menu { + property int currentMarker + property int markersCount + signal itemClicked(string item) + + function update() { + clear() + addItem(qsTr("Delete")).triggered.connect(function(){itemClicked("deleteMarker")}) + addItem(qsTr("Coordinates")).triggered.connect(function(){itemClicked("getMarkerCoordinate")}) + addItem(qsTr("Move to")).triggered.connect(function(){itemClicked("moveMarkerTo")}) + addItem(qsTr("Draw...")).triggered.connect(function(){itemClicked("showDrawMenu")}) + if (currentMarker == markersCount-2){ + addItem(qsTr("Route to next point")).triggered.connect(function(){itemClicked("routeToNextPoint")}); + addItem(qsTr("Distance to next point")).triggered.connect(function(){itemClicked("distanceToNextPoint")}); + } + if (currentMarker < markersCount-2){ + addItem(qsTr("Route to next points")).triggered.connect(function(){itemClicked("routeToNextPoints")}); + addItem(qsTr("Distance to next point")).triggered.connect(function(){itemClicked("distanceToNextPoint")}); + } + } +} diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml index a6964265..ae59ffd0 100644 --- a/examples/location/mapviewer/content/map/MapComponent.qml +++ b/examples/location/mapviewer/content/map/MapComponent.qml @@ -66,6 +66,7 @@ Map { property int currentMarker signal resetState() signal showMainMenu(variant coordinate) + signal showMarkerMenu(variant coordinate) property int lastX : -1 property int lastY : -1 @@ -74,7 +75,6 @@ Map { property int jitterThreshold : 30 property bool followme: false property variant scaleLengths: [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000] - signal showDistance(string distance); signal requestLocale() /* @todo @@ -620,48 +620,6 @@ Map { scaleTimer.restart() } - OwnControls.Menu { - id: markerMenu - horizontalOrientation: false - autoWidth: true - z: map.z + 4 - opacity: 0 - - width: 150 - x: 0 - y: 0 - onClicked: { - map.state = "" - switch (button) { - case "Delete": {//remove marker - map.deleteMarker(currentMarker) - break; - } - case "Move to": {//move marker - map.moveMarker() - break; - } - case "Coordinates": {//show marker's coordinates - map.coordinatesCaptured(markers[currentMarker].coordinate.latitude, markers[currentMarker].coordinate.longitude) - break; - } - case "Distance to next point": { - showDistance(formatDistance(map.markers[currentMarker].coordinate.distanceTo(map.markers[currentMarker+1].coordinate))); - break; - } - case "Route to next points"://calculate route - case "Route to next point": { - map.calculateRoute() - break; - } - case "Draw...": { - map.drawItemPopup() - break; - } - } - } - } - OwnControls.Menu { id: drawMenu horizontalOrientation: false @@ -951,30 +909,6 @@ Map { if (markers.length == 0) markerCounter = 0 } - function markerPopup(){ - var array - var length = map.markers.length - - markerMenu.clear() - markerMenu.addItem("Delete") - markerMenu.addItem("Coordinates") - markerMenu.addItem("Move to") - markerMenu.addItem("Draw...") - - - if (currentMarker == length-2){ - markerMenu.addItem("Route to next point") - markerMenu.addItem("Distance to next point") - - } - if (currentMarker < length-2){ - markerMenu.addItem("Route to next points") - markerMenu.addItem("Distance to next point") - } - map.state = "MarkerPopupMenu" - } - - function drawItemPopup(){ var array var length = map.markers.length @@ -1052,12 +986,6 @@ Map { // states of map states: [ - State { - name: "MarkerPopupMenu" - PropertyChanges { target: markerMenu; opacity: 1} - PropertyChanges { target: markerMenu; x: ((markers[currentMarker].lastMouseX + markerMenu.width > map.width) ? map.width - markerMenu.width : markers[currentMarker].lastMouseX )} - PropertyChanges { target: markerMenu; y: ((markers[currentMarker].lastMouseY + markerMenu.height > map.height - 40) ? map.height - markerMenu.height - 40 : markers[currentMarker].lastMouseY)} - }, State { name: "DrawItemMenu" PropertyChanges { target: drawMenu; opacity: 1} diff --git a/examples/location/mapviewer/content/map/Marker.qml b/examples/location/mapviewer/content/map/Marker.qml index 0611fca1..730b62f1 100644 --- a/examples/location/mapviewer/content/map/Marker.qml +++ b/examples/location/mapviewer/content/map/Marker.qml @@ -88,7 +88,7 @@ MapQuickItem { var p = map.fromCoordinate(marker.coordinate) lastX = p.x lastY = p.y - map.markerPopup() + map.showMarkerMenu(marker.coordinate) } } } diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index cc276f1c..993439c3 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -69,6 +69,7 @@ ApplicationWindow { postalCode: "" } + Address { id: toAddress street: "Heal st" @@ -277,9 +278,6 @@ ApplicationWindow { showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode")); \ }\ }\ - onShowDistance:{\ - showMessage(qsTr("Distance"),"" + qsTr("Distance:") + " " + distance);\ - }\ onMoveMarker: {\ page.state = "Coordinates";\ }\ @@ -308,6 +306,9 @@ ApplicationWindow { onShowMainMenu: {\ mapPopupMenu.show(coordinate);\ }\ + onShowMarkerMenu: {\ + markerPopupMenu.show(coordinate);\ + }\ }',page) map.plugin = plugin; map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2 @@ -368,6 +369,38 @@ ApplicationWindow { } } + MarkerPopupMenu { + id: markerPopupMenu + onItemClicked: { + stackView.pop(page) + if (item === "deleteMarker") { + map.deleteMarker(map.currentMarker) + } else if (item === "getMarkerCoordinate") { + map.coordinatesCaptured(map.markers[map.currentMarker].coordinate.latitude, map.markers[map.currentMarker].coordinate.longitude) + } else if (item === "moveMarkerTo") { + map.moveMarker() + } else if (item === "showDrawMenu") { + map.drawItemPopup() + } else if (item === "routeToNextPoint" || item === "routeToNextPoints") { + map.calculateRoute() + } else if (item === "distanceToNextPoint") { + var coordinate1 = map.markers[currentMarker].coordinate; + var coordinate2 = map.markers[currentMarker+1].coordinate; + var distance = map.formatDistance(coordinate1.distanceTo(coordinate2)); + showMessage(qsTr("Distance"),"" + qsTr("Distance:") + " " + distance) + } + } + + function show(coordinate) { + stackView.pop(page) + markerPopupMenu.markersCount = map.markers.length + markerPopupMenu.update() + markerPopupMenu.popup() + } + + } + + StackView { id: stackView anchors.fill: parent diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc index c1b38942..ba45e928 100644 --- a/examples/location/mapviewer/mapviewerwrapper.qrc +++ b/examples/location/mapviewer/mapviewerwrapper.qrc @@ -23,5 +23,6 @@ Geocode.qml ReverseGeocode.qml MapPopupMenu.qml + MarkerPopupMenu.qml -- cgit v1.2.1