summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-02-10 18:17:11 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2015-04-13 14:54:04 +0000
commitd9af6b61ae03a7d8e3bf3295f948bb3f2ce36d9a (patch)
treef12bf03190c112c030573e8c1a739c79ba808ecd /examples
parentfb1395c2af753d559763f79b4d75320498f30ab5 (diff)
downloadqtlocation-d9af6b61ae03a7d8e3bf3295f948bb3f2ce36d9a.tar.gz
Replace map popup menu with qtquickcontrols based one.
Change-Id: I1ce01528f260dfb7f735c2b2ab777404a5a4a5b4 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/location/mapviewer/MapPopupMenu.qml65
-rw-r--r--examples/location/mapviewer/content/map/MapComponent.qml62
-rw-r--r--examples/location/mapviewer/mapviewer.qml28
-rw-r--r--examples/location/mapviewer/mapviewerwrapper.qrc1
4 files changed, 97 insertions, 59 deletions
diff --git a/examples/location/mapviewer/MapPopupMenu.qml b/examples/location/mapviewer/MapPopupMenu.qml
new file mode 100644
index 00000000..daa388ce
--- /dev/null
+++ b/examples/location/mapviewer/MapPopupMenu.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 variant coordinate
+ property int markersCount
+ property int mapItemsCount
+ signal itemClicked(string item)
+
+
+ function update() {
+ clear()
+ addItem(qsTr("Add Marker")).triggered.connect(function(){itemClicked("addMarker")})
+ addItem(qsTr("Get coordinate")).triggered.connect(function(){itemClicked("getCoordinate")})
+ addItem(qsTr("Fit Viewport To Map Items")).triggered.connect(function(){itemClicked("fitViewport")})
+
+ if (markersCount > 0) {
+ addItem(qsTr("Delete all markers")).triggered.connect(function(){itemClicked("deleteMarkers")})
+ }
+
+ if (mapItemsCount > 0) {
+ addItem(qsTr("Delete all items")).triggered.connect(function(){itemClicked("deleteItems")})
+ }
+ }
+}
diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml
index a531f08d..a6964265 100644
--- a/examples/location/mapviewer/content/map/MapComponent.qml
+++ b/examples/location/mapviewer/content/map/MapComponent.qml
@@ -65,6 +65,7 @@ Map {
property int markerCounter: 0 // counter for total amount of markers. Resets to 0 when number of markers = 0
property int currentMarker
signal resetState()
+ signal showMainMenu(variant coordinate)
property int lastX : -1
property int lastY : -1
@@ -704,46 +705,6 @@ Map {
}
OwnControls.Menu {
- id: popupMenu
- horizontalOrientation: false
- autoWidth: true
- z: map.z + 4
- opacity: 0
-
- width: 150
- x: 0
- y: 0
-
- onClicked: {
- switch (button) {
- case "Add Marker": {
- addMarker()
- break;
- }
- case "Get coordinate": {
- map.coordinatesCaptured(mouseArea.lastCoordinate.latitude, mouseArea.lastCoordinate.longitude)
- break;
- }
- case "Fit Viewport To Map Items": {
- map.fitViewportToMapItems()
- break;
- }
-
- case "Delete all markers": {
- deleteMarkers()
- break;
- }
-
- case "Delete all items": {
- deleteMapItems()
- break;
- }
- }
- map.state = ""
- }
- }
-
- OwnControls.Menu {
id: routeMenu
horizontalOrientation: false
autoWidth: true
@@ -876,19 +837,8 @@ Map {
onPressAndHold:{
if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold
&& Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) {
- popupMenu.clear()
- popupMenu.addItem("Add Marker")
- popupMenu.addItem("Get coordinate")
- popupMenu.addItem("Fit Viewport To Map Items")
-
- if (map.markers.length>0) {
- popupMenu.addItem("Delete all markers")
- }
-
- if (map.mapItems.length>0) {
- popupMenu.addItem("Delete all items")
- }
- map.state = "PopupMenu"
+ showMainMenu(lastCoordinate);
+ map.state = ""
}
}
}
@@ -1103,12 +1053,6 @@ Map {
// states of map
states: [
State {
- name: "PopupMenu"
- PropertyChanges { target: popupMenu; opacity: 1}
- PropertyChanges { target: popupMenu; x: ((map.lastX + popupMenu.width > map.width) ? map.width - popupMenu.width : map.lastX)}
- PropertyChanges { target: popupMenu; y: ((map.lastY + popupMenu.height > map.height - 40) ? map.height - popupMenu.height - 40 : map.lastY)}
- },
- 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 )}
diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml
index e0751bbe..cc276f1c 100644
--- a/examples/location/mapviewer/mapviewer.qml
+++ b/examples/location/mapviewer/mapviewer.qml
@@ -305,6 +305,9 @@ ApplicationWindow {
showMessage(title,message);\
}\
}\
+ onShowMainMenu: {\
+ mapPopupMenu.show(coordinate);\
+ }\
}',page)
map.plugin = plugin;
map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2
@@ -338,7 +341,32 @@ ApplicationWindow {
}
}
+ MapPopupMenu {
+ id: mapPopupMenu
+ onItemClicked: {
+ stackView.pop(page)
+ if (item === "addMarker") {
+ map.addMarker()
+ } else if (item === "getCoordinate") {
+ map.coordinatesCaptured(coordinate.latitude, coordinate.longitude)
+ } else if (item === "fitViewport") {
+ map.fitViewportToMapItems()
+ } else if (item === "deleteMarkers") {
+ map.deleteMarkers()
+ } else if (item === "deleteItems") {
+ map.deleteMapItems()
+ }
+ }
+ function show(coordinate) {
+ stackView.pop(page)
+ mapPopupMenu.coordinate = coordinate
+ mapPopupMenu.markersCount = map.markers.length
+ mapPopupMenu.mapItemsCount = map.mapItems.length
+ mapPopupMenu.update()
+ mapPopupMenu.popup()
+ }
+ }
StackView {
id: stackView
diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc
index b5177a93..c1b38942 100644
--- a/examples/location/mapviewer/mapviewerwrapper.qrc
+++ b/examples/location/mapviewer/mapviewerwrapper.qrc
@@ -22,5 +22,6 @@
<file>RouteAddress.qml</file>
<file>Geocode.qml</file>
<file>ReverseGeocode.qml</file>
+ <file>MapPopupMenu.qml</file>
</qresource>
</RCC>