diff options
author | juhvu <qt-info@nokia.com> | 2011-09-21 16:17:30 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-26 03:28:10 +0200 |
commit | cf89ceb0f5ef41866e23a35ebf8abfa3584f9626 (patch) | |
tree | 3bd9900e9261547f4af7731f333072dd6e41aa1a | |
parent | 33a7f66bf3c1fca16fab6303cbc104d5141e7321 (diff) | |
download | qtlocation-cf89ceb0f5ef41866e23a35ebf8abfa3584f9626.tar.gz |
Added MapMouseArea support (still needs a commit to declarative).
Change-Id: I04cdb018b7d8702f281e25a8cbd53e4af4f3cfca
Reviewed-on: http://codereview.qt-project.org/5284
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
18 files changed, 2443 insertions, 564 deletions
diff --git a/examples/declarative/map3d/map3d.pro b/examples/declarative/map3d/map3d.pro index 555b276d..16ad1c66 100644 --- a/examples/declarative/map3d/map3d.pro +++ b/examples/declarative/map3d/map3d.pro @@ -1,7 +1,7 @@ TARGET = qml_location_map3d TEMPLATE=app -QT += declarative network +QT += declarative network widgets SOURCES += qmlmap3d.cpp diff --git a/examples/declarative/map3d/map3d.qrc b/examples/declarative/map3d/map3d.qrc index 3b5e4e1f..9cc8af12 100644 --- a/examples/declarative/map3d/map3d.qrc +++ b/examples/declarative/map3d/map3d.qrc @@ -1,6 +1,7 @@ <RCC> <qresource prefix="/"> <file>map3d.qml</file> + <file>map3d_mousetest.qml</file> <file>Dialog.qml</file> <file>common/TitleBar.qml</file> <file>common/Button.qml</file> diff --git a/examples/declarative/map3d/map3d_mousetest.qml b/examples/declarative/map3d/map3d_mousetest.qml new file mode 100644 index 00000000..a5aa6549 --- /dev/null +++ b/examples/declarative/map3d/map3d_mousetest.qml @@ -0,0 +1,1058 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Mobility Components. +** +** $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 Nokia Corporation and its Subsidiary(-ies) 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.0 +import Qt.location 5.0 +import Qt.location.test 5.0 +import "common" as Common + +Item { + objectName: "The page." + width: 1140 //360 + height: 1085 // 640 + //width: 360 + //height: 640 + id: page + + //Rectangle { + // id: bottleAnimation + // width: animation.width; height: animation.height + 8 + // } + + // From location.test plugin + TestModel { + id: testModel + datatype: 'coordinate' + datacount: 8 + delay: 0 + crazyMode: false // generate arbitrarily updates. interval is set below, and the number of items is varied between 0..datacount + crazyLevel: 2000 // the update interval varies between 3...crazyLevel (ms) + } + + Item { + visible: false + id: shaderItem + width: 256 + height: 256 + x: 100 + y: 100 + Rectangle { + radius: 20 + id: shaderRect + width: parent.width + height: parent.height/4 + color: 'red' + z: 1 + Text {text: "Wicked!"} + + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { from: "DeepSkyBlue"; to: "red"; duration: 2000 } + ColorAnimation { from: "red"; to: "DeepSkyBlue"; duration: 2000 } + } + } + Rectangle { + id: shaderRect2 + opacity: 0.5 + //width: parent.width + anchors.fill: shaderRect + //height: parent.height/4 + color: 'green' + Text {text: "Sick!"} + } + Rectangle { + id: shaderRect3 + width: parent.width + anchors.top: shaderRect2.bottom + height: parent.height/4 + color: 'blue' + Text {text: "Sick!"} + } + Rectangle { + width: parent.width + anchors.top: shaderRect3.bottom + height: parent.height/4 + color: 'yellow' + Text {text: "Sick!"} + } + } + + Column { + id: buttonColumn + anchors.top: page.top + anchors.left: map.right + spacing: 2 + + Rectangle {color: "lightblue"; width: 80; height: 80; + Text {text: "Crazy mode:\n" + testModel.crazyMode + "\nclick to\ntoggle."} + MouseArea{ anchors.fill: parent; + onClicked: testModel.crazyMode = !testModel.crazyMode + onDoubleClicked: map.removeMapItem(mapItem1) + } + } + AnimatedImage { + MouseArea { anchors.fill: parent; onClicked: mapItem2.source = parent } + width: 80 + height: 80 + playing: testModel.crazyMode + source: "blinky.gif" + } + Rectangle {color: "lightblue"; width: 80; height: 80; + Text {text: "Click:\nadd item1\nDouble-click:\nrm item1"} + MouseArea{ anchors.fill: parent; + onClicked: {console.log('oooQML: ----------------adding item 1'); map.addMapItem(externalStaticMapItem1);} + onDoubleClicked: {console.log('oooQML: +++++++++++++++ removing item 1'); map.removeMapItem(externalStaticMapItem1);} + } + } + Rectangle {color: "lightblue"; width: 80; height: 80; + Text {text: "Click:\nadd item2\nDouble-click:\nrm item2"} + MouseArea{ anchors.fill: parent; + onClicked: {console.log('oooQML: adding item 2'); map.addMapItem(externalStaticMapItem2);} + onDoubleClicked: {console.log('oooQML: removing item 2'); map.removeMapItem(externalStaticMapItem2);} + } + } + } + + /* + MapItem { + id: externalStaticMapItem1 + objectName: "externalStaticMapItem1" + coordinate: brisbaneCoordinate + zoomLevel: 5.0 + source: Rectangle { + color: "gray" + width: 140 + height: 20 + Text {font.pixelSize: 15;text: "ext map item 1"; font.bold: true; color: 'red'} + } + } + + MapItem { + id: externalStaticMapItem2 + objectName: "externalStaticMapItem2" + coordinate: brisbaneCoordinate2 + zoomLevel: 5.0 + source: Rectangle { + color: "gray" + width: 140 + height: 20 + Text {font.pixelSize: 15;text: "ext map item 2"; font.bold: true; color: 'red'} + } + } + */ + + /* + MapItem { + id: mapItem1 + source: AnimatedImage {width: 80; height: 80; playing: true; source: "walk.gif"} + } + */ + + //AnimatedImage {width: 80; height: 80; playing: true; source: "walk.gif"} + //MapItem {id: mapItem2 } + //MapItem {id: mapItem3 } + //MapItem {id: mapItem4 } + //MapItem {id: mapItem5 } + //MapItem {id: mapItem6 } + //MapItem {id: mapItem7 } + //MapItem {id: mapItem8 } + + Coordinate { + id: brisbaneCoordinate + latitude: -27.5 + longitude: 140 + } + + Coordinate { + id: brisbaneCoordinate2 + latitude: -30.5 + longitude: 140 + } + + Map { + id: map + /* + MapItem { + objectName: 'blinky static item' + zoomLevel: 7 // at which map's zoom level the width and height are '1-to-1' + coordinate: brisbaneCoordinate + source: AnimatedImage { + width: 80 + height: 80 + playing: true + source: "blinky.gif" + } + } + */ + + + //MapItem { + // source: Rectangle { width: 40; height: 40; color: 'chocolate' + // } + // } + /* + MapObjectView { + id: theObjectView + model: testModel + delegate: Component { + MapItem { + objectName: 'one of many items from model' + visible: true + live: true + recursive: true + source: Rectangle { + width: 300; height: 300; color: 'green' + Component.onCompleted: { + var num = (Math.floor(4 * Math.random())); + switch (num % 4) { + case 0: + color = "#ff0000"; + break; + case 1: + color = "#0000ff"; + break; + case 2: + color = "#00ffff"; + break; + case 3: + color = "#00ff00"; + break; + } + } + + } + coordinate: Coordinate { + latitude: modeldata.coordinate.latitude; + longitude: modeldata.coordinate.longitude; + } + } + } + } + */ + + // From location.test plugin + PinchGenerator { + id: pinchGenerator + anchors.fill: parent + target: map + enabled: false + focus: true // enables keyboard control for convinience + replaySpeedFactor: 1.1 // replay with 1.1 times the recording speed to better see what happens + Text { + text: "PinchArea state: " + pinchGenerator.state + "\n" + + "Swipes recorded: " + pinchGenerator.count + "\n" + + "Replay speed factor: " + pinchGenerator.replaySpeedFactor + } + } + /* + Keys.onPressed: { + if (event.key == Qt.Key_A) { + console.log('oooQML: Key A was pressed'); + //event.accepted = true; + } + } + */ + plugin : Plugin {name : "nokia"} + // commented features are checked to work at least somehow + x: 0 + y: 0 + //size.width: 100 + //size.height: 100 + //anchors.left: parent.left + //anchors.bottom: parent.bottom + //anchors.leftMargin: 70 + //scale: 2 + //visible: false + //transform: Translate {y: 200} + //anchors.fill: page + width: page.width - 80 + height: 800 + zoomLevel: 5.1 + + // pinch.activeGestures: MapPinch.ZoomGesture | RotationGesture + pinch.activeGestures: MapPinch.NoGesture + + pinch.enabled: true + pinch.maximumZoomLevel: 20 // biggest zoomlevel allowed + pinch.minimumZoomLevel: 1 // smallest zoomlevel allowed + pinch.maximumZoomLevelChange: 1.0 // maximum zoomlevel changes per pinch + pinch.maximumRotation: 0 // unlimited + pinch.minimumRotation: 0 // unlimited + pinch.rotationSpeed: 1.0 // default ~follows angle between fingers + pinch.maximumTilt: 90 + pinch.minimumTilt: 0 + pinch.maximumTiltChange: 35 + + // Flicking + flick.enabled: true + flick.deceleration: 3000 + flick.onFlickStarted: {console.log ('flick started signal F Start ++++++++++++++++++ ') } + flick.onFlickEnded: {console.log ('flick ended signal F Stop ------------------ ') } + flick.onMovementStarted: {console.log('oooQML: movement started signal M Start ++++++++++++++++++ ') } + flick.onMovementEnded: {console.log ('movement ended signal M Stop ------------------ ') } + + + onWheel: { + console.log('oooQML: map wheel event, rotation in degrees: ' + delta/8); + if (delta > 0) map.zoomLevel += 0.25 + else map.zoomLevel -= 0.25 + } + + pinch.onPinchStarted: { + console.log('oooQML: Map element pinch started---------+++++++++++++++++++++++++++++++++++++') + pinchRect1.x = pinch.point1.x; pinchRect1.y = pinch.point1.y; + pinchRect2.x = pinch.point2.x; pinchRect2.y = pinch.point2.y; + pinchRect1.visible = true; pinchRect2.visible = true; + //console.log('oooQML: Point 1 x: ' + pinch.point1.x + ' Point2 x' + pinch.point2.x) + //console.log('oooQML: Center x: ' + pinch.center.x + ' Point1 y: ' + pinch.point1.y) + } + pinch.onPinchUpdated: { + console.log('oooQML: Map element pinch updated---------+++++++++++++++++++++++++++++++++++++') + pinchRect1.x = pinch.point1.x; pinchRect1.y = pinch.point1.y; + pinchRect2.x = pinch.point2.x; pinchRect2.y = pinch.point2.y; + } + pinch.onPinchFinished: { + console.log('oooQML: Map element pinch finished ---------+++++++++++++++++++++++++++++++++++++') + pinchRect1.visible = false; pinchRect2.visible = false; + //map.pinch.minimumZoomLevel = map.zoomLevel - 2 + //map.pinch.maximumZoomLevel = map.zoomLevel + 2 + } + + + Rectangle { + id: mouseRectUpper + color: 'green' + border.color: "yellow" + border.width: 5 + radius: 10 + opacity: 0.2 + x: 0; y: 0; + width: map.width; + height: map.height / 2 + Text { text: ' upper MapMouseArea'} + } + + MapMouseArea { + id: mouseAreaOfMap + objectName: 'map mouse area' + x: 0; y: 0; + width: map.width; + height: map.height / 2; + + onAcceptedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea acceptedButtonsChanged: ' + mouseAreaOfMap.acceptedButtons + ' ' + acceptedButtons) + } + onEnabledChanged: { + console.log('oooQML: in QML MapMouseArea enabledChanged: ' + mouseAreaOfMap.enabled) + } + onPressed: { + console.log('oooQML: in QML MapMouseArea pressed: ' + + mouse.x + ' y:' + mouse.y + ' pressed: ' + + pressed + ' mouseX: ' + mouseAreaOfMap.mouseX + ' mouseY: ' + mouseAreaOfMap.mouseY + ' button: ' + mouse.button + ' buttons: ' + mouse.buttons) + } + onPressedChanged: { + console.log('oooQML: in QML MapMouseArea pressedChanged, pressedButtons: ' + mouseAreaOfMap.pressedButtons) + } + onPressedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea pressedButtonChanged ' + ' pressed button: ' + mouseAreaOfMap.pressedButtons) + } + onReleased: { + console.log('oooQML: in QML MapMouseArea released: ' + mouse.x + ' y: ' + mouse.y) + } + onDoubleClicked: { + console.log('oooQML: in QML MapMouseArea doubleclicked---------------------------------------- dump event: ') + console.log('oooQML: accepted: ' + mouse.accepted); + console.log('oooQML: button: ' + mouse.button); + console.log('oooQML: modifiers: ' + mouse.modifiers); + console.log('oooQML: wasHeld: ' + mouse.wasHeld); + console.log('oooQML: latitude: ' + mouse.latitude); + console.log('oooQML: longitude: ' + mouse.longitude); + console.log('oooQML: x: ' + mouse.x); + console.log('oooQML: y: ' + mouse.y); + console.log('oooQML: mouse area x,y, width, height: ' + mouseAreaOfMap.x + ' ' + mouseAreaOfMap.y + ' ' + mouseAreaOfMap.width + ' ' + mouseAreaOfMap.height) + + console.log('oooQML: in QML MapMouseArea doubleclicked---------------------------------------- end dump ') + } + onClicked: { + console.log('oooQML: in QML MapMouseArea clicked') + } + onPositionChanged: { + console.log('oooQML: in QML MapMouseArea position changed, x: ' + mouse.x + ' y: ' + mouse.y + + ' mouseX: ' + mouseAreaOfMap.mouseX + ' mouseY: ' + mouseAreaOfMap.mouseY + ' button: ' + mouse.button + ' buttons: ' + mouse.buttons) + } + onEntered: { + console.log('oooQML: in QML MapMouseArea entered') + } + onExited: { + console.log('oooQML: in QML MapMouseArea exited') + } + onPressAndHold: { + console.log('oooQML: in QML MapMouseArea press and hold') + } + // This signal is not officially public per se, but used to notify containsMouse changes + onHoveredChanged: { + console.log('oooQML: in QML MapMouseArea hoveredChanged, containsMouse is: ' + mouseAreaOfMap.containsMouse) + } + } + + Rectangle { + id: mouseRectLower + color: 'green' + border.color: "yellow" + border.width: 5 + radius: 10 + opacity: 0.2 + x: 0; y: map.height/2; + width: map.width; + height: map.height/2; + Text { text: ' lower MapMouseArea'} + } + + MapMouseArea { + id: mouseAreaOfMap2 + objectName: 'map mouse area 2' + x: 0; y: map.height/2; + width: map.width; + height: map.height/2; + + onAcceptedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea2 acceptedButtonsChanged: ' + mouseAreaOfMap2.acceptedButtons + ' ' + acceptedButtons) + } + onEnabledChanged: { + console.log('oooQML: in QML MapMouseArea2 enabledChanged: ' + mouseAreaOfMap2.enabled) + } + onPressed: { + console.log('oooQML: in QML MapMouseArea2 pressed: ' + + mouse.x + ' y:' + mouse.y + ' pressed: ' + + pressed + ' mouseX: ' + mouseAreaOfMap2.mouseX + ' mouseY: ' + mouseAreaOfMap2.mouseY) + } + onPressedChanged: { + console.log('oooQML: in QML MapMouseArea2 pressedChanged, pressedButtons: ' + mouseAreaOfMap2.pressedButtons) + } + onPressedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea2 pressedButtonChanged ' + ' pressed button: ' + mouseAreaOfMap2.pressedButtons) + } + onReleased: { + console.log('oooQML: in QML MapMouseArea2 released: ' + mouse.x + ' y: ' + mouse.y) + } + onDoubleClicked: { + console.log('oooQML: in QML MapMouseArea2 doubleclicked---------------------------------------- dump event: ') + console.log('oooQML: accepted: ' + mouse.accepted); + console.log('oooQML: button: ' + mouse.button); + console.log('oooQML: modifiers: ' + mouse.modifiers); + console.log('oooQML: wasHeld: ' + mouse.wasHeld); + console.log('oooQML: latitude: ' + mouse.latitude); + console.log('oooQML: longitude: ' + mouse.longitude); + console.log('oooQML: x: ' + mouse.x); + console.log('oooQML: y: ' + mouse.y); + console.log('oooQML: mouse area x,y, width, height: ' + mouseAreaOfMap2.x + ' ' + mouseAreaOfMap2.y + ' ' + mouseAreaOfMap2.width + ' ' + mouseAreaOfMap2.height) + + console.log('oooQML: in QML MapMouseArea2 doubleclicked---------------------------------------- end dump ') + } + onClicked: { + console.log('oooQML: in QML MapMouseArea2 clicked') + } + onPositionChanged: { + console.log('oooQML: in QML MapMouseArea2 position changed, x: ' + mouse.x + ' y: ' + mouse.y + + ' mouseX: ' + mouseAreaOfMap2.mouseX + ' mouseY: ' + mouseAreaOfMap2.mouseY) + } + onEntered: { + console.log('oooQML: in QML MapMouseArea2 entered') + } + onExited: { + console.log('oooQML: in QML MapMouseArea2 exited') + } + onPressAndHold: { + console.log('oooQML: in QML MapMouseArea2 press and hold') + } + // This signal is not officially public per se, but used to notify containsMouse changes + onHoveredChanged: { + console.log('oooQML: in QML MapMouseArea2 hoveredChanged, containsMouse is: ' + mouseAreaOfMap2.containsMouse) + } + } + + // overlaps both mouse areas 1 and 2 (rhs) + Rectangle { + id: mouseRectRightOverlapping + color: 'green' + border.color: "red" + border.width: 5 + radius: 10 + opacity: 0.2 + x: map.width/2; y: 0; + width: map.width/2; + height: map.height; + Text { text: 'overlapping MapMouseArea'} + } + + MapMouseArea { + id: mouseAreaOfMap3 + objectName: 'map mouse area 3' + x: map.width/2; y: 0; + width: map.width/2; + height: map.height; + + onAcceptedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea3 acceptedButtonsChanged: ' + mouseAreaOfMap3.acceptedButtons + ' ' + acceptedButtons) + } + onEnabledChanged: { + console.log('oooQML: in QML MapMouseArea3 enabledChanged: ' + mouseAreaOfMap3.enabled) + } + onPressed: { + console.log('oooQML: in QML MapMouseArea3 pressed: ' + + mouse.x + ' y:' + mouse.y + ' pressed: ' + + pressed + ' mouseX: ' + mouseAreaOfMap3.mouseX + ' mouseY: ' + mouseAreaOfMap3.mouseY) + } + onPressedChanged: { + console.log('oooQML: in QML MapMouseArea3 pressedChanged, pressedButtons: ' + mouseAreaOfMap3.pressedButtons) + } + onPressedButtonsChanged: { + console.log('oooQML: in QML MapMouseArea3 pressedButtonChanged ' + ' pressed button: ' + mouseAreaOfMap3.pressedButtons) + } + onReleased: { + console.log('oooQML: in QML MapMouseArea3 released: ' + mouse.x + ' y: ' + mouse.y) + } + onDoubleClicked: { + console.log('oooQML: in QML MapMouseArea3 doubleclicked---------------------------------------- dump event: ') + console.log('oooQML: accepted: ' + mouse.accepted); + console.log('oooQML: button: ' + mouse.button); + console.log('oooQML: modifiers: ' + mouse.modifiers); + console.log('oooQML: wasHeld: ' + mouse.wasHeld); + console.log('oooQML: latitude: ' + mouse.latitude); + console.log('oooQML: longitude: ' + mouse.longitude); + console.log('oooQML: x: ' + mouse.x); + console.log('oooQML: y: ' + mouse.y); + console.log('oooQML: mouse area x,y, width, height: ' + mouseAreaOfMap3.x + ' ' + mouseAreaOfMap3.y + ' ' + mouseAreaOfMap3.width + ' ' + mouseAreaOfMap3.height) + console.log('oooQML: in QML MapMouseArea3 doubleclicked---------------------------------------- end dump ') + } + onClicked: { + console.log('oooQML: in QML MapMouseArea3 clicked') + } + onPositionChanged: { + console.log('oooQML: in QML MapMouseArea3 position changed, x: ' + mouse.x + ' y: ' + mouse.y + + ' mouseX: ' + mouseAreaOfMap3.mouseX + ' mouseY: ' + mouseAreaOfMap3.mouseY) + } + onEntered: { + console.log('oooQML: in QML MapMouseArea3 entered') + } + onExited: { + console.log('oooQML: in QML MapMouseArea3 exited') + } + onPressAndHold: { + console.log('oooQML: in QML MapMouseArea3 press and hold') + } + // This signal is not officially public per se, but used to notify containsMouse changes + onHoveredChanged: { + console.log('oooQML: in QML MapMouseArea3 hoveredChanged, containsMouse is: ' + mouseAreaOfMap3.containsMouse) + } + } + + + //focus : true + center: Coordinate { + latitude: 51.5 + longitude: -0.11 + } + // <unsupported so far> + //rotation: 10 // strangely impacts the size of the map element though + //transform: Scale { origin.x: 25; origin.y: 25; xScale: 3} // weirdly translates the item + //transform: Rotation { origin.y: 25; origin.x: 25; angle: 45} // weirdly translates the item + //z: 4 // map will always be under everything, will not be supported + //opacity: 0.4 // doesn't probably make sense + //clip: true // not implemented, not sure if very useful either + // </unsupported so far> + } + + Rectangle { + id: referenceMouseAreaRectangleUpper + color: 'steelblue' + border.color: "black" + border.width: 5 + radius: 10 + width: 250 + height: 150 + x: map.width - 250 + y: map.height- 300 + Text { text: " Reference mouse area upper\n (the main reference area)"} + MouseArea { + anchors.fill: parent; + id: referenceMouseAreaUpper + objectName: 'referenceMouseAreaUpper' + + onAcceptedButtonsChanged: { + console.log('oooQML: in QML Reference MouseArea upper acceptedButtonsChanged: ' + referenceMouseAreaUpper.acceptedButtons) + } + onEnabledChanged: { + console.log('oooQML: in QML Reference MouseArea upper enabledChanged: ' + referenceMouseAreaUpper.enabled) + } + onPressed: { + console.log('oooQML: in QML Reference MouseArea upper pressed: ' + mouse.x + ' y:' + mouse.y + ' pressed: ' + pressed) + } + onPressedChanged: { + console.log('oooQML: in QML Reference MouseArea upper pressedChanged ' + ' pressed button: ' + referenceMouseAreaUpper.pressedButtons) + } + onReleased: { + console.log('oooQML: in QML Reference MouseArea upper released: ' + mouse.x + ' y: ' + mouse.y) + } + onDoubleClicked: { + console.log('oooQML: in QML mouse area doubleclicked---------------------------------------- dump event: ') + console.log('oooQML: accepted: ' + mouse.accepted); + console.log('oooQML: button: ' + mouse.button); + console.log('oooQML: modifiers: ' + mouse.modifiers); + console.log('oooQML: wasHeld: ' + mouse.wasHeld); + console.log('oooQML: latitude: ' + mouse.latitude); + console.log('oooQML: longitude: ' + mouse.longitude); + console.log('oooQML: x: ' + mouse.x); + console.log('oooQML: y: ' + mouse.y); + console.log('oooQML: in QML Reference MouseArea upper doubleclicked---------------------------------------- end dump ') + } + onClicked: { + console.log('oooQML: in QML Reference MouseArea upper clicked') + } + onPositionChanged: { + console.log('oooQML: in QML MouseArea upper reference position changed, x: ' + mouse.x + ' y: ' + mouse.y) + } + onEntered: { + console.log('oooQML: in QML Reference upper MouseArea entered') + } + onExited: { + console.log('oooQML: in QML Reference MouseArea upper exited') + } + onPressAndHold: { + console.log('oooQML: in QML Reference MouseArea upper press and hold') + } + // This signal is not officially public per se, but used to notify containsMouse changes + onHoveredChanged: { + console.log('oooQML: in QML Reference MouseArea upper hoveredChanged, containsMouse is: ' + referenceMouseAreaUpper.containsMouse) + } + } + } + + Rectangle { + id: referenceMouseAreaRectangleLower + color: 'steelblue' + border.color: "black" + border.width: 5 + radius: 10 + width: 250 + height: 150 + anchors.top: referenceMouseAreaRectangleUpper.bottom + anchors.left: referenceMouseAreaRectangleUpper.left + Text { text: " Reference mouse area lower"} + MouseArea { + anchors.fill: parent; + id: referenceMouseAreaLower + objectName: 'referenceMouseAreaLower' + onClicked: console.log('oooQML: clicked: ' + referenceMouseAreaLower.objectName) + + onPositionChanged: { + console.log('oooQML: in QML MouseArea lower reference position changed, x: ' + mouse.x + ' y: ' + mouse.y) + } + onEntered: { + console.log('oooQML: in QML Reference lower MouseArea entered') + } + onExited: { + console.log('oooQML: in QML Reference MouseArea lower exited') + } + + } + } + + Rectangle { + id: referenceMouseAreaRectangleOverlapping + color: 'red' + border.color: "black" + border.width: 5 + radius: 10 + opacity: 0.5 + z: 30 + width: referenceMouseAreaRectangleUpper.width / 2 + height: referenceMouseAreaRectangleUpper.height * 2 + //width: 100 + //height: 100 + //x: 100 + //y: 100 + x: referenceMouseAreaRectangleUpper.x + 150 + y: referenceMouseAreaRectangleUpper.y + Text { text: " Reference\nmouse\noverlap"} + MouseArea { + anchors.fill: parent; + id: referenceMouseAreaOverlapping + objectName: 'referenceMouseAreaOverLapping' + + onAcceptedButtonsChanged: { + console.log('oooQML: in QML Reference MouseArea OL acceptedButtonsChanged: ' + referenceMouseAreaUpper.acceptedButtons) + } + onEnabledChanged: { + console.log('oooQML: in QML Reference MouseArea OL enabledChanged: ' + referenceMouseAreaUpper.enabled) + } + onPressed: { + console.log('oooQML: in QML Reference MouseArea OL pressed: ' + mouse.x + ' y:' + mouse.y + ' pressed: ' + pressed) + } + onPressedChanged: { + console.log('oooQML: in QML Reference MouseArea OL pressedChanged ' + ' pressed button: ' + referenceMouseAreaUpper.pressedButtons) + } + onReleased: { + console.log('oooQML: in QML Reference MouseArea OL released: ' + mouse.x + ' y: ' + mouse.y) + } + onDoubleClicked: { + console.log('oooQML: in QML mouse area doubleclicked---------------------------------------- dump event: ') + console.log('oooQML: accepted: ' + mouse.accepted); + console.log('oooQML: button: ' + mouse.button); + console.log('oooQML: modifiers: ' + mouse.modifiers); + console.log('oooQML: wasHeld: ' + mouse.wasHeld); + console.log('oooQML: latitude: ' + mouse.latitude); + console.log('oooQML: longitude: ' + mouse.longitude); + console.log('oooQML: x: ' + mouse.x); + console.log('oooQML: y: ' + mouse.y); + console.log('oooQML: in QML Reference MouseArea doubleclicked---------------------------------------- end dump ') + } + onClicked: { + console.log('oooQML: in QML Reference MouseArea OL clicked') + } + onPositionChanged: { + console.log('oooQML: in QML MouseArea OL reference position changed, x: ' + mouse.x + ' y: ' + mouse.y) + } + onEntered: { + console.log('oooQML: in QML Reference MouseArea OL entered') + } + onExited: { + console.log('oooQML: in QML Reference MouseArea OL exited') + } + onPressAndHold: { + console.log('oooQML: in QML Reference MouseArea OL press and hold') + } + // This signal is not officially public per se, but used to notify containsMouse changes + onHoveredChanged: { + console.log('oooQML: in QML Reference MouseArea OL hoveredChanged, containsMouse is: ' + referenceMouseAreaUpper.containsMouse) + } + } + } + + Row { + id: buttonRow + anchors.leftMargin: 2 + anchors.topMargin: 2 + anchors.top: map.bottom; + spacing: 2 + Rectangle { id: rowRect1; width: 80; height: 65; color: 'peru'; + MouseArea { anchors.fill: parent; onClicked: { map.pinch.maximumZoomLevelChange += 0.1} + Text {text: "Pinch zoom\nsensitivity+"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.pinch.maximumZoomLevelChange -= 0.1} + Text {text: "Pinch zoom\nsensitivity-"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.pinch.rotationSpeed += 0.1} + Text {text: "Pinch rotation\nsensitivity+"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.pinch.rotationSpeed -= 0.1} + Text {text: "Pinch rotation\nsensitivity-"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.pinch.maximumTiltChange += 1} + Text {text: "Pinch tilt\nsensitivity+"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.pinch.maximumTiltChange -= 1} + Text {text: "Pinch tilt\nsensitivity-"} + } + } + Rectangle { id: rowRectPinchGen; width: rowRect1.width; height: rowRect1.height; color: 'lightsteelblue'; + Text { text: "Pinch\nzoom:\n" + ((map.pinch.activeGestures & MapPinch.ZoomGesture) > 0? "Yes":"No")} + MouseArea { + anchors.fill: parent; + onClicked: { + console.log('oooQML: map pinch active gestures' + map.pinch.activeGestures); + if (map.pinch.activeGestures & MapPinch.ZoomGesture) + map.pinch.activeGestures &= ~MapPinch.ZoomGesture + else + map.pinch.activeGestures += MapPinch.ZoomGesture + } + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRectPinchGen.color; + Text { text: "Pinch\nrotation:\n" + ((map.pinch.activeGestures & MapPinch.RotationGesture) > 0? "Yes":"No")} + MouseArea { + anchors.fill: parent; + onClicked: { + console.log('oooQML: map pinch active gestures' + map.pinch.activeGestures); + if (map.pinch.activeGestures & MapPinch.RotationGesture) + map.pinch.activeGestures &= ~MapPinch.RotationGesture + else + map.pinch.activeGestures += MapPinch.RotationGesture + } + } + } + + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRectPinchGen.color; + Text { text: "Pinch\ntilt:\n" + ((map.pinch.activeGestures & MapPinch.TiltGesture) > 0? "Yes":"No")} + MouseArea { + anchors.fill: parent; + onClicked: { + console.log('oooQML: map pinch active gestures' + map.pinch.activeGestures); + if (map.pinch.activeGestures & MapPinch.TiltGesture) + map.pinch.activeGestures &= ~MapPinch.TiltGesture + else + map.pinch.activeGestures += MapPinch.TiltGesture + } + } + + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRectPinchGen.color; + Text { id: generatorEnabledText; text: pinchGenerator.enabled? "Pinch Gen\nEnabled" : "Pinch Gen\nDisabled"; font.bold: true} + MouseArea { + anchors.fill: parent; + onClicked: { + if (pinchGenerator.focus == true) { + pinchGenerator.focus = false; + pinchGenerator.enabled = false; + pinchGenerator.z = -1 + map.focus = true; + } else { + pinchGenerator.focus = true + pinchGenerator.enabled = true; + pinchGenerator.z = 10 + map.focus = false + } + } + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + Text {text: map.flick.enabled? "Flick\nEnabled":"Flick\nDisabled"; font.bold: true} + MouseArea { anchors.fill: parent; onClicked: {map.flick.enabled = !map.flick.enabled} } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.flick.deceleration += 200} + Text {text: "Flick\ndeceleration+"} + } + } + Rectangle { width: rowRect1.width; height: rowRect1.height; color: rowRect1.color; + MouseArea { anchors.fill: parent; onClicked: {map.flick.deceleration -= 200} + Text {text: "Flick\ndeceleration-"} + } + } + } // Row + + // Info texts + Row { + id: textRow1 + spacing: 15 + anchors.top: buttonRow.bottom + Text {id: firstText; text: "Map zoom level: " + map.zoomLevel; color: 'red'; font.bold: true} + Text {text: "Pinch zoom sensitivity: " + map.pinch.maximumZoomLevelChange; color: firstText.color; font.bold: true} + Text {text: "Pinch rotation sensitivity: " + map.pinch.rotationSpeed; color: firstText.color; font.bold: true} + } + Row { + id: textRow2 + spacing: 15 + anchors.top: textRow1.bottom + Text {text: "Pinch tilt sensitivity: " + map.pinch.maximumTiltChange; color: firstText.color; font.bold: true} + Text {text: "Flick deceleration: " + map.flick.deceleration; color: firstText.color; font.bold: true} + Text {text: "Weather: Sunny, mild, late showers."; color: firstText.color; font.bold: true} + } // info texts + + // Row 2 (mouse area) + Row { + id: buttonRow2 + anchors.leftMargin: 2 + anchors.topMargin: 2 + anchors.top: textRow2.bottom; + spacing: 2 + Rectangle { id: rowRect2; width: 80; height: 65; color: 'peru'; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap.enabled? "Map mouse\nenabled":"Map mouse\ndisabled" } + onClicked: {mouseAreaOfMap.enabled = !mouseAreaOfMap.enabled} + } + } + Rectangle { width: rowRect2.width; height: rowRect2.height; color: rowRect2.color; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap.hoverEnabled? "MMouseU\nhover\nenabled":"MMouseU\nhover\ndisabled" } + onClicked: {mouseAreaOfMap.hoverEnabled = !mouseAreaOfMap.hoverEnabled} + } + } + Rectangle { width: rowRect2.width; height: rowRect2.height; color: rowRect2.color; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap2.hoverEnabled? "MMouseL\nhover\nenabled":"MMouseL\nhover\ndisabled" } + onClicked: {mouseAreaOfMap2.hoverEnabled = !mouseAreaOfMap2.hoverEnabled} + } + } + Rectangle { width: rowRect2.width; height: rowRect2.height; color: rowRect2.color; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap3.hoverEnabled? "MMouseO\nhover\nenabled":"MMouseO\nhover\ndisabled" } + onClicked: {mouseAreaOfMap3.hoverEnabled = !mouseAreaOfMap3.hoverEnabled} + } + } + Rectangle { width: rowRect2.width; height: rowRect2.height; color: rowRect2.color; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap2.enabled? "Map ML\nenabled":"Map ML\ndisabled" } + onClicked: {mouseAreaOfMap2.enabled = !mouseAreaOfMap2.enabled} + } + } + } + + // Row 3 reference mouse area + Row { + id: buttonRow3 + anchors.leftMargin: 2 + anchors.topMargin: 2 + anchors.top: buttonRow2.bottom; + spacing: 2 + Rectangle { id: rowRect3; width: 80; height: 65; color: 'steelblue'; + MouseArea { anchors.fill: parent; + Text {text: referenceMouseAreaOverlapping.enabled? "OL mouse\nenabled":"OL mouse\ndisabled" } + onClicked: { + //referenceMouseAreaUpper.enabled = !referenceMouseAreaUpper.enabled + //referenceMouseAreaLower.enabled = !referenceMouseAreaLower.enabled + referenceMouseAreaOverlapping.enabled = !referenceMouseAreaOverlapping.enabled + } + } + } + Rectangle { width: rowRect3.width; height: rowRect3.height; color: rowRect3.color; + MouseArea { anchors.fill: parent; + Text {text: referenceMouseAreaUpper.hoverEnabled? "Map mouse\nhover enabled":"Map mouse\nhover disabled" } + onClicked: { + referenceMouseAreaUpper.hoverEnabled = !referenceMouseAreaUpper.hoverEnabled + referenceMouseAreaLower.hoverEnabled = !referenceMouseAreaLower.hoverEnabled + referenceMouseAreaOverlapping.hoverEnabled = !referenceMouseAreaOverlapping.hoverEnabled + } + } + } + Rectangle { width: rowRect3.width; height: rowRect3.height; color: rowRect3.color; + MouseArea { anchors.fill: parent; + Text {text: referenceMouseAreaLower.enabled? "Low mouse\nenabled":"Low mouse\ndisabled" } + onClicked: { + //referenceMouseAreaUpper.enabled = !referenceMouseAreaUpper.enabled + referenceMouseAreaLower.enabled = !referenceMouseAreaLower.enabled + //referenceMouseAreaOverlapping.enabled = !referenceMouseAreaOverlapping.enabled + } + } + } + Rectangle { width: rowRect3.width; height: rowRect3.height; color: rowRect3.color; + MouseArea { anchors.fill: parent; + Text {text: referenceMouseAreaUpper.enabled? "Up mouse\nenabled":"Up mouse\ndisabled" } + onClicked: { + referenceMouseAreaUpper.enabled = !referenceMouseAreaUpper.enabled + //referenceMouseAreaLower.enabled = !referenceMouseAreaLower.enabled + //referenceMouseAreaOverlapping.enabled = !referenceMouseAreaOverlapping.enabled + } + } + } + Rectangle { width: rowRect3.width; height: rowRect3.height; color: rowRect3.color; + MouseArea { anchors.fill: parent; + Text {text: mouseAreaOfMap3.enabled? "Map MOL\nenabled":"Map MOL\ndisabled" } + onClicked: {mouseAreaOfMap3.enabled = !mouseAreaOfMap3.enabled} + } + } + } + // Row 3 (reference mouse area) + + Rectangle { + id: pinchRect1 + color: 'red' + visible: false + z: 10 + width: 5 + height: 5 + } + Rectangle { + id: pinchRect2 + color: 'red' + visible: false + z: 10 + width: 5 + height: 5 + } + + Repeater { + id: swipeView1 + model: pinchGenerator.swipe1 + delegate: Component { + Rectangle { + Text {id: touchPointText} + Component.onCompleted: { + if (modelData.touchState == 1) { // Qt.TouchPointPressed + color = "pink"; width = 15; height = 15 + touchPointText.text = 'From' + } + else if (modelData.touchState == 2) { // Qt.TouchPointMoved + color = 'yellow'; width = 5; height = 5 + } + else if (modelData.touchState == 8) { // Qt.TouchPointReleased + color = 'red'; width = 15; height = 15 + touchPointText.text = 'To' + } + } + x: modelData.targetX; y: modelData.targetY + } + } + } + + Repeater { + id: swipeView2 + model: pinchGenerator.swipe2 + delegate: Component { + Rectangle { + Text {id: touchPoint2Text} + Component.onCompleted: { + if (modelData.touchState == 1) { // Qt.TouchPointPressed + color = "green"; width = 15; height = 15 + touchPoint2Text.text = 'From' + } + else if (modelData.touchState == 2) { // Qt.TouchPointMoved + color = 'yellow'; width = 5; height = 5 + } + else if (modelData.touchState == 8) { // Qt.TouchPointReleased + color = 'blue'; width = 15; height = 15 + touchPoint2Text.text = 'To' + } + } + x: modelData.targetX; y: modelData.targetY + } + } + } +} diff --git a/src/imports/location/qdeclarative3dgraphicsgeomap.cpp b/src/imports/location/qdeclarative3dgraphicsgeomap.cpp index 9cc964aa..557237ee 100644 --- a/src/imports/location/qdeclarative3dgraphicsgeomap.cpp +++ b/src/imports/location/qdeclarative3dgraphicsgeomap.cpp @@ -69,6 +69,7 @@ #include <QSGCanvas> #include <QSGEngine> #include <QDesktopWidget> +#include <QtGui/QGuiApplication> #include <QDebug> @@ -111,28 +112,24 @@ QDeclarative3DGraphicsGeoMap::QDeclarative3DGraphicsGeoMap(QSGItem *parent) plugin_(0), serviceProvider_(0), mappingManager_(0), -// mapData_(0), center_(0), initialCoordinate(0), // mapType_(NoMap), // connectivityMode_(NoConnectivity), componentCompleted_(false), -#ifdef QSGMOUSEAREA_AVAILABLE - mouseArea_(0), -#endif flickable_(0), pinchArea_(0), + //hoverItem_(0), + mouseGrabberItem_(0), canvas_(0), touchTimer_(-1), tileCache_(0) - - // ses_(0), - // texture_(0) { + QLOC_TRACE0; initialCoordinate = new QGeoCoordinate(-27.0, 153.0); zoomLevel_ = 8; size_ = QSizeF(100.0, 100.0); - setAcceptHoverEvents(true); + setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); setFlags(QSGItem::ItemHasContents); @@ -142,11 +139,9 @@ QDeclarative3DGraphicsGeoMap::QDeclarative3DGraphicsGeoMap(QSGItem *parent) SIGNAL(updateRequired()), this, SLOT(update())); - //connect(map_->mapCamera(), SIGNAL(zoomChanged(double)), this, SLOT(cameraZoomLevelChanged(double))); // Create internal flickable and pinch area. flickable_ = new QDeclarativeGeoMapFlickable(map_, this); pinchArea_ = new QDeclarativeGeoMapPinchArea(this, this); - qDebug() << __FUNCTION__ << "Created.============================================================"; } QSGNode* QDeclarative3DGraphicsGeoMap::updatePaintNode(QSGNode* node, UpdatePaintNodeData* data) @@ -171,19 +166,17 @@ QDeclarative3DGraphicsGeoMap::~QDeclarative3DGraphicsGeoMap() // } // delete mapData_; // } + mouseAreas_.clear(); if (serviceProvider_) delete serviceProvider_; if (initialCoordinate) { delete initialCoordinate; } -#ifdef QSGMOUSEAREA_AVAILABLE - delete mouseArea_; -#endif } void QDeclarative3DGraphicsGeoMap::componentComplete() { - qDebug() << __FUNCTION__ << "Completed =====-===-=================================================="; + QLOC_TRACE0; componentCompleted_ = true; populateMap(); map_->resize(width(), height()); @@ -206,8 +199,8 @@ void QDeclarative3DGraphicsGeoMap::itemChange(ItemChange change, const ItemChang canvas_->sceneGraphEngine()->disconnect(this); } canvas_ = data.canvas; - if (canvas_->sceneGraphEngine()) { - qDebug() << __FUNCTION__ << "Engine exists. Connecting to beforeRendering() " << canvas_->sceneGraphEngine(); + if (canvas_ && canvas_->sceneGraphEngine()) { + QLOC_TRACE1("QSGEngine exists, connecting directly."); QSGEngine* engine = canvas_->sceneGraphEngine(); connect((QObject*)engine, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection); engine->setClearBeforeRendering(false); @@ -229,12 +222,10 @@ void QDeclarative3DGraphicsGeoMap::sceneGraphInitialized() void QDeclarative3DGraphicsGeoMap::populateMap() { -// if (!mapData_ || !componentCompleted_) if (!componentCompleted_) return; QObjectList kids = children(); for (int i = 0; i < kids.size(); ++i) { - //qDebug() << "Looping through..: " << kids.at(i)->metaObject()->className() << kids.at(i)->objectName(); // dispatch items appropriately QDeclarativeGeoMapObjectView* mapView = qobject_cast<QDeclarativeGeoMapObjectView*>(kids.at(i)); if (mapView) { @@ -246,56 +237,12 @@ void QDeclarative3DGraphicsGeoMap::populateMap() if (mapItem) { addMapItem(mapItem); } -#ifdef QSGMOUSEAREA_AVAILABLE - QSGMouseArea *mouseArea = qobject_cast<QSGMouseArea*>(kids.at(i)); - if (mouseArea && !mouseArea_) { - //qDebug() << "Got mouse area."; - mouseArea_ = mouseArea; - // This is the trick to get mouse events reach Map element; - // if visible is true then the MouseArea will consume events - // before Map has chance to use it. - mouseArea_->setVisible(false); - connect(mouseArea_, SIGNAL(visibleChanged()), this, SLOT(mouseChanged())); - connect(mouseArea_, SIGNAL(enabledChanged()), this, SLOT(mouseChanged())); - connect(mouseArea_, SIGNAL(widthChanged()), this, SLOT(mouseChanged())); - connect(mouseArea_, SIGNAL(heightChanged()), this, SLOT(mouseChanged())); - } else if (mouseArea && mouseArea_) { - qmlInfo(this) << tr("Warning: only one MouseArea / Map supported. Extra MouseArea ignored."); - } -#endif QDeclarativeGeoMapMouseArea *mapMouseArea = qobject_cast<QDeclarativeGeoMapMouseArea*>(kids.at(i)); if (mapMouseArea) { - qmlInfo(this) << tr("Warning: MapMouseArea is no longer supported. Use normal MouseArea instead."); - } - } -} - -void QDeclarative3DGraphicsGeoMap::mapItemTextureChanged() -{ -#ifdef QSGSHADEREFFECTSOURCE_AVAILABLE - for (int i = mapItemsPending_.count() - 1; i >= 0; --i) { - if (mapItemsPending_.at(i)->hasValidTexture()) { - disconnect(mapItemsPending_.at(i), SIGNAL(textureChanged()), this, SLOT(mapItemTextureChanged())); - mapItemsPending_.at(i)->setMap(this); - mapItems_.append(mapItemsPending_.at(i)); - map_->addMapItem(mapItemsPending_.at(i)->mapItem()); - mapItemsPending_.removeAt(i); + mapMouseArea->setMap(this); + mouseAreas_.append(mapMouseArea); } } -#endif -} - -void QDeclarative3DGraphicsGeoMap::mouseChanged() -{ -#ifdef QSGMOUSEAREA_AVAILABLE - if (mouseArea_ - && mouseArea_->isVisible() - && mouseArea_->isEnabled() - && mouseArea_->width() > 0 - && mouseArea_->height() > 0) { - qmlInfo(this) << tr("Warning: MouseArea in Map visible, enabled and has geometry. Map unable to intercept & dispatch mouse to map objects."); - } -#endif } void QDeclarative3DGraphicsGeoMap::setupMapView(QDeclarativeGeoMapObjectView *view) @@ -324,16 +271,6 @@ qreal ViewportSubsurface::aspectRatio() const return QGLSubsurface::aspectRatio() * m_adjust; } -void QDeclarative3DGraphicsGeoMap::closeEvent(QCloseEvent *) -{ - qApp->quit(); -} - -void QDeclarative3DGraphicsGeoMap::showEvent(QShowEvent *) -{ - updateAspectRatio(); -} - void QDeclarative3DGraphicsGeoMap::updateAspectRatio() { map_->resize(width(), height()); @@ -341,28 +278,16 @@ void QDeclarative3DGraphicsGeoMap::updateAspectRatio() map_->update(); } -void QDeclarative3DGraphicsGeoMap::resizeEvent(QResizeEvent *event) +void QDeclarative3DGraphicsGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - Q_UNUSED(event); + setSize(QSizeF(newGeometry.width(), newGeometry.height())); updateAspectRatio(); + QSGItem::geometryChanged(newGeometry, oldGeometry); } -/* -void QDeclarative3DGraphicsGeoMap::enterEvent(QEvent *) -{ - setFocus(true); - //grabKeyboard(); -} - -void QDeclarative3DGraphicsGeoMap::leaveEvent(QEvent *e) -{ - setFocus(false); - //releaseKeyboard(); -} -*/ - void QDeclarative3DGraphicsGeoMap::keyPressEvent(QKeyEvent *e) { + QLOC_TRACE2(" key: ", e->key()); CameraData cameraData = map_->cameraData(); if (e->key() == Qt::Key_Left) { if (e->modifiers() & Qt::ShiftModifier) { @@ -433,6 +358,19 @@ void QDeclarative3DGraphicsGeoMap::beforeRendering() { if (!isVisible()) return; + + // temporary check until refactor branch is fully functional again + static bool render = true; + if (!render) + return; + const QGLContext* context = QGLContext::currentContext(); + if (!context || !context->device()) { + render = false; + qmlInfo(this) << tr("GL paint device is NULL. Will not render the map."); + return; + } + // end of temporary check + QGLPainter painter; if (!painter.begin()) { qmlInfo(this) << tr("GL graphics system is not active; cannot use 3D items"); @@ -544,23 +482,8 @@ void QDeclarative3DGraphicsGeoMap::earlyDraw(QGLPainter *painter) void QDeclarative3DGraphicsGeoMap::paintGL(QGLPainter *painter) { - if (map_) { - // QGLSceneNode *node = map_->sceneNode(); + if (map_) map_->paintGL(painter); -// QGLSceneNode *node = map_->sceneNodeForRendering(); -// if (node) { -// node->draw(painter); -// map_->sceneNodeRenderingDone(); -// } else { -// qDebug() << "=-=-=-=-=-=-=-=- WILL MISS A MAP FRAME =-=-=-=-=-=-=-=-=-=-=-=-="; -// } - } -} - -void QDeclarative3DGraphicsGeoMap::geometryChanged(const QRectF &newGeometry, - const QRectF & /*oldGeometry*/) -{ - setSize(newGeometry.size()); } /*! @@ -932,13 +855,12 @@ void QDeclarative3DGraphicsGeoMap::centerAltitudeChanged(double /*altitude*/) QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::toCoordinate(QPointF screenPosition) const { - Q_UNUSED(screenPosition); QGeoCoordinate coordinate; - qWarning() << __FUNCTION__ << " not implemented."; // TODO -// if (mapData_) -// coordinate = mapData_->screenPositionToCoordinate(screenPosition); - return new QDeclarativeCoordinate(coordinate, - const_cast<QDeclarative3DGraphicsGeoMap *>(this)); + if (map_) + coordinate = map_->screenPositionToCoordinate(screenPosition); + // by default objects returned from method call get javascript ownership, + // so we don't need to worry about this as long as we don't set the parent + return new QDeclarativeCoordinate(coordinate); } /*! @@ -950,14 +872,12 @@ QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::toCoordinate(QPointF scree Returns an invalid QPointF if \a coordinate is not within the current viewport. */ + QPointF QDeclarative3DGraphicsGeoMap::toScreenPosition(QDeclarativeCoordinate* coordinate) const { - Q_UNUSED(coordinate); QPointF point; - qWarning() << __FUNCTION__ << " not implemented."; // TODO -// if (mapData_) -// point = mapData_->coordinateToScreenPosition(coordinate->coordinate()); - + if (map_) + point = map_->coordinateToScreenPosition(coordinate->coordinate()); return point; } @@ -965,115 +885,278 @@ void QDeclarative3DGraphicsGeoMap::pan(int dx, int dy) { Q_UNUSED(dx); Q_UNUSED(dy); - qWarning() << __FUNCTION__ << " not implemented."; // TODO - //qDebug() << "pan: " << dx << dy; - //if (mapData_) { - // mapData_->pan(dx, dy); - // update(); - if (map_) { - // TODO zzz map_-> - } else { - qmlInfo(this) << tr("Map plugin is not set, cannot pan."); - } + qWarning() << __FUNCTION__ << " of Map not implemented."; // TODO } void QDeclarative3DGraphicsGeoMap::touchEvent(QTouchEvent *event) { - //qDebug() << "touchEvent in Map3D, enter, sending touchEvent to pinch area."; - if (pinchArea_) - pinchArea_->touchEvent(event); + QLOC_TRACE0; + event->accept(); + pinchArea_->touchEvent(event); } void QDeclarative3DGraphicsGeoMap::wheelEvent(QWheelEvent *event) { + QLOC_TRACE0; + event->accept(); emit wheel(event->delta()); - //QSGItem::wheelEvent(event); } -void QDeclarative3DGraphicsGeoMap::mousePressEvent(QGraphicsSceneMouseEvent *event) +// event delivery helpers +bool QDeclarative3DGraphicsGeoMap::deliverMouseEvent(QMouseEvent* event) { - //qDebug() << "mousePressEvent in Map3D, enter +------------------------------------------------------------------"; -// if (!mapData_) { -// qmlInfo(this) << tr("Map plugin is not set, mouse event cannot be processed."); -// return; -// } -#ifdef QSGMOUSEAREA_AVAILABLE - canvas()->sendEvent(mouseArea_, event); -#endif + QLOC_TRACE2("mouse grabber item: ", mouseGrabberItem_); + // todo deliver first for map items + + // mouse grabber item is an item that has received the initial + // press event. all events will be given to that item (can be + // outside of mouse area) until mouse is released. this enables + // for example entered() exited() -signals whilst mouse is pressed + lastMousePosition_ = event->windowPos(); + + if (!mouseGrabberItem_ && + event->type() == QEvent::MouseButtonPress && + (event->button() & event->buttons()) == event->buttons()) { + QList<QDeclarativeGeoMapMouseArea*> mouseAreas = mouseAreasAt(event->pos()); + for (int i = 0; i < mouseAreas.count(); ++i) { + QDeclarativeGeoMapMouseArea* item = mouseAreas.at(i); + QLOC_TRACE2("delivering initial mouse press for: ", item->objectName()); + if (deliverInitialMousePressEvent(item, event)) { + QLOC_TRACE2("initial mouse press accepted by: ", item->objectName()); + return true; + } + } + QLOC_TRACE1("no item found for initial mouse press"); + return false; + } + if (mouseGrabberItem_) { + bool transformOk; + const QTransform &transform = itemTransform(mouseGrabberItem_, &transformOk); + QMouseEvent me(event->type(), // event type + transform.map(event->windowPos()), // pos coordinates translated into that of mapmousearea (local coords) + event->windowPos(), // window position (coords relative to window) + event->screenPos(), // global position (absolute coords) + event->button(), // button causing the event + event->buttons(), // buttons pressed when event was caused + event->modifiers()); // any keyboard modifiers held when event was triggered + me.accept(); + mouseGrabberItem_->mouseEvent(&me); + QLOC_TRACE2("mouse grabber accepted event: ", me.isAccepted()); + event->setAccepted(me.isAccepted()); + if (me.isAccepted()) + return true; + } + return false; +} + +bool QDeclarative3DGraphicsGeoMap::deliverInitialMousePressEvent(QDeclarativeGeoMapMouseArea* ma, QMouseEvent* event) +{ + if (ma->acceptedMouseButtons() & event->button()) { + QPointF p = ma->mapFromScene(event->windowPos()); + if (QRectF(0, 0, ma->width(), ma->height()).contains(p)) { + QMouseEvent me(event->type(), p, event->windowPos(), event->screenPos(), + event->button(), event->buttons(), event->modifiers()); + me.accept(); + mouseGrabberItem_ = ma; + // canvas_->sendEvent(item, &me); + ma->mouseEvent(&me); + event->setAccepted(me.isAccepted()); + QLOC_TRACE2("the initial mouse press accepted: ", me.isAccepted()); + if (me.isAccepted()) + return true; + QLOC_TRACE1("nulling the mouse grabber"); + mouseGrabberItem_ = 0; + } + } + return false; +} + +void QDeclarative3DGraphicsGeoMap::mousePressEvent(QMouseEvent *event) +{ + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + deliverMouseEvent(event); if (flickable_) flickable_->mousePressEvent(event); if (pinchArea_) pinchArea_->mousePressEvent(event); - //QSGItem::mousePressEvent(event); } -void QDeclarative3DGraphicsGeoMap::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +// returns list of mouse areas under 'pos'. returned list is in the priority order in which the +// mouse events should be provided (currently does not consider 'z') +QList<QDeclarativeGeoMapMouseArea*> QDeclarative3DGraphicsGeoMap::mouseAreasAt(QPoint pos) { -#ifdef QSGMOUSEAREA_AVAILABLE - canvas()->sendEvent(mouseArea_, event); -#endif + QList<QDeclarativeGeoMapMouseArea*> list; + for (int i = mouseAreas_.count() - 1; i >= 0; --i) { + if (mouseAreas_.at(i)->boundingRect().contains(mouseAreas_.at(i)->mapFromScene(pos))) { + list.append(mouseAreas_.at(i)); + } + } + return list; +} + +void QDeclarative3DGraphicsGeoMap::mouseReleaseEvent(QMouseEvent *event) +{ + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + if (!mouseGrabberItem_) { + QSGItem::mouseReleaseEvent(event); + return; + } + deliverMouseEvent(event); + QLOC_TRACE1("nulling mouse grabber"); + + mouseGrabberItem_ = 0; if (flickable_) flickable_->mouseReleaseEvent(event); if (pinchArea_) pinchArea_->mouseReleaseEvent(event); - //QSGItem::mouseReleaseEvent(event); } -void QDeclarative3DGraphicsGeoMap::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +void QDeclarative3DGraphicsGeoMap::mouseDoubleClickEvent(QMouseEvent *event) { -// if (!mapData_) { -// qmlInfo(this) << tr("Map plugin is not set, mouse event cannot be processed."); -// return; -// } -#ifdef QSGMOUSEAREA_AVAILABLE - canvas()->sendEvent(mouseArea_, event); -#endif - //QSGItem::mouseDoubleClickEvent(event); + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + if (!mouseGrabberItem_ && (event->button() & event->buttons()) == event->buttons()) { + QList<QDeclarativeGeoMapMouseArea*> mouseAreas = mouseAreasAt(event->pos()); + for (int i = 0; i < mouseAreas.count(); ++i) { + if (deliverInitialMousePressEvent(mouseAreas.at(i), event)) { + event->accept(); + return; + } + } + event->ignore(); + return; + } + deliverMouseEvent(event); } -void QDeclarative3DGraphicsGeoMap::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QDeclarative3DGraphicsGeoMap::mouseMoveEvent(QMouseEvent *event) { -#ifdef QSGMOUSEAREA_AVAILABLE - canvas()->sendEvent(mouseArea_, event); -#endif + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + /* hover placeholder + if (!mouseGrabberItem_) { + if (lastMousePosition_.isNull()) + lastMousePosition_ = event->windowPos(); + QPointF last = lastMousePosition_; + lastMousePosition_ = event->windowPos(); + bool accepted = event->isAccepted(); + bool delivered = deliverHoverEvent(mouseAreaAt(event->pos()), event->windowPos(), last, event->modifiers(), accepted); + // exit any hover areas if we're out of bounds + if (!delivered) + accepted = clearHover(); + event->setAccepted(accepted); + return; + } + */ + if (!mouseGrabberItem_) + return; + + deliverMouseEvent(event); if (flickable_) flickable_->mouseMoveEvent(event); if (pinchArea_) pinchArea_->mouseMoveEvent(event); - //QSGItem::mouseMoveEvent(event); } -void QDeclarative3DGraphicsGeoMap::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +// hover functions are a placeholder. It works to an extent but +// will need more work and testing if will be supported officially +/* + +bool QDeclarative3DGraphicsGeoMap::deliverHoverEvent(QDeclarativeGeoMapMouseArea* ma, const QPointF &scenePos, const QPointF &lastScenePos, + Qt::KeyboardModifiers modifiers, bool &accepted) { -// if (!mapData_) -// return; -#ifdef QSGMOUSEAREA_AVAILABLE - if (mouseArea_ && mouseArea_->hoverEnabled()) { - canvas()->sendEvent(mouseArea_, event); + if (hoverItem_ && ma == hoverItem_) { + // hovering on the same item as before + QLOC_TRACE2(" deliver hover for same item: ", ma->objectName()); + accepted = sendHoverEvent(QEvent::HoverMove, ma, scenePos, lastScenePos, modifiers, accepted); + return true; + } else { + // leave previous hover item since it is different + if (hoverItem_) { + sendHoverEvent(QEvent::HoverLeave, hoverItem_, scenePos, lastScenePos, modifiers, accepted); + QLOC_TRACE2("exiting previous hover area: ", hoverItem_->objectName()); + hoverItem_ = 0; + } + // enter new hover item if any + if (ma && ma->hoverEnabled()) { + QLOC_TRACE2("entering new hover area: ", ma->objectName()); + sendHoverEvent(QEvent::HoverEnter, ma, scenePos, lastScenePos, modifiers, accepted); + hoverItem_ = ma; + } else { + if (ma) { + QLOC_TRACE2("no hover area, hovering disabled: ", ma->objectName()); + } else { + QLOC_TRACE1("no hover area"); + } + } + return true; } -#endif + return false; } -void QDeclarative3DGraphicsGeoMap::hoverMoveEvent(QGraphicsSceneHoverEvent *event) + +void QDeclarative3DGraphicsGeoMap::hoverEvent(QHoverEvent* event) { -#ifdef QSGMOUSEAREA_AVAILABLE - if (mouseArea_ && mouseArea_->hoverEnabled()) { - canvas()->sendEvent(mouseArea_, event); + QDeclarativeGeoMapMouseArea* ma = mouseAreaAt(event->pos()); + if (ma) { + QLOC_TRACE2("for mouse area: ", ma->objectName()); + } else { + QLOC_TRACE1("no mouse area"); } -#endif + if (lastMousePosition_.isNull()) + lastMousePosition_ = event->pos(); // hmmm todo was windowPos + QPointF last = lastMousePosition_; + lastMousePosition_ = event->pos(); // hmmm todo was windowPos + bool accepted = event->isAccepted(); + (bool)deliverHoverEvent(ma, event->pos(), last, event->modifiers(), accepted); } -void QDeclarative3DGraphicsGeoMap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) + +bool QDeclarative3DGraphicsGeoMap::clearHover() { -// if (!mapData_) -// return; -#ifdef QSGMOUSEAREA_AVAILABLE - if (mouseArea_ && mouseArea_->hoverEnabled()) { - canvas()->sendEvent(mouseArea_, event); - } -#endif + QLOC_TRACE0; + if (!hoverItem_) + return false; + QPointF pos = QCursor::pos(); + bool accepted = sendHoverEvent(QEvent::HoverLeave, hoverItem_, pos, pos, QGuiApplication::keyboardModifiers(), true); + hoverItem_ = 0; + return accepted; } +bool QDeclarative3DGraphicsGeoMap::sendHoverEvent(QEvent::Type type, QSGItem *item, + const QPointF &scenePos, const QPointF &lastScenePos, + Qt::KeyboardModifiers modifiers, bool accepted) +{ + bool transformOk; + const QTransform &transform = itemTransform(item, &transformOk); + //create copy of event + QHoverEvent hoverEvent(type, transform.map(scenePos), transform.map(lastScenePos), modifiers); + hoverEvent.setAccepted(accepted); + QDeclarativeGeoMapMouseArea* ma = static_cast<QDeclarativeGeoMapMouseArea*>(item); + ma->hoverEvent(&hoverEvent); + return hoverEvent.isAccepted(); +} + +void QDeclarative3DGraphicsGeoMap::hoverEnterEvent(QHoverEvent *event) +{ + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + QLOC_TRACE2(" type: ", event->type()); + hoverEvent(event); +} + +void QDeclarative3DGraphicsGeoMap::hoverMoveEvent(QHoverEvent *event) +{ + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + QLOC_TRACE2(" type: ", event->type()); + hoverEvent(event); +} + +void QDeclarative3DGraphicsGeoMap::hoverLeaveEvent(QHoverEvent *event) +{ + QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos()); + QLOC_TRACE2(" type: ", event->type()); + hoverEvent(event); +} +*/ + void QDeclarative3DGraphicsGeoMap::internalCenterChanged(const QGeoCoordinate &coordinate) { emit declarativeCenterChanged(new QDeclarativeCoordinate(coordinate, this)); @@ -1127,6 +1210,8 @@ void QDeclarative3DGraphicsGeoMap::addMapItem(QDeclarativeGeoMapItem *item) item->setMap(this); mapItems_.append(item); map_->addMapItem(item->mapItem()); +#else + Q_UNUSED(item); #endif } @@ -1140,6 +1225,8 @@ void QDeclarative3DGraphicsGeoMap::removeMapItem(QDeclarativeGeoMapItem *item) mapItems_.removeOne(item); mapItemsPending_.removeOne(item); map_->removeMapItem(item->mapItem()); +#else + Q_UNUSED(item); #endif } diff --git a/src/imports/location/qdeclarative3dgraphicsgeomap_p.h b/src/imports/location/qdeclarative3dgraphicsgeomap_p.h index 67abdece..c60ed773 100644 --- a/src/imports/location/qdeclarative3dgraphicsgeomap_p.h +++ b/src/imports/location/qdeclarative3dgraphicsgeomap_p.h @@ -50,14 +50,22 @@ #include "qdeclarativegeomapobjectview_p.h" #include <QtCore/QCoreApplication> -// Check $$pwd/location.pro how to enable these -#ifdef QSGMOUSEAREA_AVAILABLE -#include "qsgmousearea_p.h" -#endif #include "qsgtexture.h" #include "qdeclarativegeomapflickable_p.h" #include "qdeclarativegeomappincharea_p.h" +//#define QT_DECLARATIVE_LOCATION_TRACE 1 + +#ifdef QT_DECLARATIVE_LOCATION_TRACE +#define QLOC_TRACE0 qDebug() << __FILE__ << __FUNCTION__; +#define QLOC_TRACE1(msg1) qDebug() << __FILE__ << __FUNCTION__ << msg1; +#define QLOC_TRACE2(msg1, msg2) qDebug() << __FILE__ << __FUNCTION__ << msg1 << msg2; +#else +#define QLOC_TRACE0 +#define QLOC_TRACE1(msg1) +#define QLOC_TRACE2(msg1, msg2) +#endif + #include "cameradata.h" #include "map.h" @@ -78,9 +86,6 @@ class QDeclarativeCoordinate; class QDeclarativeGeoServiceProvider; class QDeclarative3DGraphicsGeoMap; class QDeclarativeGeoMapItem; -#ifdef QSGMOUSEAREA_AVAILABLE -class QSGMouseEvent; -#endif class QDeclarative3DGraphicsGeoMap : public QSGItem { @@ -140,12 +145,6 @@ public: QDeclarativeGeoMapFlickable* flick(); - void setMouseEnabled(bool enabled); - bool mouseEnabled() const; - void setMouseHoverEnabled(bool enabled); - bool mouseHoverEnabled() const; - bool containsMouse() const; - void setZoomLevel(qreal zoomLevel); qreal zoomLevel() const; @@ -188,26 +187,19 @@ public Q_SLOTS: protected: void touchEvent(QTouchEvent *event); void wheelEvent(QWheelEvent *event); - void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + // hover is just a placeholder + //void hoverEnterEvent(QHoverEvent *event); + //void hoverMoveEvent(QHoverEvent *event); + //void hoverLeaveEvent(QHoverEvent *event); void keyPressEvent(QKeyEvent *e); - void closeEvent(QCloseEvent *e); - //void enterEvent(QEvent *e); - //void leaveEvent(QEvent *e); - void showEvent(QShowEvent *e); - void resizeEvent(QResizeEvent *e); + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); Q_SIGNALS: - // wheel void wheel(qreal delta); - void pluginChanged(QDeclarativeGeoServiceProvider *plugin); void sizeChanged(const QSizeF &size); void zoomLevelChanged(qreal zoomLevel); @@ -225,8 +217,6 @@ private Q_SLOTS: void centerAltitudeChanged(double altitude); void sceneGraphInitialized(); void beforeRendering(); - void mouseChanged(); - void mapItemTextureChanged(); void cameraZoomLevelChanged(double zoomLevel); private: @@ -234,6 +224,24 @@ private: void updateAspectRatio(); void populateMap(); + /* hover placeholder (works to an extent but would need more work) + void hoverEvent(QHoverEvent* event); + bool clearHover(); + bool deliverHoverEvent(QDeclarativeGeoMapMouseArea* ma, + const QPointF &scenePos, + const QPointF &lastScenePos, + Qt::KeyboardModifiers modifiers, + bool &accepted); + bool sendHoverEvent(QEvent::Type type, QSGItem *item, + const QPointF &scenePos, const QPointF &lastScenePos, + Qt::KeyboardModifiers modifiers, bool accepted); + QDeclarativeGeoMapMouseArea* hoverItem_; + */ + + QList<QDeclarativeGeoMapMouseArea*> mouseAreasAt(QPoint pos); + bool deliverMouseEvent(QMouseEvent* event); + bool deliverInitialMousePressEvent(QDeclarativeGeoMapMouseArea* ma, QMouseEvent* event); + QDeclarativeGeoServiceProvider* plugin_; QGeoServiceProvider* serviceProvider_; QGeoMappingManager* mappingManager_; @@ -249,11 +257,12 @@ private: bool componentCompleted_; QList<QDeclarativeGeoMapObjectView*> mapViews_; -#ifdef QSGMOUSEAREA_AVAILABLE - QSGMouseArea* mouseArea_; -#endif QDeclarativeGeoMapFlickable* flickable_; QDeclarativeGeoMapPinchArea* pinchArea_; + QList<QDeclarativeGeoMapMouseArea*> mouseAreas_; + + QDeclarativeGeoMapMouseArea* mouseGrabberItem_; + QPointF lastMousePosition_; void paintGL(QGLPainter *painter); void earlyDraw(QGLPainter *painter); diff --git a/src/imports/location/qdeclarativegeomapflickable.cpp b/src/imports/location/qdeclarativegeomapflickable.cpp index 154d9ae3..810f4bf7 100644 --- a/src/imports/location/qdeclarativegeomapflickable.cpp +++ b/src/imports/location/qdeclarativegeomapflickable.cpp @@ -122,7 +122,7 @@ void QDeclarativeGeoMapFlickable::setDeceleration(qreal deceleration) emit decelerationChanged(); } -void QDeclarativeGeoMapFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapFlickable::mousePressEvent(QMouseEvent *event) { if (!enabled_) return; @@ -158,7 +158,7 @@ void QDeclarativeGeoMapFlickable::stop() velocityTime_.invalidate(); } -void QDeclarativeGeoMapFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapFlickable::mouseMoveEvent(QMouseEvent *event) { if (!enabled_) { return; @@ -284,7 +284,7 @@ bool QDeclarativeGeoMapFlickable::enabled() const return enabled_; } -void QDeclarativeGeoMapFlickable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapFlickable::mouseReleaseEvent(QMouseEvent *event) { if (!pressed_ || !enabled_) return; diff --git a/src/imports/location/qdeclarativegeomapflickable_p.h b/src/imports/location/qdeclarativegeomapflickable_p.h index a6c73c7b..427e7157 100644 --- a/src/imports/location/qdeclarativegeomapflickable_p.h +++ b/src/imports/location/qdeclarativegeomapflickable_p.h @@ -49,6 +49,7 @@ #endif #include <QtDeclarative/qdeclarative.h> +#include <QtGui/qevent.h> #include <QElapsedTimer> #include <QVector> #include <QObject> @@ -79,9 +80,9 @@ public: bool enabled() const; void setEnabled(bool enabled); - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); virtual void timerEvent(QTimerEvent *event); signals: diff --git a/src/imports/location/qdeclarativegeomapitem.cpp b/src/imports/location/qdeclarativegeomapitem.cpp index 1b6d304b..3e19be7e 100644 --- a/src/imports/location/qdeclarativegeomapitem.cpp +++ b/src/imports/location/qdeclarativegeomapitem.cpp @@ -65,7 +65,7 @@ QDeclarativeGeoMapItem::QDeclarativeGeoMapItem(QSGItem *parent) componentCompleted_(false) { connect(this, SIGNAL(sourceItemChanged()), this, SIGNAL(sourceChanged())); - connect(this->texture(), SIGNAL(textureChanged()), this, SLOT(textureChangedSlot())); + connect(this->textureProvider(), SIGNAL(textureChanged()), this, SLOT(textureChangedSlot())); } QDeclarativeGeoMapItem::~QDeclarativeGeoMapItem() @@ -77,12 +77,12 @@ QDeclarativeGeoMapItem::~QDeclarativeGeoMapItem() void QDeclarativeGeoMapItem::textureChangedSlot() { - if (!texture()) { + if (!textureProvider()->texture()) { mapItem_.setTextureId(0); // invalidate return; } - mapItem_.setTextureId(texture()->textureId()); - mapItem_.setSize(texture()->textureSize()); + mapItem_.setTextureId(textureProvider()->texture()->textureId()); + mapItem_.setSize(textureProvider()->texture()->textureSize()); } MapItem* QDeclarativeGeoMapItem::mapItem() @@ -169,8 +169,8 @@ void QDeclarativeGeoMapItem::updateItem() { // we seem to not always get texture changed -signals when // adding static map items with add - if (!mapItem_.textureId() && texture()) { - mapItem_.setTextureId(texture()->textureId()); + if (!mapItem_.textureId() && textureProvider()->texture()) { + mapItem_.setTextureId(textureProvider()->texture()->textureId()); } mapItem_.update(); } diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp index c307844d..1c968c3a 100644 --- a/src/imports/location/qdeclarativegeomapmousearea.cpp +++ b/src/imports/location/qdeclarativegeomapmousearea.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -40,12 +40,22 @@ ****************************************************************************/ #include "qdeclarativegeomapmousearea_p.h" +#include <QtDeclarative/qdeclarativeinfo.h> +#include <QtDeclarative/QSGCanvas> + +#ifndef QSGMOUSEAREA_AVAILABLE + +#else + +#include <qsgevents_p_p.h> +#include "qsgmousearea_p.h" + #include <QDebug> QT_BEGIN_NAMESPACE /*! - \qmlclass MapMouseArea QDeclarativeGeoMapMouseArea + \qmlclass MapMouseArea \brief The MapMouseArea item enables simple mouse handling. @@ -69,108 +79,222 @@ QT_BEGIN_NAMESPACE used involved handling mouse presses and clicks: onClicked, onDoubleClicked, onPressed and onReleased. - MapMouseArea items only report mouse clicks and not changes to the - position of the mouse cursor. + MapMouseArea does not intend to be generic mouse area that supports every + possible usage, rather it focuses on catering for the major use-cases. Hence there + are some implementation limitations: + \list + \i The mouse event is guaranteed only to be valid for the + duration of the signal handler (e.g. onPositionChanged, onClicked). Consequently + the mouse event itself should not be stored. The main reason for this is to + optimize memory usage; we do not want to allocate heap memory every time the mouse + moves. + \i Nested mouse areas are not supported (MapMouseArea { MapMouseArea {} } + \i Using normal QML MouseArea in MapItem or Map has no effect + \i If mouse areas of map overlap, the declaration order is significant (not e.g. 'z' value) + \i Only one MapMouseArea per MapItem is supported, and it always fills the whole MapItem + \endlist \sa MapMouseEvent */ QDeclarativeGeoMapMouseArea::QDeclarativeGeoMapMouseArea(QSGItem *parent) : QSGItem(parent), - enabled_(true), - hoverEnabled_(false) {} + mouseEvent_(0), + map_(0), + mouseArea_(0), + componentCompleted_(false) +{ + mouseEvent_ = new QDeclarativeGeoMapMouseEvent(this); + mouseArea_ = new QSGMouseArea(this); + // prevents mouseArea automagically intercepting mouse events: + mouseArea_->setVisible(false); + setVisible(false); + setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); + setAcceptHoverEvents(false); + // connect to signals so we can intercept them and convert to map + // mouse events (and e.g. to amend with geo coordinate). + // the signals that were present on mobility + connect(mouseArea_, SIGNAL(pressed(QSGMouseEvent*)), this, SLOT(pressedHandler(QSGMouseEvent*))); + connect(mouseArea_, SIGNAL(clicked(QSGMouseEvent*)), this, SLOT(clickedHandler(QSGMouseEvent*))); + connect(mouseArea_, SIGNAL(doubleClicked(QSGMouseEvent*)), this, SLOT(doubleClickedHandler(QSGMouseEvent*))); + connect(mouseArea_, SIGNAL(released(QSGMouseEvent*)), this, SLOT(releasedHandler(QSGMouseEvent*))); + connect(mouseArea_, SIGNAL(pressedChanged()), this, SLOT(pressedChangedHandler())); + connect(mouseArea_, SIGNAL(enabledChanged()), this, SLOT(enabledChangedHandler())); + connect(mouseArea_, SIGNAL(acceptedButtonsChanged()), this, SLOT(acceptedButtonsChangedHandler())); + //connect(mouseArea_, SIGNAL(hoverEnabledChanged()), this, SLOT(hoverEnabledChangedHandler())); + // new signals from qt5 -> + connect(mouseArea_, SIGNAL(hoveredChanged()), this, SLOT(hoveredChangedHandler())); + connect(mouseArea_, SIGNAL(positionChanged(QSGMouseEvent*)), this, SLOT(positionChangedHandler(QSGMouseEvent*))); + connect(mouseArea_, SIGNAL(entered()), this, SLOT(enteredHandler())); + connect(mouseArea_, SIGNAL(exited()), this, SLOT(exitedHandler())); + connect(mouseArea_, SIGNAL(pressAndHold(QSGMouseEvent*)), this, SLOT(pressAndHoldHandler(QSGMouseEvent*))); +} QDeclarativeGeoMapMouseArea::~QDeclarativeGeoMapMouseArea() { + delete mouseEvent_; + delete mouseArea_; } -void QDeclarativeGeoMapMouseArea::setMap(QDeclarative3DGraphicsGeoMap *map) +void QDeclarativeGeoMapMouseArea::componentComplete() { - map_ = map; + mouseArea_->setWidth(this->width()); + mouseArea_->setHeight(this->height()); + mouseArea_->setX(this->x()); + mouseArea_->setY(this->y()); + componentCompleted_ = true; + QSGItem::componentComplete(); } -QDeclarative3DGraphicsGeoMap* QDeclarativeGeoMapMouseArea::map() const +void QDeclarativeGeoMapMouseArea::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - return map_; + if (!componentCompleted_) + return; + mouseArea_->setWidth(this->width()); + mouseArea_->setHeight(this->height()); + mouseArea_->setX(this->x()); + mouseArea_->setY(this->y()); + QSGItem::geometryChanged(newGeometry, oldGeometry); } -/*! - \qmlproperty qreal MapMouseArea::mouseX - \qmlproperty qreal MapMouseArea::mouseY - - These properties hold the screen coordinates of the mouse cursor. +void QDeclarativeGeoMapMouseArea::hoveredChangedHandler() +{ + emit hoveredChanged(mouseArea_->hovered()); +} - These properties will only be valid while a button is pressed, and will - remain valid as long as the button is held down even if the mouse is moved - outside the area. +void QDeclarativeGeoMapMouseArea::pressAndHoldHandler(QSGMouseEvent* event) +{ + mapMouseEvent(event); + emit pressAndHold(mouseEvent_); +} - The screen coordinates are relative to the MouseArea. +/* hovering not supported at the moment +void QDeclarativeGeoMapMouseArea::hoverEnabledChangedHandler() +{ + emit hoverEnabledChanged(mouseArea_->hoverEnabled()); +} */ -qreal QDeclarativeGeoMapMouseArea::mouseX() const +void QDeclarativeGeoMapMouseArea::acceptedButtonsChangedHandler() { - return mouseX_; + emit acceptedButtonsChanged(mouseArea_->acceptedButtons()); } -qreal QDeclarativeGeoMapMouseArea::mouseY() const +void QDeclarativeGeoMapMouseArea::enabledChangedHandler() { - return mouseY_; + emit enabledChanged(mouseArea_->isEnabled()); } -bool QDeclarativeGeoMapMouseArea::hovered() const +void QDeclarativeGeoMapMouseArea::pressedHandler(QSGMouseEvent* event) { - return hovered_; + mapMouseEvent(event); + emit pressed(mouseEvent_); } -void QDeclarativeGeoMapMouseArea::setHovered(bool hovered) +void QDeclarativeGeoMapMouseArea::pressedChangedHandler() { - if (hovered_ == hovered) - return; + emit pressedChanged(mouseArea_->pressed()); +} + +void QDeclarativeGeoMapMouseArea::enteredHandler() +{ + emit entered(); +} + +void QDeclarativeGeoMapMouseArea::exitedHandler() +{ + emit exited(); +} + +void QDeclarativeGeoMapMouseArea::positionChangedHandler(QSGMouseEvent* event) +{ + mapMouseEvent(event); + emit positionChanged(mouseEvent_); +} + +void QDeclarativeGeoMapMouseArea::mapMouseEvent(QSGMouseEvent* event) +{ + // we could probably access these directly, + // wouldn't worsen the private header dependency much + mouseEvent_->setAccepted(event->property("accepted").toBool()); + mouseEvent_->setButton(event->property("button").toInt()); + mouseEvent_->setButtons(event->property("buttons").toInt()); + mouseEvent_->setModifiers(event->property("modifiers").toInt()); + mouseEvent_->setWasHeld(event->property("wasHeld").toBool()); + mouseEvent_->setX(event->property("x").toInt()); + mouseEvent_->setY(event->property("y").toInt()); + if (map_) + mouseEvent_->setCoordinate( + map_->map()->screenPositionToCoordinate(QPointF(mouseEvent_->x(), mouseEvent_->y()))); +} + +void QDeclarativeGeoMapMouseArea::releasedHandler(QSGMouseEvent* event) +{ + mapMouseEvent(event); + emit released(mouseEvent_); +} - hovered_ = hovered; +void QDeclarativeGeoMapMouseArea::clickedHandler(QSGMouseEvent* event) +{ + mapMouseEvent(event); + emit clicked(mouseEvent_); +} - emit hoveredChanged(hovered_); +void QDeclarativeGeoMapMouseArea::doubleClickedHandler(QSGMouseEvent* event) +{ + mapMouseEvent(event); + emit doubleClicked(mouseEvent_); +} - if (hovered_) - emit entered(); - else - emit exited(); +void QDeclarativeGeoMapMouseArea::setMap(QDeclarative3DGraphicsGeoMap *map) +{ + Q_ASSERT(map); + map_ = map; } /*! - \qmlproperty bool MapMouseArea::pressed - This property holds whether the mouse area is currently pressed. + \qmlproperty real MapMouseArea::mouseX + \qmlproperty real MapMouseArea::mouseY + + These properties hold the screen coordinates of the mouse cursor. + + These properties will only be valid while a button is pressed, and will remain + valid as long as the button is held down even if the mouse is moved outside the area. + + The screen coordinates are relative to the MapMouseArea. */ -bool QDeclarativeGeoMapMouseArea::pressed() const +qreal QDeclarativeGeoMapMouseArea::mouseX() const { - return pressed_; + return mouseArea_->mouseX(); } -bool QDeclarativeGeoMapMouseArea::setPressed(bool pressed, QDeclarativeGeoMapMouseEvent *event) +qreal QDeclarativeGeoMapMouseArea::mouseY() const { - if (pressed_ == pressed) - return false; - - bool isClick = pressed_ && !pressed;// && hovered_; + return mouseArea_->mouseY(); +} - pressed_ = pressed; +/*! + \qmlproperty bool MapMouseArea::containsMouse + This property holds whether the mouse is currently inside the mouse area. - if (pressed_) { - if (!doubleClick_) - emit QDeclarativeGeoMapMouseArea::pressed(event); - } else { - emit released(event); - // TODO set saved position in event? - if (isClick && !longPress_ && !doubleClick_) { - emit clicked(event); + \warning This property is not updated if the area moves under the mouse: \e containsMouse will not change. + In addition, containsMouse will only be valid when the mouse is pressed. +*/ - } - } +bool QDeclarativeGeoMapMouseArea::hovered() const +{ + return mouseArea_->hovered(); +} - emit pressedChanged(pressed_); +/*! + \qmlproperty bool MapMouseArea::pressed + This property holds whether the mouse area is currently pressed. +*/ - return event->accepted(); +bool QDeclarativeGeoMapMouseArea::pressed() const +{ + return mouseArea_->pressed(); } /*! @@ -182,24 +306,19 @@ bool QDeclarativeGeoMapMouseArea::setPressed(bool pressed, QDeclarativeGeoMapMou bool QDeclarativeGeoMapMouseArea::isEnabled() const { - return enabled_; + return mouseArea_->isEnabled(); } void QDeclarativeGeoMapMouseArea::setEnabled(bool enabled) { - if (enabled_ == enabled) - return; - - enabled_ = enabled; - - emit enabledChanged(enabled_); + mouseArea_->setEnabled(enabled); } /*! - \qmlproperty MouseButton MapMouseArea::pressedButton - This property holds the mouse button currently pressed. + \qmlproperty MouseButton MapMouseArea::pressedButtons + This property holds the mouse buttons currently pressed. - It is one of: + It contains a bitwise combination of: \list \o Qt.LeftButton \o Qt.RightButton @@ -209,12 +328,11 @@ void QDeclarativeGeoMapMouseArea::setEnabled(bool enabled) \sa acceptedButtons */ -Qt::MouseButton QDeclarativeGeoMapMouseArea::pressedButton() const +Qt::MouseButtons QDeclarativeGeoMapMouseArea::pressedButtons() const { - return pressedButton_; + return static_cast<Qt::MouseButtons>(mouseEvent_->button()); } - /*! \qmlproperty Qt::MouseButtons MapMouseArea::acceptedButtons This property holds the mouse buttons that the mouse area reacts to. @@ -238,129 +356,65 @@ Qt::MouseButton QDeclarativeGeoMapMouseArea::pressedButton() const void QDeclarativeGeoMapMouseArea::setAcceptedButtons(Qt::MouseButtons acceptedButtons) { - if (acceptedButtons_ == acceptedButtons) - return; - - acceptedButtons_ = acceptedButtons; - - emit acceptedButtonsChanged(acceptedButtons_); + mouseArea_->setAcceptedButtons(acceptedButtons); + setAcceptedMouseButtons(acceptedButtons); } Qt::MouseButtons QDeclarativeGeoMapMouseArea::acceptedButtons() const { - return acceptedButtons_; -} - -bool QDeclarativeGeoMapMouseArea::hoverEnabled() const -{ - return hoverEnabled_; + return mouseArea_->acceptedButtons(); } -void QDeclarativeGeoMapMouseArea::setHoverEnabled(bool hoverEnabled) -{ - if (hoverEnabled == hoverEnabled_) - return; +/* hover is currently not supported + \qmlproperty bool MapMouseArea::hoverEnabled + This property holds whether hover events are handled. - hoverEnabled_ = hoverEnabled; - //setAcceptsHoverEvents(hoverEnabled_); - setAcceptHoverEvents(hoverEnabled_); - setAcceptedMouseButtons(Qt::LeftButton); - emit hoverEnabledChanged(hoverEnabled_); - // TODO update hovered property -} + By default, mouse events are only handled in response to a button event, or when a button is + pressed. Hover enables handling of all mouse events even when no mouse button is + pressed. + This property affects the \l containsMouse property and the \l onEntered, \l onExited and + \l onPositionChanged signals. - - - - -void QDeclarativeGeoMapMouseArea::doubleClickEvent(QDeclarativeGeoMapMouseEvent *event) +bool QDeclarativeGeoMapMouseArea::hoverEnabled() const { - if (!enabled_) { - //TODO QSGItem::mouseDoubleClickEvent(convert event to regular event here) - return; - } - // TODO check this properly - bool doubleClickConnected = true; - - if (doubleClickConnected) - doubleClick_ = true; - // TODO save event - event->setAccepted(doubleClickConnected); - emit doubleClicked(event); - // TODO QSGItem::mouseDoubleClickEvent(convert event to regular event here) - - map_->setActiveMouseArea(0); + return mouseArea_->hoverEnabled(); } -void QDeclarativeGeoMapMouseArea::pressEvent(QDeclarativeGeoMapMouseEvent *event) +void QDeclarativeGeoMapMouseArea::setHoverEnabled(bool hoverEnabled) { - if (!enabled_) { - //TODO QSGItem::mousePressEvent(convert event to regular event here) - return; - } - - event->setAccepted(true); - - longPress_ = false; - // TODO save event - mouseX_ = event->x(); - mouseY_ = event->y(); - pressedButton_ = Qt::MouseButton(event->button()); - modifiers_ = Qt::KeyboardModifiers(event->modifiers()); - - //setHovered(true); - // TODO setup long press timer - event->setAccepted(setPressed(true, event)); - - if (event->accepted()) - map_->setActiveMouseArea(this); + mouseArea_->setHoverEnabled(hoverEnabled); } -void QDeclarativeGeoMapMouseArea::releaseEvent(QDeclarativeGeoMapMouseEvent *event) +bool QDeclarativeGeoMapMouseArea::hoverEvent(QHoverEvent *event) { - if (!enabled_) { - //TODO QSGItem::mouseReleaseEvent(convert event to regular event here) - return; + if (!map_ || !map_->canvas()) { + qmlInfo(this) << "Warning: no qsgcanvas available, cannot dispatch the mouse event"; + return false; } - - // save event - setPressed(false, event); - pressedButton_ = Qt::NoButton; - modifiers_ = Qt::NoModifier; - doubleClick_ = false; -} - -void QDeclarativeGeoMapMouseArea::enterEvent() -{ - if (!enabled_ || !hoverEnabled()) - return; - - setHovered(true); - - emit entered(); -} - -void QDeclarativeGeoMapMouseArea::exitEvent() -{ - if (!enabled_ || !hoverEnabled()) - return; - - setHovered(false); - - emit exited(); + // we need to filter hover events to mimic regular MouseArea's behavior + if (!mouseArea_->hoverEnabled()) { + return false; + } + map_->canvas()->sendEvent(mouseArea_, event); + return true; } +*/ -void QDeclarativeGeoMapMouseArea::moveEvent(QDeclarativeGeoMapMouseEvent *event) +bool QDeclarativeGeoMapMouseArea::mouseEvent(QMouseEvent *event) { - if (!enabled_) - return; - - event->setButton(pressedButton_); - event->setModifiers(modifiers_); - - emit positionChanged(event); + if (!map_ || !map_->canvas()) { + qmlInfo(this) << "Warning: no qsgcanvas available, cannot dispatch the mouse event"; + return false; + } + if (!mouseArea_->isEnabled()) { + QLOC_TRACE2("mouse area not enabled.", objectName()); + event->ignore(); + return false; + } + map_->canvas()->sendEvent(mouseArea_, event); + return event->isAccepted(); // hmm.. } /*! @@ -420,6 +474,52 @@ void QDeclarativeGeoMapMouseArea::moveEvent(QDeclarativeGeoMapMouseEvent *event) The accepted property defaults to true. */ +/*! + \qmlsignal MapMouseArea::onEntered() + + This handler is called when the mouse enters the mouse area. + + The onEntered handler is only called while a button is + pressed. + + \sa onExited() +*/ + +/*! + \qmlsignal MapMouseArea::onPositionChanged(MapMouseEvent mouse) + + This handler is called when the mouse position changes. + + The \l {MapMouseEvent}{mouse} parameter provides information about the mouse, including the x and y + position, and any buttons currently pressed. + + The \e accepted property of the MapMouseEvent parameter is ignored in this handler. + + The onPositionChanged handler is only called while a button is pressed. +*/ + +/*! + \qmlsignal MapMouseArea::onPressAndHold(MapMouseEvent mouse) + + This handler is called when there is a long press (currently 800ms). + The \l {MapMouseEvent}{mouse} parameter provides information about the press, including the x and y + position of the press, and which button is pressed. + + The \e accepted property of the MapMouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MapMouseArea::onExited() + + This handler is called when the mouse exits the mouse area. + + The onExited handler is only called while a button is pressed. + + \sa onEntered() +*/ + +#endif // QSGMOUSEAREA_AVAILABLE + #include "moc_qdeclarativegeomapmousearea_p.cpp" QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapmousearea_p.h b/src/imports/location/qdeclarativegeomapmousearea_p.h index bd388e54..07766449 100644 --- a/src/imports/location/qdeclarativegeomapmousearea_p.h +++ b/src/imports/location/qdeclarativegeomapmousearea_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -46,40 +46,50 @@ #include "qdeclarative3dgraphicsgeomap_p.h" #include "qdeclarativegeomapmouseevent_p.h" -// !!! IMPORTANT !!! -// -// Inheriting from QSGItem here -// is just a workaround to have non-gui related (ie where visualization is not -// the main thing) autotests to pass in QML2 environment. -// Real QML2 Map support (and related map object is a work in progress elsewhere. -// This Map element instantiates but does not do anything meaningful from app dev -// perspective. -// -// !!! IMPORTANT !!! - #include <QtDeclarative/QSGItem> QT_BEGIN_NAMESPACE +#ifndef QSGMOUSEAREA_AVAILABLE + class QDeclarativeGeoMapMouseArea : public QSGItem { Q_OBJECT - Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged) - Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged) +public: + void setMap(QDeclarative3DGraphicsGeoMap *map) {Q_UNUSED(map);} + bool mouseEvent(QMouseEvent* event) {Q_UNUSED(event); return false;} + + QDeclarativeGeoMapMouseArea(QSGItem *parent = 0) { Q_UNUSED(parent); qWarning("=================== using map mouse area stub ===============");} + ~QDeclarativeGeoMapMouseArea() {} +}; + +#else + +class QSGMouseArea; +class QSGMouseEvent; + +class QDeclarativeGeoMapMouseArea : public QSGItem +{ + Q_OBJECT + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(Qt::MouseButton pressedButton READ pressedButton NOTIFY pressedButtonChanged) + Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) + // placeholder (if hover will be enabled) + //Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) public: QDeclarativeGeoMapMouseArea(QSGItem *parent = 0); ~QDeclarativeGeoMapMouseArea(); + // From QDeclarativeParserStatus + virtual void componentComplete(); + void setMap(QDeclarative3DGraphicsGeoMap *map); - QDeclarative3DGraphicsGeoMap* map() const; qreal mouseX() const; qreal mouseY() const; @@ -89,67 +99,63 @@ public: bool isEnabled() const; void setEnabled(bool enabled); - Qt::MouseButton pressedButton() const; + Qt::MouseButtons pressedButtons() const; - bool hoverEnabled() const; - void setHoverEnabled(bool hoverEnabled); + //bool hoverEnabled() const; + //void setHoverEnabled(bool hoverEnabled); void setAcceptedButtons(Qt::MouseButtons acceptedButtons); Qt::MouseButtons acceptedButtons() const; - void doubleClickEvent(QDeclarativeGeoMapMouseEvent *event); - void pressEvent(QDeclarativeGeoMapMouseEvent *event); - void releaseEvent(QDeclarativeGeoMapMouseEvent *event); - void enterEvent(); - void exitEvent(); - void moveEvent(QDeclarativeGeoMapMouseEvent *event); + bool mouseEvent(QMouseEvent* event); + //bool hoverEvent(QHoverEvent* event); Q_SIGNALS: - void mousePositionChanged(); - void hoveredChanged(bool hovered); - void pressedChanged(bool pressed); - void enabledChanged(bool enabled); - void pressedButtonChanged(Qt::MouseButtons pressedButton); - void acceptedButtonsChanged(Qt::MouseButtons acceptedButtons); - void hoverEnabledChanged(bool hoverEnabled); - - void positionChanged(QDeclarativeGeoMapMouseEvent *mouse); - void pressed(QDeclarativeGeoMapMouseEvent *mouse); -// void pressAndHold(QDeclarativeGeoMapMouseEvent *mouse); - void released(QDeclarativeGeoMapMouseEvent *mouse); + // publicly supported (i.e. documented) signals: void clicked(QDeclarativeGeoMapMouseEvent *mouse); void doubleClicked(QDeclarativeGeoMapMouseEvent *mouse); + void pressed(QDeclarativeGeoMapMouseEvent *mouse); + void released(QDeclarativeGeoMapMouseEvent *mouse); + void positionChanged(QDeclarativeGeoMapMouseEvent *mouse); + void pressAndHold(QDeclarativeGeoMapMouseEvent *mouse); void entered(); void exited(); -// void cancelled(); + // internal signals (non documented, used as property notifiers): + void hoveredChanged(bool hovered); + void pressedChanged(bool pressed); + void enabledChanged(bool enabled); + void acceptedButtonsChanged(Qt::MouseButtons acceptedButtons); + //void hoverEnabledChanged(bool hoverEnabled); + +protected: + // from QSGItem + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + +private slots: + void pressedHandler(QSGMouseEvent* event); + void releasedHandler(QSGMouseEvent* event); + void clickedHandler(QSGMouseEvent* event); + void doubleClickedHandler(QSGMouseEvent* event); + void positionChangedHandler(QSGMouseEvent* event); + void pressAndHoldHandler(QSGMouseEvent* event); + void enteredHandler(); + void exitedHandler(); + void canceledHandler(); + void enabledChangedHandler(); + void acceptedButtonsChangedHandler(); + //void hoverEnabledChangedHandler(); + void pressedChangedHandler(); + void hoveredChangedHandler(); private: - bool setPressed(bool pressed, QDeclarativeGeoMapMouseEvent *event); - void setHovered(bool hovered); - - bool hovered_; - bool enabled_; - bool hoverEnabled_; - qreal mouseX_; - qreal mouseY_; - bool pressed_; - bool longPress_; - bool doubleClick_; - Qt::MouseButtons acceptedButtons_; - Qt::MouseButton pressedButton_; - Qt::KeyboardModifiers modifiers_; - -// qreal startX_; -// qreal startY_; -// QPointF lastPos_; -// QPointF lastScenePos_; -// Qt::MouseButton lastButton_; -// Qt::MouseButtons lastButtons_; -// Qt::KeyboardModifiers lastModifiers_; - + void mapMouseEvent(QSGMouseEvent* event); + QDeclarativeGeoMapMouseEvent* mouseEvent_; QDeclarative3DGraphicsGeoMap* map_; + QSGMouseArea* mouseArea_; + bool componentCompleted_; }; +#endif // QSGMOUSEAREA_AVAILABLE QT_END_NAMESPACE QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeGeoMapMouseArea)); diff --git a/src/imports/location/qdeclarativegeomapmouseevent.cpp b/src/imports/location/qdeclarativegeomapmouseevent.cpp index c979e836..9fa959d3 100644 --- a/src/imports/location/qdeclarativegeomapmouseevent.cpp +++ b/src/imports/location/qdeclarativegeomapmouseevent.cpp @@ -61,7 +61,11 @@ QDeclarativeGeoMapMouseEvent::QDeclarativeGeoMapMouseEvent(QObject *parent) : QObject(parent), accepted_(false), button_(Qt::NoButton), - coordinate_(0) + modifiers_(Qt::NoModifier), + wasHeld_(false), + x_(0), + y_(0), + buttons_(Qt::NoButton) { } @@ -76,8 +80,7 @@ QDeclarativeGeoMapMouseEvent::~QDeclarativeGeoMapMouseEvent() propagated to items below this item. Generally, if the item acts on the mouse event then it should be accepted - so that items lower in the stacking order do not also respond to the same ev -ent. + so that items lower in the stacking order do not also respond to the same event. */ void QDeclarativeGeoMapMouseEvent::setAccepted(bool accepted) @@ -94,11 +97,14 @@ bool QDeclarativeGeoMapMouseEvent::accepted() const \qmlproperty enumeration MapMouseEvent::button This property holds the button that caused the event. It can be one of: + \list \o Qt.LeftButton \o Qt.RightButton \o Qt.MiddleButton \endlist + + \sa buttons */ void QDeclarativeGeoMapMouseEvent::setButton(int button) @@ -112,6 +118,36 @@ int QDeclarativeGeoMapMouseEvent::button() const } /*! + \qmlproperty enumeration MapMouseEvent::buttons + + This property holds the mouse buttons pressed when the event was + generated. For mouse move events, this is all buttons that are pressed + down. For mouse press and double click events this includes the button + that caused the event. For mouse release events this excludes the button + that caused the event. + + It contains a bitwise combination of: + + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MiddleButton + \endlist + + \sa button +*/ + +void QDeclarativeGeoMapMouseEvent::setButtons(int buttons) +{ + buttons_ = buttons; +} + +int QDeclarativeGeoMapMouseEvent::buttons() const +{ + return buttons_; +} + +/*! \qmlproperty int MapMouseEvent::modifiers This property holds the keyboard modifier flags that existed immediately @@ -138,15 +174,21 @@ int QDeclarativeGeoMapMouseEvent::modifiers() const return modifiers_; } -//void QDeclarativeGeoMapMouseEvent::setWasHeld(bool wasHeld) -//{ -// wasHeld_ = wasHeld; -//} +/*! + \qmlproperty bool MapMouseEvent::wasHeld -//bool QDeclarativeGeoMapMouseEvent::wasHeld() const -//{ -// return wasHeld_; -//} + This property is true if the mouse button has been held pressed longer the threshold (800ms). +*/ + +void QDeclarativeGeoMapMouseEvent::setWasHeld(bool wasHeld) +{ + wasHeld_ = wasHeld; +} + +bool QDeclarativeGeoMapMouseEvent::wasHeld() const +{ + return wasHeld_; +} /*! \qmlproperty int MapMouseEvent::x @@ -184,17 +226,14 @@ int QDeclarativeGeoMapMouseEvent::y() const occurred. */ -void QDeclarativeGeoMapMouseEvent::setCoordinate(QDeclarativeCoordinate *coordinate) +void QDeclarativeGeoMapMouseEvent::setCoordinate(QGeoCoordinate coordinate) { - if (!coordinate || (coordinate == coordinate_)) - return; - - coordinate_ = coordinate; + coordinate_.setCoordinate(coordinate); } QDeclarativeCoordinate* QDeclarativeGeoMapMouseEvent::coordinate() { - return coordinate_; + return &coordinate_; } #include "moc_qdeclarativegeomapmouseevent_p.cpp" diff --git a/src/imports/location/qdeclarativegeomapmouseevent_p.h b/src/imports/location/qdeclarativegeomapmouseevent_p.h index f1da2afe..f16deb4b 100644 --- a/src/imports/location/qdeclarativegeomapmouseevent_p.h +++ b/src/imports/location/qdeclarativegeomapmouseevent_p.h @@ -54,8 +54,9 @@ class QDeclarativeGeoMapMouseEvent : public QObject Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) Q_PROPERTY(int button READ button) + Q_PROPERTY(int buttons READ buttons) Q_PROPERTY(int modifiers READ modifiers) -// Q_PROPERTY(bool wasHeld READ wasHeld) + Q_PROPERTY(bool wasHeld READ wasHeld) Q_PROPERTY(int x READ x) Q_PROPERTY(int y READ y) Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate) @@ -70,11 +71,14 @@ public: void setButton(int button); int button() const; + void setButtons(int buttons); + int buttons() const; + void setModifiers(int modifiers); int modifiers() const; -// void setWasHeld(bool wasHeld); -// bool wasHeld() const; + void setWasHeld(bool wasHeld); + bool wasHeld() const; void setX(int x); int x() const; @@ -82,17 +86,18 @@ public: void setY(int y); int y() const; - void setCoordinate(QDeclarativeCoordinate *coordinate); + void setCoordinate(QGeoCoordinate coordinate); QDeclarativeCoordinate* coordinate(); private: bool accepted_; int button_; int modifiers_; -// bool wasHeld_; + bool wasHeld_; int x_; int y_; - QDeclarativeCoordinate *coordinate_; + int buttons_; + QDeclarativeCoordinate coordinate_; }; QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomappincharea.cpp b/src/imports/location/qdeclarativegeomappincharea.cpp index 1c4c8a91..880d10b7 100644 --- a/src/imports/location/qdeclarativegeomappincharea.cpp +++ b/src/imports/location/qdeclarativegeomappincharea.cpp @@ -42,7 +42,7 @@ #include <QtWidgets/QApplication> #include "qdeclarativegeomappincharea_p.h" #include "qdeclarative3dgraphicsgeomap_p.h" -#include <QGraphicsSceneMouseEvent> +#include <QtGui/qevent.h> #include <QDebug> #include "math.h" #include "map.h" @@ -247,21 +247,21 @@ void QDeclarativeGeoMapPinchArea::setMaximumTiltChange(qreal tilt) emit maximumTiltChangeChanged(); } -void QDeclarativeGeoMapPinchArea::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapPinchArea::mousePressEvent(QMouseEvent *event) { Q_UNUSED(event); // TODO may not be needed at all if (!enabled_) return; } -void QDeclarativeGeoMapPinchArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapPinchArea::mouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); // TODO may not be needed at all if (!enabled_) return; } -void QDeclarativeGeoMapPinchArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativeGeoMapPinchArea::mouseMoveEvent(QMouseEvent *event) { Q_UNUSED(event); // TODO may not be needed at all if (!enabled_) diff --git a/src/imports/location/qdeclarativegeomappincharea_p.h b/src/imports/location/qdeclarativegeomappincharea_p.h index fcd3236d..b81c725d 100644 --- a/src/imports/location/qdeclarativegeomappincharea_p.h +++ b/src/imports/location/qdeclarativegeomappincharea_p.h @@ -188,9 +188,9 @@ public: void setMaximumTiltChange(qreal tilt); // TODO likely we only need touchEvent, not mouseEvents. - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); void touchEvent(QTouchEvent *event); signals: diff --git a/src/location/mapsgl/tilecache.cpp b/src/location/mapsgl/tilecache.cpp index 03daa710..9dd41631 100644 --- a/src/location/mapsgl/tilecache.cpp +++ b/src/location/mapsgl/tilecache.cpp @@ -396,16 +396,17 @@ void TileCache::loadTiles() //QStringList files = dir.entryList(formats, QDir::Files, QDir::Time | QDir::Reversed); QStringList files = dir.entryList(formats, QDir::Files); - qDebug() << __FUNCTION__ << "tiles: " << files.size(); + int tiles = 0; for (int i = 0; i < files.size(); ++i) { - TileSpec spec = filenameToTileSpec(files.at(i)); if (spec.zoom() == -1) continue; QString filename = dir.filePath(files.at(i)); - qDebug() << __FUNCTION__ << "tile iteration: " << i; addToDiskCache(spec, filename); + tiles++; } + qDebug() << __FUNCTION__ << " loaded this many map tiles to cache: " << tiles; + } QString TileCache::tileSpecToFilename(const TileSpec &spec, const QString &directory) diff --git a/tests/auto/declarative/tst_map_mouse.qml b/tests/auto/declarative/tst_map_mouse.qml index 92d86e41..3a8a36e2 100644 --- a/tests/auto/declarative/tst_map_mouse.qml +++ b/tests/auto/declarative/tst_map_mouse.qml @@ -42,69 +42,642 @@ import QtQuick 2.0 import QtTest 1.0 import Qt.location 5.0 +import Qt.location.test 5.0 + + /* + MapMouseArea setup for this test case. + Map dimensions are 100 * 100 + Item containing map is 120,120 + + (50,50) + (0,0) ---------------------------------------------------- (100,0) + | no mouse area | mouse area overlapper | + | | | + (0,20) ---------------------------------------------------- (100,20) + | mouse area upper | mouse area upper, | + | | mouse area overlapper | + | | | + | | | + | | | + (0,50) ---------------------------------------------------- (100,50) + | mouse area lower | mouse area lower, | + | | mouse area overlapper | + | | | + | | | + | | | + | | | + | | | + | | | + (0,100) ---------------------------------------------------- (100,100) | + | + | + ----------(120, 120) + + */ Item { - id: masterItem + id: page + x: 0; y: 0; + width: 120 + height: 120 // General-purpose elements for the test: Plugin { id: testPlugin; name : "nokia"; PluginParameter {name: "mapping.host"; value: "for.nonexistent"}} - //Coordinate{ id: mapDefaultCenter; latitude: 10; longitude: 10} - Coordinate{ id: mapDefaultCenter; latitude: 0; longitude: 0} - Coordinate{ id: topLeftCoord; latitude: 10; longitude: 11} - Coordinate{ id: bottomRightCoord; latitude: 12; longitude: 13} - MapMouseEvent{ id: dummyMouseEvent;} - Rectangle {id: rektankeli; anchors.top: parent.top; width: parent.width; height: 20} + Coordinate{ id: mapDefaultCenter; latitude: 20; longitude: 20} + + MapMouseEvent{ + id: mapMouseEvent + } + Map { - id: mouseMap; - anchors.top: rektankeli.bottom + id: map; + x: 0; y: 0; width: 100; height: 100 center: mapDefaultCenter plugin: testPlugin; + + property real lastWheelDelta: 0 + onWheel: lastWheelDelta = delta + MapMouseArea { - id: mapMouse - enabled: true - //onClicked: console.log('mouse area clicked mapMouse') - } - MapCircle { - MapMouseArea { - id: circleMouse - //onClicked: console.log('mouse area clicked circleMouse') - } - } - MapRectangle { - topLeft: topLeftCoord - bottomRight: bottomRightCoord - MapMouseArea { - id: rectangleMouse - enabled: false - //onClicked: console.log('mouse area clicked rectanglemouse') - } + id: mouseUpper + objectName: "mouseUpper" + x: 0; y: 20; width: 100; height: 29 + property variant lastMouseEvent: null + onClicked: lastMouseEvent = mouse + onDoubleClicked: lastMouseEvent = mouse + onPressed: lastMouseEvent = mouse + onReleased: lastMouseEvent = mouse + onPositionChanged: lastMouseEvent = mouse + onPressAndHold: lastMouseEvent = mouse + } + MapMouseArea { + id: mouseLower + objectName: "mouseLower" + x: 0; y: 50; width: 100; height: 50 + property variant lastMouseEvent: null + onClicked: lastMouseEvent = mouse + onDoubleClicked: lastMouseEvent = mouse + onPressed: lastMouseEvent = mouse + onReleased: lastMouseEvent = mouse + onPositionChanged: lastMouseEvent = mouse + onPressAndHold: lastMouseEvent = mouse + } + MapMouseArea { + id: mouseOverlapper + objectName: "mouseOverlapper" + x: 50; y: 0; width: 50; height: 100 + property variant lastMouseEvent: null + onClicked: lastMouseEvent = mouse + onDoubleClicked: lastMouseEvent = mouse + onPressed: lastMouseEvent = mouse + onReleased: { console.log('overlapper released'); lastMouseEvent = mouse } + onPositionChanged: lastMouseEvent = mouse + onPressAndHold: { console.log('overlapper pressandhold'); lastMouseEvent = mouse } } } + TestCase { - name: "MapMouse" + name: "MapMouseArea" when: windowShown - SignalSpy {id: rectangleClickedSpy; target: rectangleMouse; signalName: "clicked"} - SignalSpy {id: rectangleEnabledSpy; target: rectangleMouse; signalName: "enabledChanged"} - SignalSpy {id: rectangleAcceptedButtonsSpy; target: rectangleMouse; signalName: "acceptedButtonsChanged"} - function test_signals() { - // 1. Default values - compare (circleMouse.mouseX, 0) - compare (circleMouse.mouseY, 0) - compare (circleMouse.pressed, false) - compare (circleMouse.enabled, true) - // 2. Basic changes - compare (rectangleEnabledSpy.count, 0) - compare (rectangleAcceptedButtonsSpy.count, 0) - rectangleMouse.enabled = true - rectangleMouse.acceptedButtons = Qt.MiddleButton - compare (rectangleEnabledSpy.count, 1) - compare (rectangleAcceptedButtonsSpy.count, 1) - // 3. Clicking - // MousePress does not work for some reason. It propagates all the way - // to the QDeclarativeView but never reaches the graphics geo map. - // That should be solved to really be able to test the mouse. - //mousePress(masterItem, 5, 5) - //mousePress(mouseMap, 20, 20) - //compare(rectangleClickedSpy.count, 1) + SignalSpy {id: mouseUpperClickedSpy; target: mouseUpper; signalName: "clicked"} + SignalSpy {id: mouseLowerClickedSpy; target: mouseLower; signalName: "clicked"} + SignalSpy {id: mouseOverlapperClickedSpy; target: mouseOverlapper; signalName: "clicked"} + SignalSpy {id: mouseUpperDoubleClickedSpy; target: mouseUpper; signalName: "doubleClicked"} + SignalSpy {id: mouseLowerDoubleClickedSpy; target: mouseLower; signalName: "doubleClicked"} + SignalSpy {id: mouseOverlapperDoubleClickedSpy; target: mouseOverlapper; signalName: "doubleClicked"} + SignalSpy {id: mouseUpperPressedSpy; target: mouseUpper; signalName: "onPressed"} + SignalSpy {id: mouseLowerPressedSpy; target: mouseLower; signalName: "onPressed"} + SignalSpy {id: mouseOverlapperPressedSpy; target: mouseOverlapper; signalName: "onPressed"} + SignalSpy {id: mouseUpperReleasedSpy; target: mouseUpper; signalName: "released"} + SignalSpy {id: mouseLowerReleasedSpy; target: mouseLower; signalName: "released"} + SignalSpy {id: mouseOverlapperReleasedSpy; target: mouseOverlapper; signalName: "released"} + SignalSpy {id: mouseUpperPositionChangedSpy; target: mouseUpper; signalName: "positionChanged"} + SignalSpy {id: mouseLowerPositionChangedSpy; target: mouseLower; signalName: "positionChanged"} + SignalSpy {id: mouseOverlapperPositionChangedSpy; target: mouseOverlapper; signalName: "positionChanged"} + SignalSpy {id: mouseUpperPressAndHoldSpy; target: mouseUpper; signalName: "pressAndHold"} + SignalSpy {id: mouseLowerPressAndHoldSpy; target: mouseLower; signalName: "pressAndHold"} + SignalSpy {id: mouseOverlapperPressAndHoldSpy; target: mouseOverlapper; signalName: "pressAndHold"} + SignalSpy {id: mouseUpperEnteredSpy; target: mouseUpper; signalName: "entered"} + SignalSpy {id: mouseLowerEnteredSpy; target: mouseLower; signalName: "entered"} + SignalSpy {id: mouseOverlapperEnteredSpy; target: mouseOverlapper; signalName: "entered"} + SignalSpy {id: mouseUpperExitedSpy; target: mouseUpper; signalName: "exited"} + SignalSpy {id: mouseLowerExitedSpy; target: mouseLower; signalName: "exited"} + SignalSpy {id: mouseOverlapperExitedSpy; target: mouseOverlapper; signalName: "exited"} + + SignalSpy {id: mouseUpperEnabledChangedSpy; target: mouseUpper; signalName: "enabledChanged"} + SignalSpy {id: mouseUpperAcceptedButtonsChangedSpy; target: mouseUpper; signalName: "acceptedButtonsChanged"} + SignalSpy {id: mouseUpperPressedButtonsChangedSpy; target: mouseUpper; signalName: "pressedChanged"} + SignalSpy {id: mouseUpperHoveredChangedSpy; target: mouseUpper; signalName: "hoveredChanged"} + SignalSpy {id: mouseUpperPressedChangedSpy; target: mouseUpper; signalName: "pressedChanged"} + + SignalSpy {id: mouseOverlapperEnabledChangedSpy; target: mouseOverlapper; signalName: "enabledChanged"} + + SignalSpy {id: mapWheelSpy; target: map; signalName: "wheel"} + + function clear_data() { + map.lastWheelDelta = 0 + mouseUpper.lastMouseEvent = null + mouseLower.lastMouseEvent = null + mouseOverlapper.lastMouseEvent = null + + mouseUpperClickedSpy.clear() + mouseLowerClickedSpy.clear() + mouseOverlapperClickedSpy.clear() + mouseUpperDoubleClickedSpy.clear() + mouseLowerDoubleClickedSpy.clear() + mouseOverlapperDoubleClickedSpy.clear() + mouseUpperPressedSpy.clear() + mouseLowerPressedSpy.clear() + mouseOverlapperPressedSpy.clear() + mouseUpperReleasedSpy.clear() + mouseLowerReleasedSpy.clear() + mouseOverlapperReleasedSpy.clear() + mouseUpperPositionChangedSpy.clear() + mouseLowerPositionChangedSpy.clear() + mouseOverlapperPositionChangedSpy.clear() + mouseUpperPressAndHoldSpy.clear() + mouseLowerPressAndHoldSpy.clear() + mouseOverlapperPressAndHoldSpy.clear() + mouseUpperEnteredSpy.clear() + mouseLowerEnteredSpy.clear() + mouseOverlapperEnteredSpy.clear() + mouseUpperExitedSpy.clear() + mouseLowerExitedSpy.clear() + mouseOverlapperExitedSpy.clear() + + mouseUpperEnabledChangedSpy.clear() + mouseUpperAcceptedButtonsChangedSpy.clear() + mouseUpperPressedButtonsChangedSpy.clear() + mouseUpperHoveredChangedSpy.clear() + mouseUpperPressedChangedSpy.clear() + mouseUpperPositionChangedSpy.clear() + + mouseOverlapperEnabledChangedSpy.clear() + } + // these 'real_' prefixed functions do sequences as + // it would occur on real app (e.g. doubleclick is in fact + // a sequence of press, release, doubleclick, release). + // (they were recorded as seen on test app). mouseClick() works ok + // because testlib internally converts it to mousePress + mouseRelease events + function real_click (target, x, y) { + mousePress(target, x,y) + mouseRelease(target, x, y) + } + function real_double_click (target, x, y) { + mousePress(target, x,y) + mouseRelease(target, x, y) + mouseDoubleClick(target, x, y) + mouseRelease(target, x, y) + } + function real_press_and_hold(target, x,y) { + mousePress(target,x,y) + wait(850) // threshold is 800 ms + mouseRelease(target,x, y) + } + + function test_enabled() { + clear_data() + // check that disabling overlapping mouse areas let events flow through + mouseUpper.enabled = false + compare(mouseUpperEnabledChangedSpy.count, 1) + compare(mouseUpperClickedSpy.count, 0) + mouseClick(map, 5, 25) + compare(mouseUpperClickedSpy.count, 0) + mouseUpper.enabled = true + mouseClick(map, 5, 25) + compare(mouseUpperClickedSpy.count, 1) + compare(mouseUpperEnabledChangedSpy.count, 2) + // when overlapping are is disabled, the event should flow through + compare(mouseOverlapperClickedSpy.count, 0) + mouseClick(map, 55, 25) + compare(mouseUpperClickedSpy.count, 1) + compare(mouseOverlapperClickedSpy.count, 1) + mouseOverlapper.enabled = false + compare(mouseOverlapperEnabledChangedSpy.count, 1) + compare(mouseOverlapper.enabled, false) + mouseClick(map, 55, 25) + compare(mouseOverlapperClickedSpy.count, 1) + compare(mouseUpperClickedSpy.count, 2) + // re-enable and verify that still works + mouseOverlapper.enabled = true + compare(mouseOverlapperEnabledChangedSpy.count, 2) + compare(mouseOverlapper.enabled, true) + mouseClick(map, 55, 25) + compare(mouseOverlapperClickedSpy.count, 2) // should consume again + compare(mouseUpperClickedSpy.count, 2) + } + + function test_wheel() { + clear_data() + // on map but without mouse area + mouseWheel(map, 5, 5, 15, Qt.LeftButton, Qt.NoModifiers) + compare(mapWheelSpy.count, 1) + compare(map.lastWheelDelta, 15) + mouseWheel(map, 5, 5, -15, Qt.LeftButton, Qt.NoModifiers) + compare(mapWheelSpy.count, 2) + compare(map.lastWheelDelta, -15) + // on map on top of mouse area + mouseWheel(map, 55, 75, -30, Qt.LeftButton, Qt.NoModifiers) + compare(mapWheelSpy.count, 3) + compare(map.lastWheelDelta, -30) + // outside of map + mouseWheel(map, -100, -100, 30, Qt.LeftButton, Qt.NoModifiers) + compare(mapWheelSpy.count, 3) + compare(map.lastWheelDelta, -30) + } + + function test_aaa_basic_properties() // _aaa_ to ensure execution first + { + clear_data() + // default values + compare(mouseUpper.containsMouse, false) + compare(mouseUpper.pressed, false) + compare(mouseUpper.enabled, true) + compare(mouseUpper.pressedButtons, 0) + compare(mouseUpper.acceptedButtons, Qt.LeftButton) + // accepted buttons + compare(mouseUpperAcceptedButtonsChangedSpy.count, 0) + mouseUpper.acceptedButtons = Qt.RightButton | Qt.MiddleButton + compare(mouseUpper.acceptedButtons, Qt.RightButton | Qt.MiddleButton) + compare(mouseUpperAcceptedButtonsChangedSpy.count, 1) + mouseClick(map, 5, 25) + compare(mouseUpperClickedSpy.count, 0) // left button not accepted + mouseUpper.acceptedButtons = Qt.LeftButton + compare(mouseUpperAcceptedButtonsChangedSpy.count, 2) + mouseClick(map, 5, 25) + compare(mouseUpperClickedSpy.count, 1) + } + + function test_aab_event_basic_properties() { + compare(mapMouseEvent.accepted, false) + compare(mapMouseEvent.button, Qt.NoButton) + compare(mapMouseEvent.modifiers, Qt.NoModifier) + compare(mapMouseEvent.wasHeld, false) + compare(mapMouseEvent.x, 0) + compare(mapMouseEvent.y, 0) + } + + function test_basic_position_changed() { + // tests basic position changed/move when button is being pressed + clear_data(); + mousePress(map, 5, 25) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.buttons, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + // moves within the mouse area + mouseMove(map, 5, 26, 0, Qt.LeftButton) // '0' is 'delay' + wait(1) // mouseMove event goes one extra eventloop round in the test lib + compare(mouseUpperEnteredSpy.count, 1) + compare(mouseUpperPositionChangedSpy.count, 1) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, 6) // 20 offset, mouseXY is relative to the mouse area + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.NoButton) + compare(mouseUpper.lastMouseEvent.buttons, Qt.LeftButton) // buttons being pressed whilst movin' + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) // testfunction won't take required 800 ms + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 6) // remember 20 offset of the mouse area + + mouseMove(map, 6, 27, 0, Qt.LeftButton | Qt.RightButton) + wait(1) + compare(mouseUpperEnteredSpy.count, 1) // no re-entry + compare(mouseUpperPositionChangedSpy.count, 2) + compare(mouseUpper.mouseX, 6) + compare(mouseUpper.mouseY, 7) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.NoButton) + compare(mouseUpper.lastMouseEvent.buttons, Qt.LeftButton | Qt.RightButton) // buttons being pressed whilst movin' + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) // testfunction won't take required 800 ms + compare(mouseUpper.lastMouseEvent.x, 6) + compare(mouseUpper.lastMouseEvent.y, 7) // remember 20 offset of the mouse area + + // moves outside of mouse but within map + mouseMove(map, 2, 2, 0) + wait(1) + compare(mouseUpperExitedSpy.count, 1) + compare(mouseUpperPositionChangedSpy.count, 3) + compare(mouseUpper.mouseX, 2) + compare(mouseUpper.mouseY, -18) + // come back to map + mouseMove(map, 7, 28, 0) + wait(1) + compare(mouseUpperEnteredSpy.count, 2) + compare(mouseUpperExitedSpy.count, 1) + compare(mouseUpperPositionChangedSpy.count, 4) + compare(mouseUpper.mouseX, 7) + compare(mouseUpper.mouseY, 8) + + // move outside of widget area (left). make sure that other mouse areas won't get the events + mouseMove(map, -10, 10, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 5) + compare(mouseUpperExitedSpy.count, 2) + compare(mouseUpper.mouseX, -10) + compare(mouseUpper.mouseY, -10) + + // back in and then on top of the widget + mouseMove(map, 5, 25, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 6) + compare(mouseUpperExitedSpy.count, 2) + compare(mouseUpperEnteredSpy.count, 3) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, 5) + mouseMove(map, 5, -25, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 7) + compare(mouseUpperExitedSpy.count, 3) + compare(mouseUpperEnteredSpy.count, 3) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, -45) + + // back in then float on top of other mouse areas + mouseMove(map, 5, 25, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 8) + compare(mouseUpperExitedSpy.count, 3) + compare(mouseUpperEnteredSpy.count, 4) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, 5) + mouseMove(map, 5, 75, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 9) + compare(mouseUpperExitedSpy.count, 4) + compare(mouseUpperEnteredSpy.count, 4) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, 55) // remember the 20 offset of upper mouse area + mouseMove(map, 75, 75, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 10) + compare(mouseUpperExitedSpy.count, 4) + compare(mouseUpperEnteredSpy.count, 4) + compare(mouseUpper.mouseX, 75) + compare(mouseUpper.mouseY, 55) + // finally back in + mouseMove(map, 5, 25, 0) + wait(1) + compare(mouseUpperPositionChangedSpy.count, 11) + compare(mouseUpperExitedSpy.count, 4) + compare(mouseUpperEnteredSpy.count, 5) + compare(mouseUpper.mouseX, 5) + compare(mouseUpper.mouseY, 5) + + // check that these fellas didn't get any stupid ideas + compare(mouseLowerEnteredSpy.count, 0) + compare(mouseLowerPositionChangedSpy.count, 0) + compare(mouseOverlapperEnteredSpy.count, 0) + compare(mouseOverlapperPositionChangedSpy.count, 0) + // release mouse + mouseRelease(map, 5, 25) + // TODO enable these! + compare(mouseUpperEnteredSpy.count, 5) + compare(mouseUpperExitedSpy.count, 5) // release triggers one more exited() + } + + function test_basic_press_release() { + clear_data() + // send to emptiness + mousePress(map, 5, 5) + compare(mouseUpperPressedSpy.count, 0) + compare(mouseLowerPressedSpy.count, 0) + compare(mouseOverlapperPressedSpy.count, 0) + mouseRelease(map, 5, 5) + compare(mouseUpperReleasedSpy.count, 0) + compare(mouseLowerReleasedSpy.count, 0) + compare(mouseOverlapperReleasedSpy.count, 0) + // send to upper mouse area + mousePress(map, 5, 25) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 0) + compare(mouseOverlapperPressedSpy.count, 0) + + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 5) // remember 20 offset of the mouse area + mousePress(map, 5, 26) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 0) + compare(mouseOverlapperPressedSpy.count, 0) + + mouseRelease(map, 5, 26) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseUpperReleasedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 0) + compare(mouseLowerReleasedSpy.count, 0) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 6) // remember 20 offset of the mouse area + + mousePress(map, 5, 75) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 1) + compare(mouseOverlapperPressedSpy.count, 0) + compare(mouseLower.lastMouseEvent.accepted, true) + compare(mouseLower.lastMouseEvent.button, Qt.LeftButton) + compare(mouseLower.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseLower.lastMouseEvent.wasHeld, false) + compare(mouseLower.lastMouseEvent.x, 5) + compare(mouseLower.lastMouseEvent.y, 25) // remember 50 offset of the mouse area + + mouseRelease(map, 5, 75) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseUpperReleasedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 1) + compare(mouseLowerReleasedSpy.count, 1) + mousePress(map, 55, 75) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 1) + compare(mouseOverlapperPressedSpy.count, 1) + compare(mouseOverlapperReleasedSpy.count, 0) + mouseRelease(map, 55, 25) + compare(mouseUpperPressedSpy.count, 1) + compare(mouseUpperReleasedSpy.count, 1) + compare(mouseLowerPressedSpy.count, 1) + compare(mouseLowerReleasedSpy.count, 1) + compare(mouseOverlapperReleasedSpy.count, 1) + } + + function test_basic_click() { + clear_data(); + + mouseClick(map, 5, 5, Qt.RightButton, Qt.AltModifier) + compare(mouseUpperClickedSpy.count, 0) + compare(mouseLowerClickedSpy.count, 0) + compare(mouseOverlapperClickedSpy.count, 0) + mouseUpper.acceptedButtons = Qt.LeftButton | Qt.RightButton + mouseClick(map, 5, 25, Qt.RightButton, Qt.AltModifier) + compare(mouseUpperClickedSpy.count, 1) + compare(mouseLowerClickedSpy.count, 0) + compare(mouseOverlapperClickedSpy.count, 0) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.RightButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.AltModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 5) // remember 20 offset of the mouse area + // check we get valid geocoordinates (would be NaN if something was wrong) + verify(mouseUpper.lastMouseEvent.coordinate.longitude > -180 && mouseUpper.lastMouseEvent.coordinate.longitude < 180) + verify(mouseUpper.lastMouseEvent.coordinate.longitude > -90 && mouseUpper.lastMouseEvent.coordinate.latitude < 90) + + // mouse click with unaccepted buttons should not cause click + mouseUpper.acceptedButtons = Qt.LeftButton + mouseClick(map, 5, 25, Qt.RightButton, Qt.AltModifier) + compare(mouseUpperClickedSpy.count, 1) + compare(mouseLowerClickedSpy.count, 0) + compare(mouseOverlapperClickedSpy.count, 0) + + mouseClick(map, 5, 25) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 0) + compare(mouseOverlapperClickedSpy.count, 0) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + mouseClick(map, 5, 55) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 1) + compare(mouseOverlapperClickedSpy.count, 0) + mouseClick(map, 5, 55) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 2) + compare(mouseOverlapperClickedSpy.count, 0) + // declaration order counts on overlap case; overlapping area + // declared later will get the events + mouseClick(map, 55, 25) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 2) + compare(mouseOverlapperClickedSpy.count, 1) + mouseClick(map, 55, 75) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 2) + compare(mouseOverlapperClickedSpy.count, 2) + real_click(map, 55, 25) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 2) + compare(mouseOverlapperClickedSpy.count, 3) + real_click(map, 55, 75) + compare(mouseUpperClickedSpy.count, 2) + compare(mouseLowerClickedSpy.count, 2) + compare(mouseOverlapperClickedSpy.count, 4) + } + + function test_basic_double_click() { + clear_data(); + real_double_click(map, 5, 5) + + compare(mouseUpperDoubleClickedSpy.count, 0) + compare(mouseLowerDoubleClickedSpy.count, 0) + compare(mouseOverlapperDoubleClickedSpy.count, 0) + real_double_click(map, 5, 25) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, false) + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 5) // remember 20 offset of the mouse area + + compare(mouseUpperDoubleClickedSpy.count, 1) + compare(mouseLowerDoubleClickedSpy.count, 0) + compare(mouseOverlapperDoubleClickedSpy.count, 0) + real_double_click(map, 5, 25) + compare(mouseUpperDoubleClickedSpy.count, 2) + compare(mouseLowerDoubleClickedSpy.count, 0) + compare(mouseOverlapperDoubleClickedSpy.count, 0) + real_double_click(map, 5, 55) + compare(mouseUpperDoubleClickedSpy.count, 2) + compare(mouseLowerDoubleClickedSpy.count, 1) + compare(mouseOverlapperDoubleClickedSpy.count, 0) + real_double_click(map, 5, 55) + compare(mouseUpperDoubleClickedSpy.count, 2) + compare(mouseLowerDoubleClickedSpy.count, 2) + compare(mouseOverlapperDoubleClickedSpy.count, 0) + // declaration order counts on overlap case; overlapping area declared later will get the events + real_double_click(map, 55, 25) + compare(mouseUpperDoubleClickedSpy.count, 2) + compare(mouseLowerDoubleClickedSpy.count, 2) + compare(mouseOverlapperDoubleClickedSpy.count, 1) + compare(mouseOverlapperPressedSpy.count, 1) + compare(mouseOverlapperReleasedSpy.count, 2) + real_double_click(map, 55, 75) + compare(mouseUpperDoubleClickedSpy.count, 2) + compare(mouseLowerDoubleClickedSpy.count, 2) + compare(mouseOverlapperDoubleClickedSpy.count, 2) + compare(mouseOverlapperPressedSpy.count, 2) + compare(mouseOverlapperReleasedSpy.count, 4) + // disable overlapping area and check event is delivered to the ones beneath + mouseOverlapper.enabled = false + real_double_click(map, 55, 25) + compare(mouseUpperDoubleClickedSpy.count, 3) + compare(mouseLowerDoubleClickedSpy.count, 2) + compare(mouseOverlapperDoubleClickedSpy.count, 2) + real_double_click(map, 55, 75) + compare(mouseUpperDoubleClickedSpy.count, 3) + compare(mouseLowerDoubleClickedSpy.count, 3) + compare(mouseOverlapperDoubleClickedSpy.count, 2) + mouseOverlapper.enabled = true + real_double_click(map, 55, 25) + compare(mouseUpperDoubleClickedSpy.count, 3) + compare(mouseLowerDoubleClickedSpy.count, 3) + compare(mouseOverlapperDoubleClickedSpy.count, 3) + real_double_click(map, 55, 75) + compare(mouseUpperDoubleClickedSpy.count, 3) + compare(mouseLowerDoubleClickedSpy.count, 3) + compare(mouseOverlapperDoubleClickedSpy.count, 4) + } + + function test_zzz_basic_press_and_hold() { // _zzz_ to ensure execution last (takes time) + clear_data(); + real_press_and_hold(map, 5, 5) + compare(mouseUpperPressAndHoldSpy.count, 0) + compare(mouseLowerPressAndHoldSpy.count, 0) + compare(mouseOverlapperPressAndHoldSpy.count, 0) + + mousePress(map,5,25) + wait(850) // threshold is 800 ms + compare(mouseUpperPressAndHoldSpy.count, 1) + compare(mouseLowerPressAndHoldSpy.count, 0) + compare(mouseOverlapperPressAndHoldSpy.count, 0) + compare(mouseUpper.lastMouseEvent.accepted, true) + compare(mouseUpper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseUpper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseUpper.lastMouseEvent.wasHeld, true) // notable part + compare(mouseUpper.lastMouseEvent.x, 5) + compare(mouseUpper.lastMouseEvent.y, 5) // remember 20 offset of the mouse area + mouseRelease(map,5,25) + real_press_and_hold(map, 5, 55) + compare(mouseUpperPressAndHoldSpy.count, 1) + compare(mouseLowerPressAndHoldSpy.count, 1) + compare(mouseOverlapperPressAndHoldSpy.count, 0) + real_press_and_hold(map, 55, 75) + compare(mouseUpperPressAndHoldSpy.count, 1) + compare(mouseLowerPressAndHoldSpy.count, 1) + compare(mouseOverlapperPressAndHoldSpy.count, 1) + compare(mouseOverlapper.lastMouseEvent.accepted, true) + compare(mouseOverlapper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseOverlapper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseOverlapper.lastMouseEvent.wasHeld, true) + compare(mouseOverlapper.lastMouseEvent.x, 5) + compare(mouseOverlapper.lastMouseEvent.y, 75) + // make sure that the wasHeld is cleared + mouseClick(map, 55, 75) + compare(mouseOverlapper.lastMouseEvent.accepted, true) + compare(mouseOverlapper.lastMouseEvent.button, Qt.LeftButton) + compare(mouseOverlapper.lastMouseEvent.modifiers, Qt.NoModifier) + compare(mouseOverlapper.lastMouseEvent.wasHeld, false) + compare(mouseOverlapper.lastMouseEvent.x, 5) + compare(mouseOverlapper.lastMouseEvent.y, 75) + real_press_and_hold(map, 55, 25) + compare(mouseUpperPressAndHoldSpy.count, 1) + compare(mouseLowerPressAndHoldSpy.count, 1) + compare(mouseOverlapperPressAndHoldSpy.count, 2) } } } diff --git a/tests/declarativetestplugin/qdeclarativepinchgenerator.cpp b/tests/declarativetestplugin/qdeclarativepinchgenerator.cpp index a321f826..cb341884 100644 --- a/tests/declarativetestplugin/qdeclarativepinchgenerator.cpp +++ b/tests/declarativetestplugin/qdeclarativepinchgenerator.cpp @@ -36,7 +36,7 @@ void QDeclarativePinchGenerator::componentComplete() QSGItem::componentComplete(); } -void QDeclarativePinchGenerator::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativePinchGenerator::mousePressEvent(QMouseEvent *event) { if (state_ != Idle || !enabled_) { event->ignore(); @@ -77,17 +77,20 @@ void QDeclarativePinchGenerator::setEnabled(bool enabled) emit enabledChanged(); } -QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QGraphicsSceneMouseEvent *event) +QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMouseEvent *event) { QTouchEvent::TouchPoint touchPoint; switch (event->type()) { - case QEvent::GraphicsSceneMousePress: + //case QEvent::GraphicsSceneMousePress: + case QEvent::MouseButtonPress: touchPoint.setState(Qt::TouchPointPressed); break; - case QEvent::GraphicsSceneMouseMove: + //case QEvent::GraphicsSceneMouseMove: + case QEvent::MouseMove: touchPoint.setState(Qt::TouchPointMoved); break; - case QEvent::GraphicsSceneMouseRelease: + //case QEvent::GraphicsSceneMouseRelease: + case QEvent::MouseButtonRelease: touchPoint.setState(Qt::TouchPointReleased); break; default: @@ -97,9 +100,9 @@ QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QGrap touchPoint.setId(0); touchPoint.setPressure(0.75); touchPoint.setPos(event->pos()); - touchPoint.setLastPos(event->lastPos()); + touchPoint.setLastPos(event->pos()); touchPoint.setScenePos(target_->mapToScene(event->pos())); - touchPoint.setLastScenePos(target_->mapToScene(event->lastPos())); + touchPoint.setLastScenePos(target_->mapToScene(event->pos())); return touchPoint; } @@ -118,7 +121,7 @@ QTouchEvent::TouchPoint QDeclarativePinchGenerator::convertToPrimary(QTouchEvent } -void QDeclarativePinchGenerator::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativePinchGenerator::mouseMoveEvent(QMouseEvent *event) { if (state_ != Recording || !enabled_) { event->ignore(); @@ -137,7 +140,7 @@ void QDeclarativePinchGenerator::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } -void QDeclarativePinchGenerator::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativePinchGenerator::mouseReleaseEvent(QMouseEvent *event) { if (state_ != Recording || !enabled_) { event->ignore(); @@ -211,7 +214,7 @@ void QDeclarativePinchGenerator::setReplaySpeedFactor(qreal factor) emit replaySpeedFactorChanged(); } -void QDeclarativePinchGenerator::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +void QDeclarativePinchGenerator::mouseDoubleClickEvent(QMouseEvent *event) { Q_UNUSED(event); if (!enabled_) { @@ -388,10 +391,6 @@ Q_INVOKABLE void QDeclarativePinchGenerator::replay() replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPointDurations.at(0) / replaySpeedFactor_); replayBookmark_ = 0; setState(Replaying); - //qDebug() << "Started replay. Master total duration, first timeout, swipe counts respectively: " - // << swipes_.at(masterSwipe_)->totalDuration << swipes_.at(masterSwipe_)->touchPointDurations.at(0) - // << swipes_.at(0)->touchPoints.count() - // << swipes_.at(1)->touchPoints.count(); } Q_INVOKABLE void QDeclarativePinchGenerator::clear() diff --git a/tests/declarativetestplugin/qdeclarativepinchgenerator_p.h b/tests/declarativetestplugin/qdeclarativepinchgenerator_p.h index cb86a990..9f52ff28 100644 --- a/tests/declarativetestplugin/qdeclarativepinchgenerator_p.h +++ b/tests/declarativetestplugin/qdeclarativepinchgenerator_p.h @@ -2,7 +2,7 @@ #define QDECLARATIVEPINCHGENERATOR_H #include <QtDeclarative/QSGItem> -#include <QGraphicsSceneMouseEvent> +#include <QMouseEvent> #include <QElapsedTimer> #include <QTouchEvent> #include <QSGCanvas> @@ -93,16 +93,16 @@ public: void itemChange(ItemChange change, const ItemChangeData & data); protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); void keyPressEvent(QKeyEvent *event); void timerEvent(QTimerEvent *event); private: void setState(GeneratorState state); - QTouchEvent::TouchPoint mouseEventToTouchPoint(QGraphicsSceneMouseEvent* event); + QTouchEvent::TouchPoint mouseEventToTouchPoint(QMouseEvent* event); QTouchEvent::TouchPoint convertToPrimary(QTouchEvent::TouchPoint original); private: |