From 1ad3918809ea6c4ac3c1b185581f1c8e76f02aca Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 22 Feb 2010 15:10:37 +1000 Subject: Rename MouseRegion -> MouseArea --- demos/declarative/calculator/CalcButton.qml | 2 +- demos/declarative/flickr/common/MediaButton.qml | 2 +- demos/declarative/flickr/common/MediaLineEdit.qml | 2 +- demos/declarative/flickr/common/Slider.qml | 2 +- demos/declarative/flickr/common/Star.qml | 2 +- demos/declarative/flickr/flickr-desktop.qml | 2 +- demos/declarative/flickr/mobile/Button.qml | 2 +- demos/declarative/flickr/mobile/GridDelegate.qml | 2 +- demos/declarative/minehunt/Description.qml | 2 +- demos/declarative/minehunt/minehunt.qml | 4 +- demos/declarative/samegame/content/Button.qml | 2 +- demos/declarative/samegame/content/Dialog.qml | 2 +- demos/declarative/samegame/samegame.qml | 2 +- demos/declarative/snake/content/Button.qml | 2 +- demos/declarative/snake/snake.qml | 2 +- demos/declarative/twitter/content/Button.qml | 2 +- .../webbrowser/content/fieldtext/FieldText.qml | 6 +- demos/declarative/webbrowser/webbrowser.qml | 6 +- doc/src/declarative/advtutorial1.qdoc | 2 +- doc/src/declarative/animation.qdoc | 4 +- doc/src/declarative/basictypes.qdoc | 2 +- doc/src/declarative/elements.qdoc | 2 +- doc/src/declarative/example-slideswitch.qdoc | 6 +- doc/src/declarative/focus.qdoc | 2 +- doc/src/declarative/qmldebugging.qdoc | 2 +- doc/src/declarative/qmlintro.qdoc | 8 +- doc/src/declarative/qmlstates.qdoc | 2 +- doc/src/declarative/qtbinding.qdoc | 8 +- doc/src/declarative/scope.qdoc | 2 +- doc/src/declarative/tutorial2.qdoc | 4 +- doc/src/declarative/tutorial3.qdoc | 2 +- doc/src/snippets/declarative/drag.qml | 2 +- doc/src/snippets/declarative/mouseregion.qml | 4 +- examples/declarative/anchors/anchor-changes.qml | 2 +- examples/declarative/animations/easing.qml | 2 +- examples/declarative/behaviours/MyRect.qml | 2 +- examples/declarative/behaviours/SideRect.qml | 2 +- examples/declarative/behaviours/test.qml | 2 +- .../declarative/connections/content/Button.qml | 2 +- examples/declarative/dial/dial.qml | 2 +- examples/declarative/dynamic/qml/Button.qml | 2 +- examples/declarative/dynamic/qml/PaletteItem.qml | 2 +- examples/declarative/effects/effects.qml | 4 +- examples/declarative/layouts/Button.qml | 2 +- .../listview/content/ClickAutoRepeating.qml | 2 +- .../declarative/listview/content/MediaButton.qml | 2 +- examples/declarative/listview/dynamic.qml | 12 +- examples/declarative/listview/itemlist.qml | 2 +- examples/declarative/listview/recipes.qml | 2 +- examples/declarative/mouseregion/mouse.qml | 4 +- examples/declarative/parallax/qml/ParallaxView.qml | 2 +- examples/declarative/searchbox/SearchBox.qml | 4 +- .../declarative/slideswitch/content/Switch.qml | 4 +- examples/declarative/states/states.qml | 6 +- examples/declarative/states/transitions.qml | 6 +- examples/declarative/tabwidget/TabWidget.qml | 2 +- .../declarative/tic-tac-toe/content/TicTac.qml | 2 +- examples/declarative/tutorials/helloworld/Cell.qml | 2 +- .../declarative/tutorials/helloworld/tutorial3.qml | 2 +- .../tutorials/samegame/samegame1/Button.qml | 2 +- .../tutorials/samegame/samegame2/Button.qml | 2 +- .../tutorials/samegame/samegame3/Button.qml | 2 +- .../tutorials/samegame/samegame3/Dialog.qml | 2 +- .../tutorials/samegame/samegame3/samegame.qml | 2 +- .../samegame/samegame4/content/Button.qml | 2 +- .../samegame/samegame4/content/Dialog.qml | 2 +- .../tutorials/samegame/samegame4/samegame.qml | 2 +- examples/declarative/velocity/Day.qml | 2 +- examples/declarative/webview/content/FieldText.qml | 6 +- examples/declarative/webview/evalandattach.html | 2 +- examples/declarative/webview/evalandattach.qml | 2 +- examples/declarative/workerscript/workerscript.qml | 4 +- examples/declarative/xmldata/yahoonews.qml | 2 +- examples/declarative/xmlhttprequest/test.qml | 2 +- src/declarative/QmlChanges.txt | 2 + src/declarative/graphicsitems/graphicsitems.pri | 6 +- .../graphicsitems/qmlgraphicsevents.cpp | 2 +- .../graphicsitems/qmlgraphicsflipable.cpp | 2 +- .../graphicsitems/qmlgraphicsitemsmodule.cpp | 7 +- .../graphicsitems/qmlgraphicsloader.cpp | 2 +- .../graphicsitems/qmlgraphicsmousearea.cpp | 684 +++++++++++++++++++++ .../graphicsitems/qmlgraphicsmousearea_p.h | 185 ++++++ .../graphicsitems/qmlgraphicsmousearea_p_p.h | 117 ++++ .../graphicsitems/qmlgraphicsmouseregion.cpp | 684 --------------------- .../graphicsitems/qmlgraphicsmouseregion_p.h | 185 ------ .../graphicsitems/qmlgraphicsmouseregion_p_p.h | 117 ---- src/declarative/qml/qmlscript.cpp | 2 +- src/declarative/util/qmlanimation.cpp | 8 +- src/declarative/util/qmlconnection.cpp | 6 +- src/declarative/util/qmllistmodel.cpp | 2 +- src/declarative/util/qmlpropertychanges.cpp | 4 +- tests/auto/declarative/declarative.pro | 2 +- .../declarative/qmlanimations/data/badtype4.qml | 2 +- .../declarative/qmlanimations/data/dotproperty.qml | 2 +- .../declarative/qmlanimations/data/mixedtype1.qml | 2 +- .../declarative/qmlanimations/data/mixedtype2.qml | 2 +- .../qmlanimations/data/propertiesTransition.qml | 2 +- .../qmlanimations/data/propertiesTransition2.qml | 2 +- .../qmlanimations/data/propertiesTransition3.qml | 2 +- .../qmlanimations/data/propertiesTransition4.qml | 2 +- .../qmlanimations/data/propertiesTransition5.qml | 2 +- .../qmlanimations/data/propertiesTransition6.qml | 2 +- .../auto/declarative/qmlbehaviors/data/binding.qml | 2 +- tests/auto/declarative/qmlbehaviors/data/color.qml | 2 +- .../declarative/qmlbehaviors/data/disabled.qml | 2 +- tests/auto/declarative/qmlbehaviors/data/empty.qml | 2 +- .../declarative/qmlbehaviors/data/explicit.qml | 2 +- .../qmlbehaviors/data/groupProperty.qml | 2 +- .../qmlbehaviors/data/groupProperty2.qml | 2 +- .../qmlbehaviors/data/nonSelecting2.qml | 2 +- .../qmlbehaviors/data/reassignedAnimation.qml | 2 +- .../auto/declarative/qmlbehaviors/data/simple.qml | 2 +- tests/auto/declarative/qmldebug/tst_qmldebug.cpp | 2 +- .../qmlgraphicsmousearea/data/dragproperties.qml | 28 + .../qmlgraphicsmousearea/qmlgraphicsmousearea.pro | 9 + .../tst_qmlgraphicsmousearea.cpp | 139 +++++ .../qmlgraphicsmouseregion/data/dragproperties.qml | 28 - .../qmlgraphicsmouseregion.pro | 9 - .../tst_qmlgraphicsmouseregion.cpp | 139 ----- .../qmllanguage/data/listItemDeleteSelf.qml | 2 +- .../qmlstates/data/illegalTempState.qml | 2 +- .../declarative/qmlstates/data/legalTempState.qml | 2 +- .../declarative/qmlstates/data/parentChange.qml | 2 +- .../declarative/qmlstates/data/parentChange2.qml | 2 +- .../declarative/qmlstates/data/parentChange3.qml | 2 +- .../declarative/qmlstates/data/parentChange4.qml | 2 +- .../declarative/qmlstates/data/parentChange5.qml | 2 +- .../visual/Package_Views/packageviews.qml | 4 +- .../bindinganimation/bindinganimation.qml | 6 +- .../animation/colorAnimation/colorAnimation.qml | 2 +- .../declarative/visual/animation/easing/easing.qml | 2 +- .../parallelAnimation/parallelAnimation.qml | 2 +- .../visual/animation/parentAction/parentAction.qml | 2 +- .../animation/propertyAction/propertyAction.qml | 2 +- .../visual/animation/reanchor/reanchor.qml | 4 +- .../visual/animation/scriptAction/scriptAction.qml | 2 +- .../qmlgraphicsflickable/flickable-vertical.qml | 8 +- .../visual/qmlgraphicspathview/test-pathview.qml | 2 +- .../declarative/visual/qmlmouseregion/drag.qml | 2 +- .../visual/qmlmouseregion/mouseregion.qml | 14 +- .../declarative/visual/qmlspringfollow/follow.qml | 2 +- .../visual/selftest_noimages/selftest_noimages.qml | 2 +- .../visual/webview/settings/noAutoLoadImages.qml | 2 +- .../qmltime/tests/item_creation/children.qml | 2 +- .../qmltime/tests/item_creation/data.qml | 2 +- .../qmltime/tests/item_creation/resources.qml | 2 +- .../tests/positioner_creation/no_positioner.qml | 2 +- .../tests/positioner_creation/null_positioner.qml | 2 +- .../tests/positioner_creation/positioner.qml | 2 +- tools/qmlviewer/content/Browser.qml | 4 +- 150 files changed, 1358 insertions(+), 1355 deletions(-) create mode 100644 src/declarative/graphicsitems/qmlgraphicsmousearea.cpp create mode 100644 src/declarative/graphicsitems/qmlgraphicsmousearea_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsmousearea_p_p.h delete mode 100644 src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp delete mode 100644 src/declarative/graphicsitems/qmlgraphicsmouseregion_p.h delete mode 100644 src/declarative/graphicsitems/qmlgraphicsmouseregion_p_p.h create mode 100644 tests/auto/declarative/qmlgraphicsmousearea/data/dragproperties.qml create mode 100644 tests/auto/declarative/qmlgraphicsmousearea/qmlgraphicsmousearea.pro create mode 100644 tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp delete mode 100644 tests/auto/declarative/qmlgraphicsmouseregion/data/dragproperties.qml delete mode 100644 tests/auto/declarative/qmlgraphicsmouseregion/qmlgraphicsmouseregion.pro delete mode 100644 tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp diff --git a/demos/declarative/calculator/CalcButton.qml b/demos/declarative/calculator/CalcButton.qml index 08851d0..6210e46 100644 --- a/demos/declarative/calculator/CalcButton.qml +++ b/demos/declarative/calculator/CalcButton.qml @@ -15,7 +15,7 @@ Rectangle { Text { id: label; anchors.centerIn: parent; color: palette.buttonText } - MouseRegion { + MouseArea { id: clickRegion anchors.fill: parent onClicked: { diff --git a/demos/declarative/flickr/common/MediaButton.qml b/demos/declarative/flickr/common/MediaButton.qml index c12b642..86ac948 100644 --- a/demos/declarative/flickr/common/MediaButton.qml +++ b/demos/declarative/flickr/common/MediaButton.qml @@ -16,7 +16,7 @@ Item { source: "pics/button-pressed.png" opacity: 0 } - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: buttonImage onClicked: { container.clicked(); } diff --git a/demos/declarative/flickr/common/MediaLineEdit.qml b/demos/declarative/flickr/common/MediaLineEdit.qml index b24b296..3dfd1f3 100644 --- a/demos/declarative/flickr/common/MediaLineEdit.qml +++ b/demos/declarative/flickr/common/MediaLineEdit.qml @@ -62,7 +62,7 @@ Item { anchors.right: container.right } - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: buttonImage onClicked: { container.state = container.state=="Edit" ? "" : "Edit" } diff --git a/demos/declarative/flickr/common/Slider.qml b/demos/declarative/flickr/common/Slider.qml index fa1645c..05a87e7 100644 --- a/demos/declarative/flickr/common/Slider.qml +++ b/demos/declarative/flickr/common/Slider.qml @@ -27,7 +27,7 @@ Item { GradientStop { position: 1.0; color: "gray" } } - MouseRegion { + MouseArea { anchors.fill: parent; drag.target: parent drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: slider.xMax+2 onPositionChanged: { value = (maximum - minimum) * (handle.x-2) / slider.xMax + minimum; } diff --git a/demos/declarative/flickr/common/Star.qml b/demos/declarative/flickr/common/Star.qml index 173021b..8cd47b4 100644 --- a/demos/declarative/flickr/common/Star.qml +++ b/demos/declarative/flickr/common/Star.qml @@ -17,7 +17,7 @@ Item { opacity: 0.4 scale: 0.5 } - MouseRegion { + MouseArea { anchors.fill: container onClicked: { container.clicked() } } diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml index 3848f12..1ca3cdc 100644 --- a/demos/declarative/flickr/flickr-desktop.qml +++ b/demos/declarative/flickr/flickr-desktop.qml @@ -61,7 +61,7 @@ Item { } } - MouseRegion { anchors.fill: wrapper; onClicked: { photoClicked() } } + MouseArea { anchors.fill: wrapper; onClicked: { photoClicked() } } states: [ State { diff --git a/demos/declarative/flickr/mobile/Button.qml b/demos/declarative/flickr/mobile/Button.qml index 770330c..4ba6b19 100644 --- a/demos/declarative/flickr/mobile/Button.qml +++ b/demos/declarative/flickr/mobile/Button.qml @@ -18,7 +18,7 @@ Item { source: "images/toolbutton.sci" width: container.width; height: container.height } - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: buttonImage onClicked: { container.clicked(); } diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 6c12896..0f5b69c 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -67,6 +67,6 @@ } ] } - MouseRegion { anchors.fill: wrapper; onClicked: { photoClicked() } } + MouseArea { anchors.fill: wrapper; onClicked: { photoClicked() } } } } diff --git a/demos/declarative/minehunt/Description.qml b/demos/declarative/minehunt/Description.qml index 440dd2e..cc4d3b2 100644 --- a/demos/declarative/minehunt/Description.qml +++ b/demos/declarative/minehunt/Description.qml @@ -4,7 +4,7 @@ Item { id: page height: myText.height + 20 property var text - MouseRegion { + MouseArea { anchors.fill: parent drag.target: page drag.axis: "XandYAxis" diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 18e8195..92555c2 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -101,7 +101,7 @@ Item { } } ] - MouseRegion { + MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onPressed: { @@ -188,7 +188,7 @@ Item { anchors.right: field.right anchors.rightMargin: 20 source: isPlaying ? 'pics/face-smile.png' : hasWon ? 'pics/face-smile-big.png': 'pics/face-sad.png' - MouseRegion { + MouseArea { anchors.fill: parent onPressed: { reset() } } diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml index 63cd555..6629302 100644 --- a/demos/declarative/samegame/content/Button.qml +++ b/demos/declarative/samegame/content/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml index 5bd1123..7769328 100644 --- a/demos/declarative/samegame/content/Dialog.qml +++ b/demos/declarative/samegame/content/Dialog.qml @@ -18,5 +18,5 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } } diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index f5c4fc5..50f6293 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -28,7 +28,7 @@ Rectangle { width: parent.width - (parent.width % getTileSize()); height: parent.height - (parent.height % getTileSize()); - MouseRegion { + MouseArea { id: gameMR anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); } diff --git a/demos/declarative/snake/content/Button.qml b/demos/declarative/snake/content/Button.qml index 63cd555..6629302 100644 --- a/demos/declarative/snake/content/Button.qml +++ b/demos/declarative/snake/content/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index 58827a7..3bec747 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -101,7 +101,7 @@ Rectangle { id: skull } - MouseRegion { + MouseArea { anchors.fill: parent onPressed: { if (!head || !heartbeat.running) { diff --git a/demos/declarative/twitter/content/Button.qml b/demos/declarative/twitter/content/Button.qml index 09d471c..4cba8c3 100644 --- a/demos/declarative/twitter/content/Button.qml +++ b/demos/declarative/twitter/content/Button.qml @@ -19,7 +19,7 @@ Item { source: "images/toolbutton.sci" width: container.width; height: container.height } - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: buttonImage onClicked: { container.clicked(); } diff --git a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml index b1c1938..19b6acc 100644 --- a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml @@ -93,17 +93,17 @@ Item { } } - MouseRegion { + MouseArea { anchors.fill: cancelIcon onClicked: { reset() } } - MouseRegion { + MouseArea { anchors.fill: confirmIcon onClicked: { confirm() } } - MouseRegion { + MouseArea { id: editRegion anchors.fill: textEdit onClicked: { edit() } diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 8de13d5..934593c 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -103,7 +103,7 @@ Item { } } ] - MouseRegion { + MouseArea { anchors.fill: back_e onClicked: { if (webView.back.enabled) webView.back.trigger() } } @@ -114,7 +114,7 @@ Item { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter } - MouseRegion { + MouseArea { anchors.fill: reload onClicked: { webView.reload.trigger() } } @@ -159,7 +159,7 @@ Item { } } ] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { if (webView.forward.enabled) webView.forward.trigger() } } diff --git a/doc/src/declarative/advtutorial1.qdoc b/doc/src/declarative/advtutorial1.qdoc index 90bac1b..611a65d 100644 --- a/doc/src/declarative/advtutorial1.qdoc +++ b/doc/src/declarative/advtutorial1.qdoc @@ -56,7 +56,7 @@ button and room to display the score. The one thing you may not recognize here is the \l SystemPalette item. This item provides access to the Qt system palette and is used to make the button look more like a system button (for exact native feel you would use a \l QPushButton). Since we want a fully functional button, -we use the QML elements Text and MouseRegion inside a Rectangle to assemble a +we use the QML elements Text and MouseArea inside a Rectangle to assemble a button. Below is the code which we wrote to do this: \snippet declarative/tutorials/samegame/samegame1/Button.qml 0 diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index cfc100d..6f98cc1 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -110,7 +110,7 @@ PropertyAnimation { Image { id: image source: "image.png" - MouseRegion { + MouseArea { anchors.fill: parent onPressed: animation.start() } @@ -251,7 +251,7 @@ State { \o Update x from a script \qml -MouseRegion { +MouseArea { .... onClicked: redRect.x = 24; } diff --git a/doc/src/declarative/basictypes.qdoc b/doc/src/declarative/basictypes.qdoc index 86485d0..a5c0d8c 100644 --- a/doc/src/declarative/basictypes.qdoc +++ b/doc/src/declarative/basictypes.qdoc @@ -294,7 +294,7 @@ Actions are used like this: \qml - MouseRegion { onClicked: MyItem.myaction.trigger() } + MouseArea { onClicked: MyItem.myaction.trigger() } State { name: "enabled"; when: MyItem.myaction.enabled == true } Text { text: MyItem.someaction.text } \endqml diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index e3323c2..826d483 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -126,7 +126,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \list -\o \l MouseRegion +\o \l MouseArea \o \l FocusScope \endlist diff --git a/doc/src/declarative/example-slideswitch.qdoc b/doc/src/declarative/example-slideswitch.qdoc index c731d4a..faadfea 100644 --- a/doc/src/declarative/example-slideswitch.qdoc +++ b/doc/src/declarative/example-slideswitch.qdoc @@ -84,15 +84,15 @@ the text will only be visible when the switch is on. \snippet examples/declarative/slideswitch/content/Switch.qml 4 First, we create the background image of the switch. -In order for the switch to toggle when the user clicks on the background, we add a \l{MouseRegion} as a child item of the image. -A \c MouseRegion has a \c onClicked property that is triggered when the item is clicked. For the moment we will just call a +In order for the switch to toggle when the user clicks on the background, we add a \l{MouseArea} as a child item of the image. +A \c MouseArea has a \c onClicked property that is triggered when the item is clicked. For the moment we will just call a \c toggle() function. We will see what this function does in a moment. \snippet examples/declarative/slideswitch/content/Switch.qml 5 Then, we place the image of the knob on top of the background. The interaction here is a little more complex. We want the knob to move with the finger when it is clicked. That is what the \c drag -property of the \c MouseRegion is for. We also want to toggle the switch if the knob is released between state. We handle this case +property of the \c MouseArea is for. We also want to toggle the switch if the knob is released between state. We handle this case in the \c dorelease() function that is called in the \c onReleased property. \section2 States diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index bb9e1a4..392837d 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -263,7 +263,7 @@ Rectangle { FocusScope { id: page; width: 240; height: 25 MyWidget { focus: true } - MouseRegion { anchors.fill: parent; onClicked: { page.focus = true } } + MouseArea { anchors.fill: parent; onClicked: { page.focus = true } } } \endcode \endtable diff --git a/doc/src/declarative/qmldebugging.qdoc b/doc/src/declarative/qmldebugging.qdoc index 97bc2f8..265dd0e 100644 --- a/doc/src/declarative/qmldebugging.qdoc +++ b/doc/src/declarative/qmldebugging.qdoc @@ -50,7 +50,7 @@ \qml Rectangle { width: 200; height: 200 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: console.log("clicked") } diff --git a/doc/src/declarative/qmlintro.qdoc b/doc/src/declarative/qmlintro.qdoc index 0a503d7..6cb691a 100644 --- a/doc/src/declarative/qmlintro.qdoc +++ b/doc/src/declarative/qmlintro.qdoc @@ -326,11 +326,11 @@ Item { \section2 Signal Handlers Signal handlers allow actions to be taken in reponse to an event. For instance, -the \l MouseRegion element has signal handlers to handle mouse press, release +the \l MouseArea element has signal handlers to handle mouse press, release and click: \code -MouseRegion { +MouseArea { onPressed: console.log("mouse button pressed") } \endcode @@ -338,10 +338,10 @@ MouseRegion { All signal handlers begin with \e "on". Some signal handlers include an optional parameter, for example -the MouseRegion onPressed signal handler has a \e mouse parameter: +the MouseArea onPressed signal handler has a \e mouse parameter: \code -MouseRegion { +MouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton onPressed: if (mouse.button == Qt.RightButton) console.log("Right mouse button pressed") } diff --git a/doc/src/declarative/qmlstates.qdoc b/doc/src/declarative/qmlstates.qdoc index 867c714..a916ce8 100644 --- a/doc/src/declarative/qmlstates.qdoc +++ b/doc/src/declarative/qmlstates.qdoc @@ -94,7 +94,7 @@ Item { } ] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myItem.state = 'moved' } diff --git a/doc/src/declarative/qtbinding.qdoc b/doc/src/declarative/qtbinding.qdoc index 8b9909e..0f1195c 100644 --- a/doc/src/declarative/qtbinding.qdoc +++ b/doc/src/declarative/qtbinding.qdoc @@ -212,7 +212,7 @@ Rectangle { text: "Hello Colorful World!" } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { palette.text = "blue"; @@ -255,7 +255,7 @@ the following types: \o QVariant \endlist -This example toggles the "LED Blinker" when the MouseRegion is clicked: +This example toggles the "LED Blinker" when the MouseArea is clicked: \table \row @@ -291,7 +291,7 @@ int main(int argc, char **argv) import Qt 4.6 Rectangle { - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { if (ledBlinker.isRunning()) @@ -315,7 +315,7 @@ is to have a "running" property. This leads to much nicer QML code: import Qt 4.6 Rectangle { - MouseRegion { + MouseArea { anchors.fill: parent onClicked: ledBlinker.running = !ledBlinker.running } diff --git a/doc/src/declarative/scope.qdoc b/doc/src/declarative/scope.qdoc index 470e8f6..8716c77 100644 --- a/doc/src/declarative/scope.qdoc +++ b/doc/src/declarative/scope.qdoc @@ -317,7 +317,7 @@ Rectangle { anchors.centerIn: parent text: root.text } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: buttonClicked(text) } diff --git a/doc/src/declarative/tutorial2.qdoc b/doc/src/declarative/tutorial2.qdoc index 3e92e37..ee72ae8 100644 --- a/doc/src/declarative/tutorial2.qdoc +++ b/doc/src/declarative/tutorial2.qdoc @@ -87,10 +87,10 @@ In this case the rectangle will have the same size as its parent (see \l{anchor- \snippet examples/declarative/tutorials/helloworld/Cell.qml 3 -In order to change the color of the text when clicking on a cell, we create a \l MouseRegion element with +In order to change the color of the text when clicking on a cell, we create a \l MouseArea element with the same size as its parent. -A \l MouseRegion defines a signal called \e clicked. +A \l MouseArea defines a signal called \e clicked. When this signal is triggered we want to emit our own \e clicked signal with the color as parameter. \section2 The main QML file diff --git a/doc/src/declarative/tutorial3.qdoc b/doc/src/declarative/tutorial3.qdoc index e4d7995..bcf5f74 100644 --- a/doc/src/declarative/tutorial3.qdoc +++ b/doc/src/declarative/tutorial3.qdoc @@ -58,7 +58,7 @@ Here is the QML code: \snippet examples/declarative/tutorials/helloworld/tutorial3.qml 2 First, we create a new \e down state for our text element. -This state will be activated when the \l MouseRegion is pressed, and deactivated when it is released. +This state will be activated when the \l MouseArea is pressed, and deactivated when it is released. The \e down state includes a set of property changes from our implicit \e {default state} (the items as they were initially defined in the QML). diff --git a/doc/src/snippets/declarative/drag.qml b/doc/src/snippets/declarative/drag.qml index 8735d0c..8e5b599 100644 --- a/doc/src/snippets/declarative/drag.qml +++ b/doc/src/snippets/declarative/drag.qml @@ -6,7 +6,7 @@ Rectangle { Image { id: pic; source: "qtlogo-64.png"; anchors.verticalCenter: parent.verticalCenter opacity: (600.0-pic.x) / 600; - MouseRegion { + MouseArea { anchors.fill: parent drag.target: pic drag.axis: "XAxis" diff --git a/doc/src/snippets/declarative/mouseregion.qml b/doc/src/snippets/declarative/mouseregion.qml index 67857f5..79f8f8f 100644 --- a/doc/src/snippets/declarative/mouseregion.qml +++ b/doc/src/snippets/declarative/mouseregion.qml @@ -4,13 +4,13 @@ Rectangle { width: 200; height: 100 HorizontalLayout { //! [0] Rectangle { width: 100; height: 100; color: "green" - MouseRegion { anchors.fill: parent; onClicked: { parent.color = 'red' } } + MouseArea { anchors.fill: parent; onClicked: { parent.color = 'red' } } } //! [0] //! [1] Rectangle { width: 100; height: 100; color: "green" - MouseRegion { + MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { diff --git a/examples/declarative/anchors/anchor-changes.qml b/examples/declarative/anchors/anchor-changes.qml index f6fd35d..99ca3db 100644 --- a/examples/declarative/anchors/anchor-changes.qml +++ b/examples/declarative/anchors/anchor-changes.qml @@ -25,7 +25,7 @@ Item { Text { text: "Bottom"; anchors.bottom: parent.bottom } } - MouseRegion { + MouseArea { anchors.fill: content onPressed: window.state = "FullScreen" onReleased: window.state = "" diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml index 59e9b17..9b5bcc6 100644 --- a/examples/declarative/animations/easing.qml +++ b/examples/declarative/animations/easing.qml @@ -68,7 +68,7 @@ Rectangle { border.color: "White"; border.width: 2 height: 32; width: 32; radius: 8; anchors.verticalCenter: parent.verticalCenter - MouseRegion { + MouseArea { onClicked: if (rect.state == '') rect.state = "right"; else rect.state = '' anchors.fill: parent } diff --git a/examples/declarative/behaviours/MyRect.qml b/examples/declarative/behaviours/MyRect.qml index a272e1f..caf0d83 100644 --- a/examples/declarative/behaviours/MyRect.qml +++ b/examples/declarative/behaviours/MyRect.qml @@ -6,7 +6,7 @@ Rectangle { width: 100 height: 100 id: page - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { bluerect.parent = page; bluerect.x=0 } } diff --git a/examples/declarative/behaviours/SideRect.qml b/examples/declarative/behaviours/SideRect.qml index c7c7ebf..63b7db2 100644 --- a/examples/declarative/behaviours/SideRect.qml +++ b/examples/declarative/behaviours/SideRect.qml @@ -9,7 +9,7 @@ Rectangle { width: 75; height: 50 radius: 5 border.width: 10; border.color: "white"; - MouseRegion { + MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { focusRect.x = myRect.x; focusRect.y = myRect.y; focusRect.text = myRect.text } diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml index 1869c45..fc3f4bf 100644 --- a/examples/declarative/behaviours/test.qml +++ b/examples/declarative/behaviours/test.qml @@ -5,7 +5,7 @@ Rectangle { width: 800 height: 600 id: page - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { bluerect.parent = page; console.log(mouseX); bluerect.x = mouseX; } } diff --git a/examples/declarative/connections/content/Button.qml b/examples/declarative/connections/content/Button.qml index 1d46acc..0e33c78 100644 --- a/examples/declarative/connections/content/Button.qml +++ b/examples/declarative/connections/content/Button.qml @@ -8,5 +8,5 @@ Item { signal clicked Image { id: icon } - MouseRegion { anchors.fill: icon; onClicked: button.clicked() } + MouseArea { anchors.fill: icon; onClicked: button.clicked() } } diff --git a/examples/declarative/dial/dial.qml b/examples/declarative/dial/dial.qml index c7b7659..3aed70e 100644 --- a/examples/declarative/dial/dial.qml +++ b/examples/declarative/dial/dial.qml @@ -26,7 +26,7 @@ Rectangle { GradientStop { position: 0.0; color: "#424242" } GradientStop { position: 1.0; color: "black" } } - MouseRegion { + MouseArea { anchors.fill: parent drag.target: parent; drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: container.width - 32 } diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml index cf2ffa7..757e295 100644 --- a/examples/declarative/dynamic/qml/Button.qml +++ b/examples/declarative/dynamic/qml/Button.qml @@ -19,6 +19,6 @@ Rectangle { color: if(!mr.pressed){activePalette.button;}else{activePalette.dark;} } } - MouseRegion { id:mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id:mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text; color: activePalette.buttonText } } diff --git a/examples/declarative/dynamic/qml/PaletteItem.qml b/examples/declarative/dynamic/qml/PaletteItem.qml index bb6036d..8a9a9ee 100644 --- a/examples/declarative/dynamic/qml/PaletteItem.qml +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -4,7 +4,7 @@ GenericItem { id: itemButton property string file Script { source: "itemCreation.js" } - MouseRegion { + MouseArea { anchors.fill: parent; onPressed: startDrag(mouse); onPositionChanged: moveDrag(mouse); diff --git a/examples/declarative/effects/effects.qml b/examples/declarative/effects/effects.qml index 51658ff..0674433 100644 --- a/examples/declarative/effects/effects.qml +++ b/examples/declarative/effects/effects.qml @@ -20,7 +20,7 @@ Rectangle { } } - MouseRegion { anchors.fill: parent; onClicked: blurEffect.running = !blurEffect.running } + MouseArea { anchors.fill: parent; onClicked: blurEffect.running = !blurEffect.running } } Text { text: "Blur"; anchors.top: blur.bottom; anchors.horizontalCenter: blur.horizontalCenter } @@ -36,7 +36,7 @@ Rectangle { offset.y: NumberAnimation { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; repeat: true; } } - MouseRegion { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } + MouseArea { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } } Image { diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml index 44d0c7b..0bdb9fc 100644 --- a/examples/declarative/layouts/Button.qml +++ b/examples/declarative/layouts/Button.qml @@ -7,7 +7,7 @@ Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.wid Image { id: pix; x: 5; y:5; source: parent.icon} Text { id: textelement; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;} - MouseRegion{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} + MouseArea{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} states: State{ name:"pressed"; when:mr.pressed diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml index be37b50..0850f4e 100644 --- a/examples/declarative/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -23,7 +23,7 @@ Item { PauseAnimation { duration: repeatperiod } } } - MouseRegion { + MouseArea { anchors.fill: parent onPressed: autoRepeat.start() onReleased: { autoRepeat.stop(); parent.isPressed = false; page.released() } diff --git a/examples/declarative/listview/content/MediaButton.qml b/examples/declarative/listview/content/MediaButton.qml index 1c88844..e9065c1 100644 --- a/examples/declarative/listview/content/MediaButton.qml +++ b/examples/declarative/listview/content/MediaButton.qml @@ -14,7 +14,7 @@ Item { source: "pics/button-pressed.png" opacity: 0 } - MouseRegion { + MouseArea { id: clickRegion anchors.fill: normal onClicked: { container.clicked(); } diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index dd898f9..81550d7 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -57,10 +57,10 @@ Rectangle { Column { id: moveButtons; x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter Image { source: "content/pics/go-up.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } } Image { source: "content/pics/go-down.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } } } @@ -93,7 +93,7 @@ Rectangle { Image { id: removeButton; source: "content/pics/archive-remove.png" anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: 10 } - MouseRegion { anchors.fill:parent; onClicked: fruitModel.remove(index) } + MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } } } } @@ -131,7 +131,7 @@ Rectangle { spacing: 8 id: buttons Image { source: "content/pics/archive-insert.png" - MouseRegion { anchors.fill: parent; + MouseArea { anchors.fill: parent; onClicked: { fruitModel.append({ "name":"Pizza Margarita", @@ -142,7 +142,7 @@ Rectangle { } } Image { source: "content/pics/archive-insert.png" - MouseRegion { anchors.fill: parent; + MouseArea { anchors.fill: parent; onClicked: { fruitModel.insert(0,{ "name":"Pizza Supreme", @@ -153,7 +153,7 @@ Rectangle { } } Image { source: "content/pics/archive-remove.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.clear() } + MouseArea { anchors.fill: parent; onClicked: fruitModel.clear() } } } } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 6392153..54981b7 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -51,7 +51,7 @@ Rectangle { Rectangle { width: 5; height: 5 radius: 3 - MouseRegion { width: 20; height: 20; anchors.centerIn: parent; onClicked: view.currentIndex = index } + MouseArea { width: 20; height: 20; anchors.centerIn: parent; onClicked: view.currentIndex = index } color: view.currentIndex == index ? "blue" : "white" } } diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml index 3410f56..f848be0 100644 --- a/examples/declarative/listview/recipes.qml +++ b/examples/declarative/listview/recipes.qml @@ -32,7 +32,7 @@ Rectangle { // This mouse region covers the entire delegate. // When clicked it changes mode to 'Details'. If we are already // in Details mode, then no change will happen. - MouseRegion { + MouseArea { id: pageMouse anchors.fill: parent onClicked: wrapper.state = 'Details'; diff --git a/examples/declarative/mouseregion/mouse.qml b/examples/declarative/mouseregion/mouse.qml index d07d471..9191f8a 100644 --- a/examples/declarative/mouseregion/mouse.qml +++ b/examples/declarative/mouseregion/mouse.qml @@ -7,7 +7,7 @@ Rectangle { width: 50; height: 50 color: "red" Text { text: "Click"; anchors.centerIn: parent } - MouseRegion { + MouseArea { hoverEnabled: true acceptedButtons: Qt.LeftButton | Qt.RightButton onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } @@ -24,7 +24,7 @@ Rectangle { y: 100; width: 50; height: 50 color: "blue" Text { text: "Drag"; anchors.centerIn: parent } - MouseRegion { + MouseArea { drag.target: parent drag.axis: "XAxis" drag.minimumX: 0 diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index f10d374..811891b 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -58,7 +58,7 @@ Item { transformOrigin: "Center" } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { root.currentIndex = index } } diff --git a/examples/declarative/searchbox/SearchBox.qml b/examples/declarative/searchbox/SearchBox.qml index 7077a11..524b652 100644 --- a/examples/declarative/searchbox/SearchBox.qml +++ b/examples/declarative/searchbox/SearchBox.qml @@ -23,7 +23,7 @@ FocusScope { text: "Type something..."; color: "gray"; font.italic: true } - MouseRegion { anchors.fill: parent; onClicked: focusScope.focus = true } + MouseArea { anchors.fill: parent; onClicked: focusScope.focus = true } TextInput { id: textInput @@ -38,7 +38,7 @@ FocusScope { anchors.verticalCenter: parent.verticalCenter source: "images/edit-clear-locationbar-rtl.png"; opacity: 0 - MouseRegion { anchors.fill: parent; onClicked: { textInput.text = ''; focusScope.focus = true } } + MouseArea { anchors.fill: parent; onClicked: { textInput.text = ''; focusScope.focus = true } } } states: State { diff --git a/examples/declarative/slideswitch/content/Switch.qml b/examples/declarative/slideswitch/content/Switch.qml index c7f1c24..930f471 100644 --- a/examples/declarative/slideswitch/content/Switch.qml +++ b/examples/declarative/slideswitch/content/Switch.qml @@ -32,7 +32,7 @@ Item { //![4] Image { id: background; source: "background.svg" - MouseRegion { anchors.fill: parent; onClicked: toggle() } + MouseArea { anchors.fill: parent; onClicked: toggle() } } //![4] @@ -40,7 +40,7 @@ Item { Image { id: knob; source: "knob.svg"; x: 1; y: 2 - MouseRegion { + MouseArea { anchors.fill: parent drag.target: knob; drag.axis: "XAxis"; drag.minimumX: 1; drag.maximumX: 78 onClicked: toggle() diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index 6f6b40f..89f2421 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -10,7 +10,7 @@ Rectangle { anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = '' } + MouseArea { anchors.fill: parent; onClicked: page.state = '' } } // Another target region. Clicking in here sets the state to 'Position1' @@ -19,7 +19,7 @@ Rectangle { anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } } // Another target region. Clicking in here sets the state to 'Position2' @@ -28,7 +28,7 @@ Rectangle { anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } } // The image which will be moved when my state changes diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index ba97d9be..48d5f60 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -10,7 +10,7 @@ Rectangle { anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = '' } + MouseArea { anchors.fill: parent; onClicked: page.state = '' } } // Another target region. Clicking in here sets the state to 'Position1' @@ -19,7 +19,7 @@ Rectangle { anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } } // Another target region. Clicking in here sets the state to 'Position2' @@ -28,7 +28,7 @@ Rectangle { anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } } // The image which will be moved when my state changes diff --git a/examples/declarative/tabwidget/TabWidget.qml b/examples/declarative/tabwidget/TabWidget.qml index c56f41e..f0dfee8 100644 --- a/examples/declarative/tabwidget/TabWidget.qml +++ b/examples/declarative/tabwidget/TabWidget.qml @@ -25,7 +25,7 @@ Item { text: stack.children[index].title elide: Text.ElideRight } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: page.current = index } diff --git a/examples/declarative/tic-tac-toe/content/TicTac.qml b/examples/declarative/tic-tac-toe/content/TicTac.qml index eb80743..ccb7b78 100644 --- a/examples/declarative/tic-tac-toe/content/TicTac.qml +++ b/examples/declarative/tic-tac-toe/content/TicTac.qml @@ -13,7 +13,7 @@ Item { anchors.centerIn: parent } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.clicked() } diff --git a/examples/declarative/tutorials/helloworld/Cell.qml b/examples/declarative/tutorials/helloworld/Cell.qml index c38b40e..de4f3bb 100644 --- a/examples/declarative/tutorials/helloworld/Cell.qml +++ b/examples/declarative/tutorials/helloworld/Cell.qml @@ -23,7 +23,7 @@ Item { //![2] //![3] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: container.clicked(container.color) } diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 107b066..9eaa009 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -14,7 +14,7 @@ Rectangle { transformOrigin: Item.Center //![1] - MouseRegion { id: mouseRegion; anchors.fill: parent } + MouseArea { id: mouseRegion; anchors.fill: parent } //![1] //![2] diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 85e6777..2e31ff8 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -18,7 +18,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 96dc246..9d35832 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -18,6 +18,6 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index 8bdb428..c616397 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -27,7 +27,7 @@ Rectangle { width: parent.width - (parent.width % tileSize); height: parent.height - (parent.height % tileSize); - MouseRegion { + MouseArea { id: gameMR anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index 3371d53..ed9fd32 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -17,5 +17,5 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } } diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 19b929f..a228e60 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -27,7 +27,7 @@ Rectangle { width: parent.width - (parent.width % getTileSize()); height: parent.height - (parent.height % getTileSize()); - MouseRegion { + MouseArea { id: gameMR anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 030fa13..c39f99b 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -48,7 +48,7 @@ Rectangle { x: stickyImage.x width: stickyImage.width * stickyImage.scale height: stickyImage.height * stickyImage.scale - MouseRegion { + MouseArea { id: mouse onClicked: { myText.focus = true } anchors.fill: parent diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml index b1c1938..19b6acc 100644 --- a/examples/declarative/webview/content/FieldText.qml +++ b/examples/declarative/webview/content/FieldText.qml @@ -93,17 +93,17 @@ Item { } } - MouseRegion { + MouseArea { anchors.fill: cancelIcon onClicked: { reset() } } - MouseRegion { + MouseArea { anchors.fill: confirmIcon onClicked: { confirm() } } - MouseRegion { + MouseArea { id: editRegion anchors.fill: textEdit onClicked: { edit() } diff --git a/examples/declarative/webview/evalandattach.html b/examples/declarative/webview/evalandattach.html index c0992bb..48a1c33 100644 --- a/examples/declarative/webview/evalandattach.html +++ b/examples/declarative/webview/evalandattach.html @@ -1,7 +1,7 @@ diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml index 1b211c9..94301cd 100644 --- a/examples/declarative/webview/evalandattach.qml +++ b/examples/declarative/webview/evalandattach.qml @@ -21,7 +21,7 @@ Item { anchors.right: parent.right } - MouseRegion { + MouseArea { anchors.fill: teksti onClicked: { webView.evaluateJavaScript ("do_it()") } } diff --git a/examples/declarative/workerscript/workerscript.qml b/examples/declarative/workerscript/workerscript.qml index e36d4d4..0566f1f 100644 --- a/examples/declarative/workerscript/workerscript.qml +++ b/examples/declarative/workerscript/workerscript.qml @@ -20,7 +20,7 @@ Rectangle { anchors.leftMargin: 20 color: "red" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myWorker.sendMessage( { rectangle: "red", x: mouse.x, y: mouse.y } ); } @@ -32,7 +32,7 @@ Rectangle { anchors.rightMargin: 20 color: "blue" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myWorker.sendMessage( { rectangle: "blue", x: mouse.x, y: mouse.y } ); } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 23463c2..b80e29c 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -22,7 +22,7 @@ Rectangle { id: delegate height: wrapper.height + 10 - MouseRegion { + MouseArea { anchors.fill: wrapper onPressed: delegate.ListView.view.currentIndex = index; onClicked: if (wrapper.state == 'Details') wrapper.state = ''; else wrapper.state = 'Details'; diff --git a/examples/declarative/xmlhttprequest/test.qml b/examples/declarative/xmlhttprequest/test.qml index 18e328b..15ac54b 100644 --- a/examples/declarative/xmlhttprequest/test.qml +++ b/examples/declarative/xmlhttprequest/test.qml @@ -3,7 +3,7 @@ import Qt 4.6 Rectangle { width: 800; height: 600 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index e3aab65..a2afc1b 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -1,6 +1,8 @@ ============================================================================= The changes below are pre Qt 4.7.0 alpha +Renamed MouseRegion -> MouseArea + QmlView ------- The API of QmlView has been narrowed and its role as a convenience class diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index db9c29e..e5343c6 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -28,8 +28,8 @@ HEADERS += \ $$PWD/qmlgraphicspositioners_p_p.h \ $$PWD/qmlgraphicsloader_p.h \ $$PWD/qmlgraphicsloader_p_p.h \ - $$PWD/qmlgraphicsmouseregion_p.h \ - $$PWD/qmlgraphicsmouseregion_p_p.h \ + $$PWD/qmlgraphicsmousearea_p.h \ + $$PWD/qmlgraphicsmousearea_p_p.h \ $$PWD/qmlgraphicspath_p.h \ $$PWD/qmlgraphicspath_p_p.h \ $$PWD/qmlgraphicspathview_p.h \ @@ -70,7 +70,7 @@ SOURCES += \ $$PWD/qmlgraphicsfocusscope.cpp \ $$PWD/qmlgraphicspositioners.cpp \ $$PWD/qmlgraphicsloader.cpp \ - $$PWD/qmlgraphicsmouseregion.cpp \ + $$PWD/qmlgraphicsmousearea.cpp \ $$PWD/qmlgraphicspath.cpp \ $$PWD/qmlgraphicspathview.cpp \ $$PWD/qmlgraphicsrectangle.cpp \ diff --git a/src/declarative/graphicsitems/qmlgraphicsevents.cpp b/src/declarative/graphicsitems/qmlgraphicsevents.cpp index 1f63218..efd7b4a 100644 --- a/src/declarative/graphicsitems/qmlgraphicsevents.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsevents.cpp @@ -183,7 +183,7 @@ Item { For example, to react to a Shift key + Left mouse button click: \qml -MouseRegion { +MouseArea { onClicked: { if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) doSomething(); } } \endqml diff --git a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp index be512fc..f5abc18 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp @@ -97,7 +97,7 @@ public: NumberAnimation { properties: "angle"; duration: 2000 } } - MouseRegion { + MouseArea { // change between default and 'back' states onClicked: flipable.state = (flipable.state == 'back' ? '' : 'back') anchors.fill: parent diff --git a/src/declarative/graphicsitems/qmlgraphicsitemsmodule.cpp b/src/declarative/graphicsitems/qmlgraphicsitemsmodule.cpp index 66d62f0..9263f49 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitemsmodule.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitemsmodule.cpp @@ -51,7 +51,7 @@ #include "qmlgraphicsanimatedimage_p.h" #include "qmlgraphicsborderimage_p.h" #include "qmlgraphicspositioners_p.h" -#include "qmlgraphicsmouseregion_p.h" +#include "qmlgraphicsmousearea_p.h" #include "qmlgraphicsflickable_p.h" #include "qmlgraphicsflickable_p_p.h" #include "qmlgraphicsflipable_p.h" @@ -64,7 +64,7 @@ #include "qmlgraphicslayoutitem_p.h" #include "qmlgraphicslistview_p.h" #include "qmlgraphicsloader_p.h" -#include "qmlgraphicsmouseregion_p.h" +#include "qmlgraphicsmousearea_p.h" #include "qmlgraphicsparticles_p.h" #include "qmlgraphicspath_p.h" #include "qmlgraphicspathview_p.h" @@ -112,7 +112,8 @@ void QmlGraphicsItemModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,LayoutItem,QmlGraphicsLayoutItem); QML_REGISTER_TYPE(Qt,4,6,ListView,QmlGraphicsListView); QML_REGISTER_TYPE(Qt,4,6,Loader,QmlGraphicsLoader); - QML_REGISTER_TYPE(Qt,4,6,MouseRegion,QmlGraphicsMouseRegion); + QML_REGISTER_TYPE(Qt,4,6,MouseRegion,QmlGraphicsMouseArea); + QML_REGISTER_TYPE(Qt,4,6,MouseArea,QmlGraphicsMouseArea); QML_REGISTER_TYPE(Qt,4,6,Opacity,QGraphicsOpacityEffect); QML_REGISTER_TYPE(Qt,4,6,ParticleMotion,QmlGraphicsParticleMotion); QML_REGISTER_TYPE(Qt,4,6,ParticleMotionGravity,QmlGraphicsParticleMotionGravity); diff --git a/src/declarative/graphicsitems/qmlgraphicsloader.cpp b/src/declarative/graphicsitems/qmlgraphicsloader.cpp index 159ddc3..e4c7411 100644 --- a/src/declarative/graphicsitems/qmlgraphicsloader.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsloader.cpp @@ -124,7 +124,7 @@ void QmlGraphicsLoaderPrivate::initResize() \code Loader { id: pageLoader } Rectangle { - MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" } + MouseArea { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" } } \endcode diff --git a/src/declarative/graphicsitems/qmlgraphicsmousearea.cpp b/src/declarative/graphicsitems/qmlgraphicsmousearea.cpp new file mode 100644 index 0000000..cc07989 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsmousearea.cpp @@ -0,0 +1,684 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlgraphicsmousearea_p.h" +#include "qmlgraphicsmousearea_p_p.h" + +#include "qmlgraphicsevents_p_p.h" + +#include + +QT_BEGIN_NAMESPACE +static const int PressAndHoldDelay = 800; + +QmlGraphicsDrag::QmlGraphicsDrag(QObject *parent) +: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) +{ +} + +QmlGraphicsDrag::~QmlGraphicsDrag() +{ +} + +QmlGraphicsItem *QmlGraphicsDrag::target() const +{ + return _target; +} + +void QmlGraphicsDrag::setTarget(QmlGraphicsItem *t) +{ + if (_target == t) + return; + _target = t; + emit targetChanged(); +} + +QmlGraphicsDrag::Axis QmlGraphicsDrag::axis() const +{ + return _axis; +} + +void QmlGraphicsDrag::setAxis(QmlGraphicsDrag::Axis a) +{ + if (_axis == a) + return; + _axis = a; + emit axisChanged(); +} + +qreal QmlGraphicsDrag::xmin() const +{ + return _xmin; +} + +void QmlGraphicsDrag::setXmin(qreal m) +{ + if (_xmin == m) + return; + _xmin = m; + emit minimumXChanged(); +} + +qreal QmlGraphicsDrag::xmax() const +{ + return _xmax; +} + +void QmlGraphicsDrag::setXmax(qreal m) +{ + if (_xmax == m) + return; + _xmax = m; + emit maximumXChanged(); +} + +qreal QmlGraphicsDrag::ymin() const +{ + return _ymin; +} + +void QmlGraphicsDrag::setYmin(qreal m) +{ + if (_ymin == m) + return; + _ymin = m; + emit minimumYChanged(); +} + +qreal QmlGraphicsDrag::ymax() const +{ + return _ymax; +} + +void QmlGraphicsDrag::setYmax(qreal m) +{ + if (_ymax == m) + return; + _ymax = m; + emit maximumYChanged(); +} + +QmlGraphicsMouseAreaPrivate::~QmlGraphicsMouseAreaPrivate() +{ + delete drag; +} + + +/*! + \qmlclass MouseArea QmlGraphicsMouseArea + \brief The MouseArea item enables simple mouse handling. + \inherits Item + + A MouseArea is typically used in conjunction with a visible item, + where the MouseArea effectively 'proxies' mouse handling for that + item. For example, we can put a MouseArea in a Rectangle that changes + the Rectangle color to red when clicked: + \snippet doc/src/snippets/declarative/mouseregion.qml 0 + + Many MouseArea signals pass a \l {MouseEvent}{mouse} parameter that contains + additional information about the mouse event, such as the position, button, + and any key modifiers. + + Below we have the previous + example extended so as to give a different color when you right click. + \snippet doc/src/snippets/declarative/mouseregion.qml 1 + + For basic key handling, see the \l {Keys}{Keys attached property}. + + MouseArea is an invisible item: it is never painted. + + \sa MouseEvent +*/ + +/*! + \qmlsignal MouseArea::onEntered() + + This handler is called when the mouse enters the mouse region. + + By default the onEntered handler is only called while a button is + pressed. Setting hoverEnabled to true enables handling of + onExited when no mouse button is pressed. + + \sa hoverEnabled +*/ + +/*! + \qmlsignal MouseArea::onExited() + + This handler is called when the mouse exists the mouse region. + + By default the onExited handler is only called while a button is + pressed. Setting hoverEnabled to true enables handling of + onExited when no mouse button is pressed. + + \sa hoverEnabled +*/ + +/*! + \qmlsignal MouseArea::onPositionChanged(MouseEvent mouse) + + This handler is called when the mouse position changes. + + The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y + position, and any buttons currently pressed. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. + + By default the onPositionChanged handler is only called while a button is + pressed. Setting hoverEnabled to true enables handling of + onPositionChanged when no mouse button is pressed. +*/ + +/*! + \qmlsignal MouseArea::onClicked(mouse) + + This handler is called when there is a click. A click is defined as a press followed by a release, + both inside the MouseArea (pressing, moving outside the MouseArea, and then moving back inside and + releasing is also considered a click). + + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseArea::onPressed(mouse) + + This handler is called when there is a press. + The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y + position and which button was pressed. + + The \e accepted property of the MouseEvent parameter determines whether this MouseArea + will handle the press and all future mouse events until release. The default is to accept + the event and not allow other MouseArea beneath this one to handle the event. If \e accepted + is set to false, no further events will be sent to this MouseArea until the button is next + pressed. +*/ + +/*! + \qmlsignal MouseArea::onReleased(mouse) + + This handler is called when there is a release. + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseArea::onPressAndHold(mouse) + + This handler is called when there is a long press (currently 800ms). + The \l {MouseEvent}{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 MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseArea::onDoubleClicked(mouse) + + This handler is called when there is a double-click (a press followed by a release followed by a press). + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \internal + \class QmlGraphicsMouseArea + \brief The QmlGraphicsMouseArea class provides a simple mouse handling abstraction for use within Qml. + + \ingroup group_coreitems + + All QmlGraphicsItem derived classes can do mouse handling but the QmlGraphicsMouseArea class exposes mouse + handling data as properties and tracks flicking and dragging of the mouse. + + A QmlGraphicsMouseArea object can be instantiated in Qml using the tag \l MouseArea. + */ +QmlGraphicsMouseArea::QmlGraphicsMouseArea(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsMouseAreaPrivate), parent) +{ + Q_D(QmlGraphicsMouseArea); + d->init(); +} + +QmlGraphicsMouseArea::~QmlGraphicsMouseArea() +{ +} + +/*! + \qmlproperty real MouseArea::mouseX + \qmlproperty real MouseArea::mouseY + These properties hold the coordinates of the mouse. + + If the hoverEnabled property is false then these properties will only be valid + while a button is pressed, and will remain valid as long as the button is held + even if the mouse is moved outside the region. + + If hoverEnabled is true then these properties will be valid: + \list + \i when no button is pressed, but the mouse is within the MouseArea (containsMouse is true). + \i if a button is pressed and held, even if it has since moved out of the region. + \endlist + + The coordinates are relative to the MouseArea. +*/ +qreal QmlGraphicsMouseArea::mouseX() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->lastPos.x(); +} + +qreal QmlGraphicsMouseArea::mouseY() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->lastPos.y(); +} + +/*! + \qmlproperty bool MouseArea::enabled + This property holds whether the item accepts mouse events. +*/ +bool QmlGraphicsMouseArea::isEnabled() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->absorb; +} + +void QmlGraphicsMouseArea::setEnabled(bool a) +{ + Q_D(QmlGraphicsMouseArea); + if (a != d->absorb) { + d->absorb = a; + emit enabledChanged(); + } +} +/*! + \qmlproperty MouseButtons MouseArea::pressedButtons + This property holds the mouse buttons currently pressed. + + It contains a bitwise combination of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist + + The code below displays "right" when the right mouse buttons is pressed: + \code + Text { + text: mr.pressedButtons & Qt.RightButton ? "right" : "" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + MouseArea { + id: mr + acceptedButtons: Qt.LeftButton | Qt.RightButton + anchors.fill: parent + } + } + \endcode + + \sa acceptedButtons +*/ +Qt::MouseButtons QmlGraphicsMouseArea::pressedButtons() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->lastButtons; +} + +void QmlGraphicsMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + d->moved = false; + if (!d->absorb) + QmlGraphicsItem::mousePressEvent(event); + else { + d->longPress = false; + d->saveEvent(event); + if (d->drag) { + d->dragX = drag()->axis() & QmlGraphicsDrag::XAxis; + d->dragY = drag()->axis() & QmlGraphicsDrag::YAxis; + } + d->dragged = false; + setHovered(true); + d->start = event->pos(); + d->startScene = event->scenePos(); + // we should only start timer if pressAndHold is connected to. + if (d->isConnected("pressAndHold(QmlGraphicsMouseEvent*)")) + d->pressAndHoldTimer.start(PressAndHoldDelay, this); + setKeepMouseGrab(false); + event->setAccepted(setPressed(true)); + } +} + +void QmlGraphicsMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) { + QmlGraphicsItem::mouseMoveEvent(event); + return; + } + + d->saveEvent(event); + + // ### we should skip this if these signals aren't used + // ### can GV handle this for us? + bool contains = boundingRect().contains(d->lastPos); + if (d->hovered && !contains) + setHovered(false); + else if (!d->hovered && contains) + setHovered(true); + + if (d->drag && d->drag->target()) { + if (!d->moved) { + if (d->dragX) d->startX = drag()->target()->x(); + if (d->dragY) d->startY = drag()->target()->y(); + } + + QPointF startLocalPos; + QPointF curLocalPos; + if (drag()->target()->parent()) { + startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); + curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos()); + } else { + startLocalPos = d->startScene; + curLocalPos = event->scenePos(); + } + + const int dragThreshold = QApplication::startDragDistance(); + qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); + qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); + if ((d->dragX && !(dx < dragThreshold)) || (d->dragY && !(dy < dragThreshold))) + d->dragged = true; + if (!keepMouseGrab()) { + if ((!d->dragY && dy < dragThreshold && d->dragX && dx > dragThreshold) + || (!d->dragX && dx < dragThreshold && d->dragY && dy > dragThreshold) + || (d->dragX && d->dragY)) { + setKeepMouseGrab(true); + } + } + + if (d->dragX) { + qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX; + if (x < drag()->xmin()) + x = drag()->xmin(); + else if (x > drag()->xmax()) + x = drag()->xmax(); + drag()->target()->setX(x); + } + if (d->dragY) { + qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY; + if (y < drag()->ymin()) + y = drag()->ymin(); + else if (y > drag()->ymax()) + y = drag()->ymax(); + drag()->target()->setY(y); + } + } + d->moved = true; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit positionChanged(&me); +} + + +void QmlGraphicsMouseArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) { + QmlGraphicsItem::mouseReleaseEvent(event); + } else { + d->saveEvent(event); + setPressed(false); + // If we don't accept hover, we need to reset containsMouse. + if (!acceptHoverEvents()) + setHovered(false); + setKeepMouseGrab(false); + } +} + +void QmlGraphicsMouseArea::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) { + QmlGraphicsItem::mouseDoubleClickEvent(event); + } else { + QmlGraphicsItem::mouseDoubleClickEvent(event); + if (event->isAccepted()) { + // Only deliver the event if we have accepted the press. + d->saveEvent(event); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); + emit this->doubleClicked(&me); + } + } +} + +void QmlGraphicsMouseArea::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) + QmlGraphicsItem::hoverEnterEvent(event); + else + setHovered(true); +} + +void QmlGraphicsMouseArea::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) { + QmlGraphicsItem::hoverEnterEvent(event); + } else { + d->lastPos = event->pos(); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit positionChanged(&me); + } +} + +void QmlGraphicsMouseArea::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (!d->absorb) + QmlGraphicsItem::hoverLeaveEvent(event); + else + setHovered(false); +} + +bool QmlGraphicsMouseArea::sceneEvent(QEvent *event) +{ + bool rv = QmlGraphicsItem::sceneEvent(event); + if (event->type() == QEvent::UngrabMouse) { + Q_D(QmlGraphicsMouseArea); + if (d->pressed) { + // if our mouse grab has been removed (probably by Flickable), fix our + // state + d->pressed = false; + setKeepMouseGrab(false); + emit pressedChanged(); + //emit hoveredChanged(); + } + } + return rv; +} + +void QmlGraphicsMouseArea::timerEvent(QTimerEvent *event) +{ + Q_D(QmlGraphicsMouseArea); + if (event->timerId() == d->pressAndHoldTimer.timerId()) { + d->pressAndHoldTimer.stop(); + if (d->pressed && d->dragged == false && d->hovered == true) { + d->longPress = true; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit pressAndHold(&me); + } + } +} + +/*! + \qmlproperty bool MouseArea::hoverEnabled + This property holds whether hover events are handled. + + 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 containsMouse property and the onEntered, onExited and onPositionChanged signals. +*/ + +/*! + \qmlproperty bool MouseArea::containsMouse + This property holds whether the mouse is currently inside the mouse region. + + \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. + In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. +*/ +bool QmlGraphicsMouseArea::hovered() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->hovered; +} + +/*! + \qmlproperty bool MouseArea::pressed + This property holds whether the mouse region is currently pressed. +*/ +bool QmlGraphicsMouseArea::pressed() const +{ + Q_D(const QmlGraphicsMouseArea); + return d->pressed; +} + +void QmlGraphicsMouseArea::setHovered(bool h) +{ + Q_D(QmlGraphicsMouseArea); + if (d->hovered != h) { + d->hovered = h; + emit hoveredChanged(); + d->hovered ? emit entered() : emit exited(); + } +} + +/*! + \qmlproperty Qt::MouseButtons MouseArea::acceptedButtons + This property holds the mouse buttons that the mouse region reacts to. + + The available buttons are: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist + + To accept more than one button the flags can be combined with the + "|" (or) operator: + + \code + MouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton } + \endcode + + The default is to accept the Left button. +*/ +Qt::MouseButtons QmlGraphicsMouseArea::acceptedButtons() const +{ + return acceptedMouseButtons(); +} + +void QmlGraphicsMouseArea::setAcceptedButtons(Qt::MouseButtons buttons) +{ + if (buttons != acceptedMouseButtons()) { + setAcceptedMouseButtons(buttons); + emit acceptedButtonsChanged(); + } +} + +bool QmlGraphicsMouseArea::setPressed(bool p) +{ + Q_D(QmlGraphicsMouseArea); + bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; + + if (d->pressed != p) { + d->pressed = p; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); + if (d->pressed) { + emit positionChanged(&me); + emit pressed(&me); + } else { + emit released(&me); + if (isclick) + emit clicked(&me); + } + + emit pressedChanged(); + return me.isAccepted(); + } + return false; +} + +QmlGraphicsDrag *QmlGraphicsMouseArea::drag() +{ + Q_D(QmlGraphicsMouseArea); + if (!d->drag) + d->drag = new QmlGraphicsDrag; + return d->drag; +} + +/*! + \qmlproperty Item MouseArea::drag.target + \qmlproperty Axis MouseArea::drag.axis + \qmlproperty real MouseArea::drag.minimumX + \qmlproperty real MouseArea::drag.maximumX + \qmlproperty real MouseArea::drag.minimumY + \qmlproperty real MouseArea::drag.maximumY + + drag provides a convenient way to make an item draggable. + + \list + \i \c target specifies the item to drag. + \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) + \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. + \endlist + + The following example uses drag to reduce the opacity of an image as it moves to the right: + \snippet doc/src/snippets/declarative/drag.qml 0 +*/ + +QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsmousearea_p.h b/src/declarative/graphicsitems/qmlgraphicsmousearea_p.h new file mode 100644 index 0000000..2e2f8c9 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsmousearea_p.h @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSMOUSEAREA_H +#define QMLGRAPHICSMOUSEAREA_H + +#include "qmlgraphicsitem.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject +{ + Q_OBJECT + + Q_ENUMS(Axis) + Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged) + Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged) + Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged) + Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged) + Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged) + //### consider drag and drop + +public: + QmlGraphicsDrag(QObject *parent=0); + ~QmlGraphicsDrag(); + + QmlGraphicsItem *target() const; + void setTarget(QmlGraphicsItem *); + + enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; + Axis axis() const; + void setAxis(Axis); + + qreal xmin() const; + void setXmin(qreal); + qreal xmax() const; + void setXmax(qreal); + qreal ymin() const; + void setYmin(qreal); + qreal ymax() const; + void setYmax(qreal); + +Q_SIGNALS: + void targetChanged(); + void axisChanged(); + void minimumXChanged(); + void maximumXChanged(); + void minimumYChanged(); + void maximumYChanged(); + +private: + QmlGraphicsItem *_target; + Axis _axis; + qreal _xmin; + qreal _xmax; + qreal _ymin; + qreal _ymax; + Q_DISABLE_COPY(QmlGraphicsDrag) +}; + +class QmlGraphicsMouseEvent; +class QmlGraphicsMouseAreaPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsMouseArea : public QmlGraphicsItem +{ + 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::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) + Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) + Q_PROPERTY(QmlGraphicsDrag *drag READ drag CONSTANT) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? + +public: + QmlGraphicsMouseArea(QmlGraphicsItem *parent=0); + ~QmlGraphicsMouseArea(); + + qreal mouseX() const; + qreal mouseY() const; + + bool isEnabled() const; + void setEnabled(bool); + + bool hovered() const; + bool pressed() const; + + Qt::MouseButtons pressedButtons() const; + + Qt::MouseButtons acceptedButtons() const; + void setAcceptedButtons(Qt::MouseButtons buttons); + + QmlGraphicsDrag *drag(); + +Q_SIGNALS: + void hoveredChanged(); + void pressedChanged(); + void enabledChanged(); + void acceptedButtonsChanged(); + void positionChanged(QmlGraphicsMouseEvent *mouse); + + void pressed(QmlGraphicsMouseEvent *mouse); + void pressAndHold(QmlGraphicsMouseEvent *mouse); + void released(QmlGraphicsMouseEvent *mouse); + void clicked(QmlGraphicsMouseEvent *mouse); + void doubleClicked(QmlGraphicsMouseEvent *mouse); + void entered(); + void exited(); + +protected: + void setHovered(bool); + bool setPressed(bool); + + 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); + bool sceneEvent(QEvent *); + void timerEvent(QTimerEvent *event); + +private: + void handlePress(); + void handleRelease(); + +private: + Q_DISABLE_COPY(QmlGraphicsMouseArea) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseArea) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsDrag) +QML_DECLARE_TYPE(QmlGraphicsMouseArea) + +QT_END_HEADER + +#endif // QMLGRAPHICSMOUSEAREA_H diff --git a/src/declarative/graphicsitems/qmlgraphicsmousearea_p_p.h b/src/declarative/graphicsitems/qmlgraphicsmousearea_p_p.h new file mode 100644 index 0000000..fadb430 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsmousearea_p_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSMOUSEREGION_P_H +#define QMLGRAPHICSMOUSEREGION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlgraphicsitem_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlGraphicsMouseAreaPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsMouseArea) + +public: + QmlGraphicsMouseAreaPrivate() + : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) + { + } + + ~QmlGraphicsMouseAreaPrivate(); + + void init() + { + Q_Q(QmlGraphicsMouseArea); + q->setAcceptedMouseButtons(Qt::LeftButton); + } + + void saveEvent(QGraphicsSceneMouseEvent *event) { + lastPos = event->pos(); + lastButton = event->button(); + lastButtons = event->buttons(); + lastModifiers = event->modifiers(); + } + + bool isConnected(const char *signal) { + Q_Q(QmlGraphicsMouseArea); + int idx = QObjectPrivate::get(q)->signalIndex(signal); + return QObjectPrivate::get(q)->isSignalConnected(idx); + } + + bool absorb : 1; + bool hovered : 1; + bool pressed : 1; + bool longPress : 1; + bool moved : 1; + bool dragX : 1; + bool dragY : 1; + bool dragged : 1; + QmlGraphicsDrag *drag; + QPointF start; + QPointF startScene; + qreal startX; + qreal startY; + QPointF lastPos; + Qt::MouseButton lastButton; + Qt::MouseButtons lastButtons; + Qt::KeyboardModifiers lastModifiers; + QBasicTimer pressAndHoldTimer; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSMOUSEREGION_P_H diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp deleted file mode 100644 index 3470d37..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp +++ /dev/null @@ -1,684 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmlgraphicsmouseregion_p.h" -#include "qmlgraphicsmouseregion_p_p.h" - -#include "qmlgraphicsevents_p_p.h" - -#include - -QT_BEGIN_NAMESPACE -static const int PressAndHoldDelay = 800; - -QmlGraphicsDrag::QmlGraphicsDrag(QObject *parent) -: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) -{ -} - -QmlGraphicsDrag::~QmlGraphicsDrag() -{ -} - -QmlGraphicsItem *QmlGraphicsDrag::target() const -{ - return _target; -} - -void QmlGraphicsDrag::setTarget(QmlGraphicsItem *t) -{ - if (_target == t) - return; - _target = t; - emit targetChanged(); -} - -QmlGraphicsDrag::Axis QmlGraphicsDrag::axis() const -{ - return _axis; -} - -void QmlGraphicsDrag::setAxis(QmlGraphicsDrag::Axis a) -{ - if (_axis == a) - return; - _axis = a; - emit axisChanged(); -} - -qreal QmlGraphicsDrag::xmin() const -{ - return _xmin; -} - -void QmlGraphicsDrag::setXmin(qreal m) -{ - if (_xmin == m) - return; - _xmin = m; - emit minimumXChanged(); -} - -qreal QmlGraphicsDrag::xmax() const -{ - return _xmax; -} - -void QmlGraphicsDrag::setXmax(qreal m) -{ - if (_xmax == m) - return; - _xmax = m; - emit maximumXChanged(); -} - -qreal QmlGraphicsDrag::ymin() const -{ - return _ymin; -} - -void QmlGraphicsDrag::setYmin(qreal m) -{ - if (_ymin == m) - return; - _ymin = m; - emit minimumYChanged(); -} - -qreal QmlGraphicsDrag::ymax() const -{ - return _ymax; -} - -void QmlGraphicsDrag::setYmax(qreal m) -{ - if (_ymax == m) - return; - _ymax = m; - emit maximumYChanged(); -} - -QmlGraphicsMouseRegionPrivate::~QmlGraphicsMouseRegionPrivate() -{ - delete drag; -} - - -/*! - \qmlclass MouseRegion QmlGraphicsMouseRegion - \brief The MouseRegion item enables simple mouse handling. - \inherits Item - - A MouseRegion is typically used in conjunction with a visible item, - where the MouseRegion effectively 'proxies' mouse handling for that - item. For example, we can put a MouseRegion in a Rectangle that changes - the Rectangle color to red when clicked: - \snippet doc/src/snippets/declarative/mouseregion.qml 0 - - Many MouseRegion signals pass a \l {MouseEvent}{mouse} parameter that contains - additional information about the mouse event, such as the position, button, - and any key modifiers. - - Below we have the previous - example extended so as to give a different color when you right click. - \snippet doc/src/snippets/declarative/mouseregion.qml 1 - - For basic key handling, see the \l {Keys}{Keys attached property}. - - MouseRegion is an invisible item: it is never painted. - - \sa MouseEvent -*/ - -/*! - \qmlsignal MouseRegion::onEntered() - - This handler is called when the mouse enters the mouse region. - - By default the onEntered handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onExited when no mouse button is pressed. - - \sa hoverEnabled -*/ - -/*! - \qmlsignal MouseRegion::onExited() - - This handler is called when the mouse exists the mouse region. - - By default the onExited handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onExited when no mouse button is pressed. - - \sa hoverEnabled -*/ - -/*! - \qmlsignal MouseRegion::onPositionChanged(MouseEvent mouse) - - This handler is called when the mouse position changes. - - The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y - position, and any buttons currently pressed. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. - - By default the onPositionChanged handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onPositionChanged when no mouse button is pressed. -*/ - -/*! - \qmlsignal MouseRegion::onClicked(mouse) - - This handler is called when there is a click. A click is defined as a press followed by a release, - both inside the MouseRegion (pressing, moving outside the MouseRegion, and then moving back inside and - releasing is also considered a click). - - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onPressed(mouse) - - This handler is called when there is a press. - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y - position and which button was pressed. - - The \e accepted property of the MouseEvent parameter determines whether this MouseRegion - will handle the press and all future mouse events until release. The default is to accept - the event and not allow other MouseRegions beneath this one to handle the event. If \e accepted - is set to false, no further events will be sent to this MouseRegion until the button is next - pressed. -*/ - -/*! - \qmlsignal MouseRegion::onReleased(mouse) - - This handler is called when there is a release. - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onPressAndHold(mouse) - - This handler is called when there is a long press (currently 800ms). - The \l {MouseEvent}{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 MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onDoubleClicked(mouse) - - This handler is called when there is a double-click (a press followed by a release followed by a press). - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \internal - \class QmlGraphicsMouseRegion - \brief The QmlGraphicsMouseRegion class provides a simple mouse handling abstraction for use within Qml. - - \ingroup group_coreitems - - All QmlGraphicsItem derived classes can do mouse handling but the QmlGraphicsMouseRegion class exposes mouse - handling data as properties and tracks flicking and dragging of the mouse. - - A QmlGraphicsMouseRegion object can be instantiated in Qml using the tag \l MouseRegion. - */ -QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsMouseRegionPrivate), parent) -{ - Q_D(QmlGraphicsMouseRegion); - d->init(); -} - -QmlGraphicsMouseRegion::~QmlGraphicsMouseRegion() -{ -} - -/*! - \qmlproperty real MouseRegion::mouseX - \qmlproperty real MouseRegion::mouseY - These properties hold the coordinates of the mouse. - - If the hoverEnabled property is false then these properties will only be valid - while a button is pressed, and will remain valid as long as the button is held - even if the mouse is moved outside the region. - - If hoverEnabled is true then these properties will be valid: - \list - \i when no button is pressed, but the mouse is within the MouseRegion (containsMouse is true). - \i if a button is pressed and held, even if it has since moved out of the region. - \endlist - - The coordinates are relative to the MouseRegion. -*/ -qreal QmlGraphicsMouseRegion::mouseX() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastPos.x(); -} - -qreal QmlGraphicsMouseRegion::mouseY() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastPos.y(); -} - -/*! - \qmlproperty bool MouseRegion::enabled - This property holds whether the item accepts mouse events. -*/ -bool QmlGraphicsMouseRegion::isEnabled() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->absorb; -} - -void QmlGraphicsMouseRegion::setEnabled(bool a) -{ - Q_D(QmlGraphicsMouseRegion); - if (a != d->absorb) { - d->absorb = a; - emit enabledChanged(); - } -} -/*! - \qmlproperty MouseButtons MouseRegion::pressedButtons - This property holds the mouse buttons currently pressed. - - It contains a bitwise combination of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MidButton - \endlist - - The code below displays "right" when the right mouse buttons is pressed: - \code - Text { - text: mr.pressedButtons & Qt.RightButton ? "right" : "" - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - MouseRegion { - id: mr - acceptedButtons: Qt.LeftButton | Qt.RightButton - anchors.fill: parent - } - } - \endcode - - \sa acceptedButtons -*/ -Qt::MouseButtons QmlGraphicsMouseRegion::pressedButtons() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastButtons; -} - -void QmlGraphicsMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - d->moved = false; - if (!d->absorb) - QmlGraphicsItem::mousePressEvent(event); - else { - d->longPress = false; - d->saveEvent(event); - if (d->drag) { - d->dragX = drag()->axis() & QmlGraphicsDrag::XAxis; - d->dragY = drag()->axis() & QmlGraphicsDrag::YAxis; - } - d->dragged = false; - setHovered(true); - d->start = event->pos(); - d->startScene = event->scenePos(); - // we should only start timer if pressAndHold is connected to. - if (d->isConnected("pressAndHold(QmlGraphicsMouseEvent*)")) - d->pressAndHoldTimer.start(PressAndHoldDelay, this); - setKeepMouseGrab(false); - event->setAccepted(setPressed(true)); - } -} - -void QmlGraphicsMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseMoveEvent(event); - return; - } - - d->saveEvent(event); - - // ### we should skip this if these signals aren't used - // ### can GV handle this for us? - bool contains = boundingRect().contains(d->lastPos); - if (d->hovered && !contains) - setHovered(false); - else if (!d->hovered && contains) - setHovered(true); - - if (d->drag && d->drag->target()) { - if (!d->moved) { - if (d->dragX) d->startX = drag()->target()->x(); - if (d->dragY) d->startY = drag()->target()->y(); - } - - QPointF startLocalPos; - QPointF curLocalPos; - if (drag()->target()->parent()) { - startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); - curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos()); - } else { - startLocalPos = d->startScene; - curLocalPos = event->scenePos(); - } - - const int dragThreshold = QApplication::startDragDistance(); - qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); - qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); - if ((d->dragX && !(dx < dragThreshold)) || (d->dragY && !(dy < dragThreshold))) - d->dragged = true; - if (!keepMouseGrab()) { - if ((!d->dragY && dy < dragThreshold && d->dragX && dx > dragThreshold) - || (!d->dragX && dx < dragThreshold && d->dragY && dy > dragThreshold) - || (d->dragX && d->dragY)) { - setKeepMouseGrab(true); - } - } - - if (d->dragX) { - qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX; - if (x < drag()->xmin()) - x = drag()->xmin(); - else if (x > drag()->xmax()) - x = drag()->xmax(); - drag()->target()->setX(x); - } - if (d->dragY) { - qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY; - if (y < drag()->ymin()) - y = drag()->ymin(); - else if (y > drag()->ymax()) - y = drag()->ymax(); - drag()->target()->setY(y); - } - } - d->moved = true; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit positionChanged(&me); -} - - -void QmlGraphicsMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseReleaseEvent(event); - } else { - d->saveEvent(event); - setPressed(false); - // If we don't accept hover, we need to reset containsMouse. - if (!acceptHoverEvents()) - setHovered(false); - setKeepMouseGrab(false); - } -} - -void QmlGraphicsMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseDoubleClickEvent(event); - } else { - QmlGraphicsItem::mouseDoubleClickEvent(event); - if (event->isAccepted()) { - // Only deliver the event if we have accepted the press. - d->saveEvent(event); - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); - emit this->doubleClicked(&me); - } - } -} - -void QmlGraphicsMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) - QmlGraphicsItem::hoverEnterEvent(event); - else - setHovered(true); -} - -void QmlGraphicsMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::hoverEnterEvent(event); - } else { - d->lastPos = event->pos(); - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit positionChanged(&me); - } -} - -void QmlGraphicsMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) - QmlGraphicsItem::hoverLeaveEvent(event); - else - setHovered(false); -} - -bool QmlGraphicsMouseRegion::sceneEvent(QEvent *event) -{ - bool rv = QmlGraphicsItem::sceneEvent(event); - if (event->type() == QEvent::UngrabMouse) { - Q_D(QmlGraphicsMouseRegion); - if (d->pressed) { - // if our mouse grab has been removed (probably by Flickable), fix our - // state - d->pressed = false; - setKeepMouseGrab(false); - emit pressedChanged(); - //emit hoveredChanged(); - } - } - return rv; -} - -void QmlGraphicsMouseRegion::timerEvent(QTimerEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (event->timerId() == d->pressAndHoldTimer.timerId()) { - d->pressAndHoldTimer.stop(); - if (d->pressed && d->dragged == false && d->hovered == true) { - d->longPress = true; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit pressAndHold(&me); - } - } -} - -/*! - \qmlproperty bool MouseRegion::hoverEnabled - This property holds whether hover events are handled. - - 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 containsMouse property and the onEntered, onExited and onPositionChanged signals. -*/ - -/*! - \qmlproperty bool MouseRegion::containsMouse - This property holds whether the mouse is currently inside the mouse region. - - \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. - In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. -*/ -bool QmlGraphicsMouseRegion::hovered() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->hovered; -} - -/*! - \qmlproperty bool MouseRegion::pressed - This property holds whether the mouse region is currently pressed. -*/ -bool QmlGraphicsMouseRegion::pressed() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->pressed; -} - -void QmlGraphicsMouseRegion::setHovered(bool h) -{ - Q_D(QmlGraphicsMouseRegion); - if (d->hovered != h) { - d->hovered = h; - emit hoveredChanged(); - d->hovered ? emit entered() : emit exited(); - } -} - -/*! - \qmlproperty Qt::MouseButtons MouseRegion::acceptedButtons - This property holds the mouse buttons that the mouse region reacts to. - - The available buttons are: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MidButton - \endlist - - To accept more than one button the flags can be combined with the - "|" (or) operator: - - \code - MouseRegion { acceptedButtons: Qt.LeftButton | Qt.RightButton } - \endcode - - The default is to accept the Left button. -*/ -Qt::MouseButtons QmlGraphicsMouseRegion::acceptedButtons() const -{ - return acceptedMouseButtons(); -} - -void QmlGraphicsMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) -{ - if (buttons != acceptedMouseButtons()) { - setAcceptedMouseButtons(buttons); - emit acceptedButtonsChanged(); - } -} - -bool QmlGraphicsMouseRegion::setPressed(bool p) -{ - Q_D(QmlGraphicsMouseRegion); - bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; - - if (d->pressed != p) { - d->pressed = p; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); - if (d->pressed) { - emit positionChanged(&me); - emit pressed(&me); - } else { - emit released(&me); - if (isclick) - emit clicked(&me); - } - - emit pressedChanged(); - return me.isAccepted(); - } - return false; -} - -QmlGraphicsDrag *QmlGraphicsMouseRegion::drag() -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->drag) - d->drag = new QmlGraphicsDrag; - return d->drag; -} - -/*! - \qmlproperty Item MouseRegion::drag.target - \qmlproperty Axis MouseRegion::drag.axis - \qmlproperty real MouseRegion::drag.minimumX - \qmlproperty real MouseRegion::drag.maximumX - \qmlproperty real MouseRegion::drag.minimumY - \qmlproperty real MouseRegion::drag.maximumY - - drag provides a convenient way to make an item draggable. - - \list - \i \c target specifies the item to drag. - \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) - \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. - \endlist - - The following example uses drag to reduce the opacity of an image as it moves to the right: - \snippet doc/src/snippets/declarative/drag.qml 0 -*/ - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion_p.h b/src/declarative/graphicsitems/qmlgraphicsmouseregion_p.h deleted file mode 100644 index cccf90c..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion_p.h +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSMOUSEREGION_H -#define QMLGRAPHICSMOUSEREGION_H - -#include "qmlgraphicsitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject -{ - Q_OBJECT - - Q_ENUMS(Axis) - Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged) - Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged) - Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged) - Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged) - Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged) - //### consider drag and drop - -public: - QmlGraphicsDrag(QObject *parent=0); - ~QmlGraphicsDrag(); - - QmlGraphicsItem *target() const; - void setTarget(QmlGraphicsItem *); - - enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; - Axis axis() const; - void setAxis(Axis); - - qreal xmin() const; - void setXmin(qreal); - qreal xmax() const; - void setXmax(qreal); - qreal ymin() const; - void setYmin(qreal); - qreal ymax() const; - void setYmax(qreal); - -Q_SIGNALS: - void targetChanged(); - void axisChanged(); - void minimumXChanged(); - void maximumXChanged(); - void minimumYChanged(); - void maximumYChanged(); - -private: - QmlGraphicsItem *_target; - Axis _axis; - qreal _xmin; - qreal _xmax; - qreal _ymin; - qreal _ymax; - Q_DISABLE_COPY(QmlGraphicsDrag) -}; - -class QmlGraphicsMouseEvent; -class QmlGraphicsMouseRegionPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem -{ - 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::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) - Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) - Q_PROPERTY(QmlGraphicsDrag *drag READ drag CONSTANT) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? - -public: - QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); - ~QmlGraphicsMouseRegion(); - - qreal mouseX() const; - qreal mouseY() const; - - bool isEnabled() const; - void setEnabled(bool); - - bool hovered() const; - bool pressed() const; - - Qt::MouseButtons pressedButtons() const; - - Qt::MouseButtons acceptedButtons() const; - void setAcceptedButtons(Qt::MouseButtons buttons); - - QmlGraphicsDrag *drag(); - -Q_SIGNALS: - void hoveredChanged(); - void pressedChanged(); - void enabledChanged(); - void acceptedButtonsChanged(); - void positionChanged(QmlGraphicsMouseEvent *mouse); - - void pressed(QmlGraphicsMouseEvent *mouse); - void pressAndHold(QmlGraphicsMouseEvent *mouse); - void released(QmlGraphicsMouseEvent *mouse); - void clicked(QmlGraphicsMouseEvent *mouse); - void doubleClicked(QmlGraphicsMouseEvent *mouse); - void entered(); - void exited(); - -protected: - void setHovered(bool); - bool setPressed(bool); - - 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); - bool sceneEvent(QEvent *); - void timerEvent(QTimerEvent *event); - -private: - void handlePress(); - void handleRelease(); - -private: - Q_DISABLE_COPY(QmlGraphicsMouseRegion) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsDrag) -QML_DECLARE_TYPE(QmlGraphicsMouseRegion) - -QT_END_HEADER - -#endif // QMLGRAPHICSMOUSEREGION_H diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion_p_p.h b/src/declarative/graphicsitems/qmlgraphicsmouseregion_p_p.h deleted file mode 100644 index be27176..0000000 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion_p_p.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSMOUSEREGION_P_H -#define QMLGRAPHICSMOUSEREGION_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmlgraphicsitem_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) - -public: - QmlGraphicsMouseRegionPrivate() - : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) - { - } - - ~QmlGraphicsMouseRegionPrivate(); - - void init() - { - Q_Q(QmlGraphicsMouseRegion); - q->setAcceptedMouseButtons(Qt::LeftButton); - } - - void saveEvent(QGraphicsSceneMouseEvent *event) { - lastPos = event->pos(); - lastButton = event->button(); - lastButtons = event->buttons(); - lastModifiers = event->modifiers(); - } - - bool isConnected(const char *signal) { - Q_Q(QmlGraphicsMouseRegion); - int idx = QObjectPrivate::get(q)->signalIndex(signal); - return QObjectPrivate::get(q)->isSignalConnected(idx); - } - - bool absorb : 1; - bool hovered : 1; - bool pressed : 1; - bool longPress : 1; - bool moved : 1; - bool dragX : 1; - bool dragY : 1; - bool dragged : 1; - QmlGraphicsDrag *drag; - QPointF start; - QPointF startScene; - qreal startX; - qreal startY; - QPointF lastPos; - Qt::MouseButton lastButton; - Qt::MouseButtons lastButtons; - Qt::KeyboardModifiers lastModifiers; - QBasicTimer pressAndHoldTimer; -}; - -QT_END_NAMESPACE - -#endif // QMLGRAPHICSMOUSEREGION_P_H diff --git a/src/declarative/qml/qmlscript.cpp b/src/declarative/qml/qmlscript.cpp index c0320cd..ef142a5 100644 --- a/src/declarative/qml/qmlscript.cpp +++ b/src/declarative/qml/qmlscript.cpp @@ -58,7 +58,7 @@ console.log(otherinterestingitem.property); } } - MouseRegion { onClicked: debugMyComponent() } + MouseArea { onClicked: debugMyComponent() } \endqml \note While it is possible to use any JavaScript code within a Script element, diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 82bd33e..d7ddfce 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -176,7 +176,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj The \c running property can be set to declaratively control whether or not an animation is running. The following example will animate a rectangle - whenever the \l MouseRegion is pressed. + whenever the \l MouseArea is pressed. \code Rectangle { @@ -185,7 +185,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj running: myMouse.pressed from: 0; to: 100 } - MouseRegion { id: myMouse } + MouseArea { id: myMouse } } \endcode @@ -1794,7 +1794,7 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) Fade out \c theObject when clicked: \qml - MouseRegion { + MouseArea { anchors.fill: theObject onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 } } @@ -2214,7 +2214,7 @@ void QmlPropertyAnimation::setProperties(const QString &prop) color: Qt.rgba(0,0,1) //need to explicitly specify target and property NumberAnimation { id: theAnim; target: theRect; property: "x" to: 500 } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: theAnim.start() } diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index 9bec3bb..3d04aaf 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -72,7 +72,7 @@ public: "on" handler that reacts when a signal is received, like this: \qml - MouseRegion { + MouseArea { onClicked: { foo(x+123,y+456) } } \endqml @@ -94,7 +94,7 @@ public: like this: \qml - MouseRegion { + MouseArea { Connection { signal: "clicked(x,y)" script: { foo(x+123,y+456) } @@ -106,7 +106,7 @@ public: the sender of the signal, and the script is the default attribute: \qml - MouseRegion { + MouseArea { id: mr } ... diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index af41dfd..8fda3ae 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -188,7 +188,7 @@ static void dump(ModelNode *node, int ind); Text { text: '$'+cost; anchors.right: parent.right } // Double the price when clicked. - MouseRegion { + MouseArea { anchors.fill: parent onClicked: fruitModel.set(index, "cost", cost*2) } diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index 84f1e9a..068cb4d 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE } } - MouseRegion { anchors.fill: parent; onClicked: myText.state = 'myState' } + MouseArea { anchors.fill: parent; onClicked: myText.state = 'myState' } } \endqml @@ -91,7 +91,7 @@ QT_BEGIN_NAMESPACE \qml PropertyChanges { - target: myMouseRegion + target: myMouseArea onClicked: doSomethingDifferent() } \endqml diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b4a0d0f..2c58f7c 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -29,7 +29,7 @@ SUBDIRS += \ qmlgraphicsitem \ # Cover qmlgraphicslistview \ # Cover qmlgraphicsloader \ # Cover - qmlgraphicsmouseregion \ # Cover + qmlgraphicsmousearea \ # Cover qmlgraphicsparticles \ # Cover qmlgraphicspathview \ # Cover qmlgraphicspositioners \ # Cover diff --git a/tests/auto/declarative/qmlanimations/data/badtype4.qml b/tests/auto/declarative/qmlanimations/data/badtype4.qml index 2ffed37..e80762f 100644 --- a/tests/auto/declarative/qmlanimations/data/badtype4.qml +++ b/tests/auto/declarative/qmlanimations/data/badtype4.qml @@ -10,7 +10,7 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: if (wrapper.state == "state1") wrapper.state = ""; else wrapper.state = "state1"; } diff --git a/tests/auto/declarative/qmlanimations/data/dotproperty.qml b/tests/auto/declarative/qmlanimations/data/dotproperty.qml index 08bb5d8..9f0e699 100644 --- a/tests/auto/declarative/qmlanimations/data/dotproperty.qml +++ b/tests/auto/declarative/qmlanimations/data/dotproperty.qml @@ -9,7 +9,7 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: if (wrapper.state == "state1") wrapper.state = ""; else wrapper.state = "state1"; } diff --git a/tests/auto/declarative/qmlanimations/data/mixedtype1.qml b/tests/auto/declarative/qmlanimations/data/mixedtype1.qml index b46270c..6770366 100644 --- a/tests/auto/declarative/qmlanimations/data/mixedtype1.qml +++ b/tests/auto/declarative/qmlanimations/data/mixedtype1.qml @@ -10,7 +10,7 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: if (wrapper.state == "state1") wrapper.state = ""; else wrapper.state = "state1"; } diff --git a/tests/auto/declarative/qmlanimations/data/mixedtype2.qml b/tests/auto/declarative/qmlanimations/data/mixedtype2.qml index 15537f1..80c9473 100644 --- a/tests/auto/declarative/qmlanimations/data/mixedtype2.qml +++ b/tests/auto/declarative/qmlanimations/data/mixedtype2.qml @@ -10,7 +10,7 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: if (wrapper.state == "state1") wrapper.state = ""; else wrapper.state = "state1"; } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition.qml index 2f7fd4a..b13b94b 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { targets: theRect; properties: "x" } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition2.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition2.qml index ae59157..033c5c1 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition2.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition2.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { target: theRect; property: "y"; to: 200 } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition3.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition3.qml index 5aaaab8..d0704c9 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition3.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition3.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { targets: theRect; properties: "y" } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition4.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition4.qml index b7ebb1b..e70c95c 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition4.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition4.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { target: theRect; properties: "x" } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition5.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition5.qml index 9034fc5..b9e27da 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition5.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition5.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { targets: theRect; property: "x" } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlanimations/data/propertiesTransition6.qml b/tests/auto/declarative/qmlanimations/data/propertiesTransition6.qml index 3d8be51..7417ed1 100644 --- a/tests/auto/declarative/qmlanimations/data/propertiesTransition6.qml +++ b/tests/auto/declarative/qmlanimations/data/propertiesTransition6.qml @@ -22,7 +22,7 @@ Rectangle { NumberAnimation { targets: theItem; properties: "x" } } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "moved" } diff --git a/tests/auto/declarative/qmlbehaviors/data/binding.qml b/tests/auto/declarative/qmlbehaviors/data/binding.qml index 18d6764..201da37 100644 --- a/tests/auto/declarative/qmlbehaviors/data/binding.qml +++ b/tests/auto/declarative/qmlbehaviors/data/binding.qml @@ -11,7 +11,7 @@ Rectangle { x: basex x: Behavior { NumberAnimation { duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/color.qml b/tests/auto/declarative/qmlbehaviors/data/color.qml index aac7283..91dbbd1 100644 --- a/tests/auto/declarative/qmlbehaviors/data/color.qml +++ b/tests/auto/declarative/qmlbehaviors/data/color.qml @@ -9,7 +9,7 @@ Rectangle { color: "green" color: Behavior { ColorAnimation { duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/disabled.qml b/tests/auto/declarative/qmlbehaviors/data/disabled.qml index e7b8d51..3c7078a 100644 --- a/tests/auto/declarative/qmlbehaviors/data/disabled.qml +++ b/tests/auto/declarative/qmlbehaviors/data/disabled.qml @@ -12,7 +12,7 @@ Rectangle { NumberAnimation { duration: 200; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/empty.qml b/tests/auto/declarative/qmlbehaviors/data/empty.qml index 412e26c..95d934a 100644 --- a/tests/auto/declarative/qmlbehaviors/data/empty.qml +++ b/tests/auto/declarative/qmlbehaviors/data/empty.qml @@ -8,7 +8,7 @@ Rectangle { width: 100; height: 100; color: "green" x: Behavior {} } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/explicit.qml b/tests/auto/declarative/qmlbehaviors/data/explicit.qml index bb17076..1b2025a 100644 --- a/tests/auto/declarative/qmlbehaviors/data/explicit.qml +++ b/tests/auto/declarative/qmlbehaviors/data/explicit.qml @@ -11,7 +11,7 @@ Rectangle { NumberAnimation { target: rect; property: "x"; duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/groupProperty.qml b/tests/auto/declarative/qmlbehaviors/data/groupProperty.qml index 8a734c1..14883d4 100644 --- a/tests/auto/declarative/qmlbehaviors/data/groupProperty.qml +++ b/tests/auto/declarative/qmlbehaviors/data/groupProperty.qml @@ -8,7 +8,7 @@ Rectangle { width: 100; height: 100; color: "green" pos: Behavior { PropertyAnimation { duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/groupProperty2.qml b/tests/auto/declarative/qmlbehaviors/data/groupProperty2.qml index 602ffbb..b43ddbc 100644 --- a/tests/auto/declarative/qmlbehaviors/data/groupProperty2.qml +++ b/tests/auto/declarative/qmlbehaviors/data/groupProperty2.qml @@ -8,7 +8,7 @@ Rectangle { width: 100; height: 100; color: "green" pos.x: Behavior { NumberAnimation { duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/nonSelecting2.qml b/tests/auto/declarative/qmlbehaviors/data/nonSelecting2.qml index 59cbd1a..f267a05 100644 --- a/tests/auto/declarative/qmlbehaviors/data/nonSelecting2.qml +++ b/tests/auto/declarative/qmlbehaviors/data/nonSelecting2.qml @@ -11,7 +11,7 @@ Rectangle { NumberAnimation { targets: rect; properties: "y"; duration: 200; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/reassignedAnimation.qml b/tests/auto/declarative/qmlbehaviors/data/reassignedAnimation.qml index 693a595..ba744b1 100644 --- a/tests/auto/declarative/qmlbehaviors/data/reassignedAnimation.qml +++ b/tests/auto/declarative/qmlbehaviors/data/reassignedAnimation.qml @@ -12,7 +12,7 @@ Rectangle { NumberAnimation { duration: 1000 } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmlbehaviors/data/simple.qml b/tests/auto/declarative/qmlbehaviors/data/simple.qml index c08a1f0..ac98ed0 100644 --- a/tests/auto/declarative/qmlbehaviors/data/simple.qml +++ b/tests/auto/declarative/qmlbehaviors/data/simple.qml @@ -11,7 +11,7 @@ Rectangle { NumberAnimation { duration: 500; } } } - MouseRegion { + MouseArea { id: clicker anchors.fill: parent } diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp index 2e668ad..ba07331 100644 --- a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp @@ -825,7 +825,7 @@ int main(int argc, char *argv[]) "width: 10; height: 20; scale: blueRect.scale;" "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" "Text { color: blueRect.color; }" - "MouseRegion {" + "MouseArea {" "onEntered: { console.log('hello') }" "}" "}"; diff --git a/tests/auto/declarative/qmlgraphicsmousearea/data/dragproperties.qml b/tests/auto/declarative/qmlgraphicsmousearea/data/dragproperties.qml new file mode 100644 index 0000000..4cd78da --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsmousearea/data/dragproperties.qml @@ -0,0 +1,28 @@ +import Qt 4.6 +Rectangle { + id: whiteRect + width: 200 + height: 200 + color: "white" + Rectangle { + id: blackRect + objectName: "blackrect" + color: "black" + y: 50 + x: 50 + width: 100 + height: 100 + opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200 + Text { text: blackRect.opacity} + MouseArea { + objectName: "mouseregion" + anchors.fill: parent + drag.target: blackRect + drag.axis: Drag.XandYAxis + drag.minimumX: 0 + drag.maximumX: whiteRect.width-blackRect.width + drag.minimumY: 0 + drag.maximumY: whiteRect.height-blackRect.height + } + } + } diff --git a/tests/auto/declarative/qmlgraphicsmousearea/qmlgraphicsmousearea.pro b/tests/auto/declarative/qmlgraphicsmousearea/qmlgraphicsmousearea.pro new file mode 100644 index 0000000..f85bf0f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsmousearea/qmlgraphicsmousearea.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui network +macx:CONFIG -= app_bundle + +HEADERS += ../shared/testhttpserver.h +SOURCES += tst_qmlgraphicsmousearea.cpp ../shared/testhttpserver.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp b/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp new file mode 100644 index 0000000..869a7bd --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +class tst_QmlGraphicsMouseArea: public QObject +{ + Q_OBJECT +private slots: + void dragProperties(); +private: + QmlView *createView(const QString &filename); +}; + +void tst_QmlGraphicsMouseArea::dragProperties() +{ + QmlView *canvas = createView(SRCDIR "/data/dragproperties.qml"); + canvas->execute(); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->rootObject() != 0); + + QmlGraphicsMouseArea *mouseRegion = canvas->rootObject()->findChild("mouseregion"); + QmlGraphicsDrag *drag = mouseRegion->drag(); + QVERIFY(mouseRegion != 0); + QVERIFY(drag != 0); + + // target + QmlGraphicsItem *blackRect = canvas->rootObject()->findChild("blackrect"); + QVERIFY(blackRect != 0); + QVERIFY(blackRect == drag->target()); + QmlGraphicsItem *rootItem = qobject_cast(canvas->rootObject()); + QVERIFY(rootItem != 0); + QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); + drag->setTarget(rootItem); + QCOMPARE(targetSpy.count(),1); + drag->setTarget(rootItem); + QCOMPARE(targetSpy.count(),1); + + // axis + QCOMPARE(drag->axis(), QmlGraphicsDrag::XandYAxis); + QSignalSpy axisSpy(drag, SIGNAL(axisChanged())); + drag->setAxis(QmlGraphicsDrag::XAxis); + QCOMPARE(drag->axis(), QmlGraphicsDrag::XAxis); + QCOMPARE(axisSpy.count(),1); + drag->setAxis(QmlGraphicsDrag::XAxis); + QCOMPARE(axisSpy.count(),1); + + // minimum and maximum properties + QSignalSpy xminSpy(drag, SIGNAL(minimumXChanged())); + QSignalSpy xmaxSpy(drag, SIGNAL(maximumXChanged())); + QSignalSpy yminSpy(drag, SIGNAL(minimumYChanged())); + QSignalSpy ymaxSpy(drag, SIGNAL(maximumYChanged())); + + QCOMPARE(drag->xmin(), 0.0); + QCOMPARE(drag->xmax(), rootItem->width()-blackRect->width()); + QCOMPARE(drag->ymin(), 0.0); + QCOMPARE(drag->ymax(), rootItem->height()-blackRect->height()); + + drag->setXmin(10); + drag->setXmax(10); + drag->setYmin(10); + drag->setYmax(10); + + QCOMPARE(drag->xmin(), 10.0); + QCOMPARE(drag->xmax(), 10.0); + QCOMPARE(drag->ymin(), 10.0); + QCOMPARE(drag->ymax(), 10.0); + + QCOMPARE(xminSpy.count(),1); + QCOMPARE(xmaxSpy.count(),1); + QCOMPARE(yminSpy.count(),1); + QCOMPARE(ymaxSpy.count(),1); + + drag->setXmin(10); + drag->setXmax(10); + drag->setYmin(10); + drag->setYmax(10); + + QCOMPARE(xminSpy.count(),1); + QCOMPARE(xmaxSpy.count(),1); + QCOMPARE(yminSpy.count(),1); + QCOMPARE(ymaxSpy.count(),1); +} + +QmlView *tst_QmlGraphicsMouseArea::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + canvas->setSource(QUrl::fromLocalFile(filename)); + + return canvas; +} + +QTEST_MAIN(tst_QmlGraphicsMouseArea) + +#include "tst_qmlgraphicsmousearea.moc" diff --git a/tests/auto/declarative/qmlgraphicsmouseregion/data/dragproperties.qml b/tests/auto/declarative/qmlgraphicsmouseregion/data/dragproperties.qml deleted file mode 100644 index 5acb3e4..0000000 --- a/tests/auto/declarative/qmlgraphicsmouseregion/data/dragproperties.qml +++ /dev/null @@ -1,28 +0,0 @@ -import Qt 4.6 -Rectangle { - id: whiteRect - width: 200 - height: 200 - color: "white" - Rectangle { - id: blackRect - objectName: "blackrect" - color: "black" - y: 50 - x: 50 - width: 100 - height: 100 - opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200 - Text { text: blackRect.opacity} - MouseRegion { - objectName: "mouseregion" - anchors.fill: parent - drag.target: blackRect - drag.axis: Drag.XandYAxis - drag.minimumX: 0 - drag.maximumX: whiteRect.width-blackRect.width - drag.minimumY: 0 - drag.maximumY: whiteRect.height-blackRect.height - } - } - } \ No newline at end of file diff --git a/tests/auto/declarative/qmlgraphicsmouseregion/qmlgraphicsmouseregion.pro b/tests/auto/declarative/qmlgraphicsmouseregion/qmlgraphicsmouseregion.pro deleted file mode 100644 index 7a7c8bd..0000000 --- a/tests/auto/declarative/qmlgraphicsmouseregion/qmlgraphicsmouseregion.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui network -macx:CONFIG -= app_bundle - -HEADERS += ../shared/testhttpserver.h -SOURCES += tst_qmlgraphicsmouseregion.cpp ../shared/testhttpserver.cpp - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp b/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp deleted file mode 100644 index 82da9c8..0000000 --- a/tests/auto/declarative/qmlgraphicsmouseregion/tst_qmlgraphicsmouseregion.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -class tst_QmlGraphicsMouseRegion: public QObject -{ - Q_OBJECT -private slots: - void dragProperties(); -private: - QmlView *createView(const QString &filename); -}; - -void tst_QmlGraphicsMouseRegion::dragProperties() -{ - QmlView *canvas = createView(SRCDIR "/data/dragproperties.qml"); - canvas->execute(); - canvas->show(); - canvas->setFocus(); - QVERIFY(canvas->rootObject() != 0); - - QmlGraphicsMouseRegion *mouseRegion = canvas->rootObject()->findChild("mouseregion"); - QmlGraphicsDrag *drag = mouseRegion->drag(); - QVERIFY(mouseRegion != 0); - QVERIFY(drag != 0); - - // target - QmlGraphicsItem *blackRect = canvas->rootObject()->findChild("blackrect"); - QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); - QmlGraphicsItem *rootItem = qobject_cast(canvas->rootObject()); - QVERIFY(rootItem != 0); - QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); - drag->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); - drag->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); - - // axis - QCOMPARE(drag->axis(), QmlGraphicsDrag::XandYAxis); - QSignalSpy axisSpy(drag, SIGNAL(axisChanged())); - drag->setAxis(QmlGraphicsDrag::XAxis); - QCOMPARE(drag->axis(), QmlGraphicsDrag::XAxis); - QCOMPARE(axisSpy.count(),1); - drag->setAxis(QmlGraphicsDrag::XAxis); - QCOMPARE(axisSpy.count(),1); - - // minimum and maximum properties - QSignalSpy xminSpy(drag, SIGNAL(minimumXChanged())); - QSignalSpy xmaxSpy(drag, SIGNAL(maximumXChanged())); - QSignalSpy yminSpy(drag, SIGNAL(minimumYChanged())); - QSignalSpy ymaxSpy(drag, SIGNAL(maximumYChanged())); - - QCOMPARE(drag->xmin(), 0.0); - QCOMPARE(drag->xmax(), rootItem->width()-blackRect->width()); - QCOMPARE(drag->ymin(), 0.0); - QCOMPARE(drag->ymax(), rootItem->height()-blackRect->height()); - - drag->setXmin(10); - drag->setXmax(10); - drag->setYmin(10); - drag->setYmax(10); - - QCOMPARE(drag->xmin(), 10.0); - QCOMPARE(drag->xmax(), 10.0); - QCOMPARE(drag->ymin(), 10.0); - QCOMPARE(drag->ymax(), 10.0); - - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); - - drag->setXmin(10); - drag->setXmax(10); - drag->setYmin(10); - drag->setYmax(10); - - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); -} - -QmlView *tst_QmlGraphicsMouseRegion::createView(const QString &filename) -{ - QmlView *canvas = new QmlView(0); - canvas->setFixedSize(240,320); - - canvas->setSource(QUrl::fromLocalFile(filename)); - - return canvas; -} - -QTEST_MAIN(tst_QmlGraphicsMouseRegion) - -#include "tst_qmlgraphicsmouseregion.moc" diff --git a/tests/auto/declarative/qmllanguage/data/listItemDeleteSelf.qml b/tests/auto/declarative/qmllanguage/data/listItemDeleteSelf.qml index 779c6d4..32b5b6c 100644 --- a/tests/auto/declarative/qmllanguage/data/listItemDeleteSelf.qml +++ b/tests/auto/declarative/qmllanguage/data/listItemDeleteSelf.qml @@ -23,7 +23,7 @@ Item { width: 200; height: 50 Text { text: name } Text { text: '$'+cost; anchors.right: parent.right } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: fruitModel.remove(index) } diff --git a/tests/auto/declarative/qmlstates/data/illegalTempState.qml b/tests/auto/declarative/qmlstates/data/illegalTempState.qml index 2702be4..0dc39ae 100644 --- a/tests/auto/declarative/qmlstates/data/illegalTempState.qml +++ b/tests/auto/declarative/qmlstates/data/illegalTempState.qml @@ -14,7 +14,7 @@ Rectangle { } ] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: card.state = "placed" } diff --git a/tests/auto/declarative/qmlstates/data/legalTempState.qml b/tests/auto/declarative/qmlstates/data/legalTempState.qml index 54c97b9..9be984c 100644 --- a/tests/auto/declarative/qmlstates/data/legalTempState.qml +++ b/tests/auto/declarative/qmlstates/data/legalTempState.qml @@ -16,7 +16,7 @@ Rectangle { } ] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: card.state = "placed" } diff --git a/tests/auto/declarative/qmlstates/data/parentChange.qml b/tests/auto/declarative/qmlstates/data/parentChange.qml index 087da6b..b8c7818 100644 --- a/tests/auto/declarative/qmlstates/data/parentChange.qml +++ b/tests/auto/declarative/qmlstates/data/parentChange.qml @@ -12,7 +12,7 @@ Rectangle { color: "red" } } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/qmlstates/data/parentChange2.qml b/tests/auto/declarative/qmlstates/data/parentChange2.qml index f0b00f5..8b23591 100644 --- a/tests/auto/declarative/qmlstates/data/parentChange2.qml +++ b/tests/auto/declarative/qmlstates/data/parentChange2.qml @@ -15,7 +15,7 @@ Rectangle { color: "red" } } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/qmlstates/data/parentChange3.qml b/tests/auto/declarative/qmlstates/data/parentChange3.qml index 2aa507c..ddf9268 100644 --- a/tests/auto/declarative/qmlstates/data/parentChange3.qml +++ b/tests/auto/declarative/qmlstates/data/parentChange3.qml @@ -16,7 +16,7 @@ Rectangle { color: "red" } } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/qmlstates/data/parentChange4.qml b/tests/auto/declarative/qmlstates/data/parentChange4.qml index d00274b..34d667a 100644 --- a/tests/auto/declarative/qmlstates/data/parentChange4.qml +++ b/tests/auto/declarative/qmlstates/data/parentChange4.qml @@ -9,7 +9,7 @@ Rectangle { width: 100; height: 100 color: "red" } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/qmlstates/data/parentChange5.qml b/tests/auto/declarative/qmlstates/data/parentChange5.qml index f75e2a3..56bdd89 100644 --- a/tests/auto/declarative/qmlstates/data/parentChange5.qml +++ b/tests/auto/declarative/qmlstates/data/parentChange5.qml @@ -9,7 +9,7 @@ Rectangle { width: 100; height: 100 color: "red" } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/visual/Package_Views/packageviews.qml b/tests/auto/declarative/visual/Package_Views/packageviews.qml index dcfe7de..b577e45 100644 --- a/tests/auto/declarative/visual/Package_Views/packageviews.qml +++ b/tests/auto/declarative/visual/Package_Views/packageviews.qml @@ -29,14 +29,14 @@ Rectangle { delegate: Package { Rectangle { id: listItem; Package.name: "list"; width:root.width/2; height: 50; color: "transparent"; border.color: "white" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myState.state = myState.state == "list" ? "grid" : "list" } } Rectangle { id: gridItem; Package.name: "grid"; width:50; height: 50; color: "transparent"; border.color: "white" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myState.state = myState.state == "list" ? "grid" : "list" } diff --git a/tests/auto/declarative/visual/animation/bindinganimation/bindinganimation.qml b/tests/auto/declarative/visual/animation/bindinganimation/bindinganimation.qml index 5230ca4..70c14cf 100644 --- a/tests/auto/declarative/visual/animation/bindinganimation/bindinganimation.qml +++ b/tests/auto/declarative/visual/animation/bindinganimation/bindinganimation.qml @@ -20,7 +20,7 @@ Rectangle { x: 50 + 50 } PropertyChanges { - target: myMouseRegion + target: myMouseArea onClicked: page.state = '' } } @@ -32,8 +32,8 @@ Rectangle { } } ] - MouseRegion { - id: myMouseRegion + MouseArea { + id: myMouseArea anchors.fill: parent onClicked: { page.state= 'hello' } } diff --git a/tests/auto/declarative/visual/animation/colorAnimation/colorAnimation.qml b/tests/auto/declarative/visual/animation/colorAnimation/colorAnimation.qml index 0e98d7e..f205ae8 100644 --- a/tests/auto/declarative/visual/animation/colorAnimation/colorAnimation.qml +++ b/tests/auto/declarative/visual/animation/colorAnimation/colorAnimation.qml @@ -34,7 +34,7 @@ Rectangle { } } ] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { mainrect.state = 'second' } } diff --git a/tests/auto/declarative/visual/animation/easing/easing.qml b/tests/auto/declarative/visual/animation/easing/easing.qml index f81400b..9c814eb 100644 --- a/tests/auto/declarative/visual/animation/easing/easing.qml +++ b/tests/auto/declarative/visual/animation/easing/easing.qml @@ -186,7 +186,7 @@ Rectangle { } } } - MouseRegion { + MouseArea { id: mouse anchors.fill: layout } diff --git a/tests/auto/declarative/visual/animation/parallelAnimation/parallelAnimation.qml b/tests/auto/declarative/visual/animation/parallelAnimation/parallelAnimation.qml index 7021e05..1980b91 100644 --- a/tests/auto/declarative/visual/animation/parallelAnimation/parallelAnimation.qml +++ b/tests/auto/declarative/visual/animation/parallelAnimation/parallelAnimation.qml @@ -14,7 +14,7 @@ Rectangle { color: "red" } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.state = "state1" } diff --git a/tests/auto/declarative/visual/animation/parentAction/parentAction.qml b/tests/auto/declarative/visual/animation/parentAction/parentAction.qml index e4f4406..eb3103e 100644 --- a/tests/auto/declarative/visual/animation/parentAction/parentAction.qml +++ b/tests/auto/declarative/visual/animation/parentAction/parentAction.qml @@ -15,7 +15,7 @@ Rectangle { color: "red" } } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml b/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml index 68671e1..593f495 100644 --- a/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml +++ b/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml @@ -7,7 +7,7 @@ Rectangle { width: 100; height: 100 color: "red" } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml index 359346f..d80631f 100644 --- a/tests/auto/declarative/visual/animation/reanchor/reanchor.qml +++ b/tests/auto/declarative/visual/animation/reanchor/reanchor.qml @@ -19,7 +19,7 @@ Rectangle { Item { id: topGuideline2; y: 50 } Item { id: bottomGuideline2; y: 175 } - MouseRegion { + MouseArea { id: wholeArea anchors.fill: parent onClicked: { @@ -55,7 +55,7 @@ Rectangle { NumberAnimation { properties: "x,y,width,height" } } - MouseRegion { + MouseArea { width: 50; height: 50 anchors.right: parent.right anchors.bottom: parent.bottom diff --git a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml index f121906..30d587a 100644 --- a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml +++ b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml @@ -7,7 +7,7 @@ Rectangle { width: 100; height: 100 color: "red" } - MouseRegion { + MouseArea { id: clickable anchors.fill: parent } diff --git a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml index cc15755..6204aa9 100644 --- a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml +++ b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml @@ -25,7 +25,7 @@ Rectangle { Repeater { model: list Rectangle { width: 300; height: 200; color: mr.pressed ? "black" : dayColor - MouseRegion { + MouseArea { id: mr anchors.fill: parent } @@ -49,7 +49,7 @@ Rectangle { height: 48 y: parent.height - 50 color: "red" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: flick.interactive = flick.interactive ? false : true } @@ -62,7 +62,7 @@ Rectangle { x: 66 y: parent.height - 50 color: "green" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: flick.pressDelay = flick.pressDelay > 0 ? 0 : 500 } @@ -75,7 +75,7 @@ Rectangle { x: 130 y: parent.height - 50 color: "yellow" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: flick.overShoot = flick.overShoot > 0 ? 0 : 30 } diff --git a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml index 70018b6..0adfa02 100644 --- a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml +++ b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml @@ -22,7 +22,7 @@ Rectangle { width: 85; height: 85; color: lColor scale: wrapper.PathView.scale - MouseRegion { anchors.fill: parent } + MouseArea { anchors.fill: parent } transform: Rotation { id: itemRotation; origin.x: wrapper.width/2; origin.y: wrapper.height/2 diff --git a/tests/auto/declarative/visual/qmlmouseregion/drag.qml b/tests/auto/declarative/visual/qmlmouseregion/drag.qml index ab4c280..dbb2a24 100644 --- a/tests/auto/declarative/visual/qmlmouseregion/drag.qml +++ b/tests/auto/declarative/visual/qmlmouseregion/drag.qml @@ -8,7 +8,7 @@ Rectangle{ id: draggable width:40; height:40; color: "lightsteelblue" y:20 - MouseRegion{ + MouseArea{ anchors.fill: parent drag.target: draggable drag.axis: "XandYAxis" diff --git a/tests/auto/declarative/visual/qmlmouseregion/mouseregion.qml b/tests/auto/declarative/visual/qmlmouseregion/mouseregion.qml index ab4223d..3c722d0 100644 --- a/tests/auto/declarative/visual/qmlmouseregion/mouseregion.qml +++ b/tests/auto/declarative/visual/qmlmouseregion/mouseregion.qml @@ -9,7 +9,7 @@ Rectangle { Rectangle { width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr1 anchors.fill: parent enabled: false @@ -22,7 +22,7 @@ Rectangle { x: 100 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr2 anchors.fill: parent acceptedButtons: Qt.RightButton @@ -42,7 +42,7 @@ Rectangle { x: 200 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr3 anchors.fill: parent onPressAndHold: { @@ -56,7 +56,7 @@ Rectangle { x: 300 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr4 anchors.fill: parent onPressed: { @@ -74,7 +74,7 @@ Rectangle { y: 50 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr5 anchors.fill: parent hoverEnabled: true @@ -93,7 +93,7 @@ Rectangle { y: 50 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr6 anchors.fill: parent onClicked: { @@ -111,7 +111,7 @@ Rectangle { y: 50 width: 98; height: 48 color: "red" - MouseRegion { + MouseArea { id: mr7 anchors.fill: parent enabled: false diff --git a/tests/auto/declarative/visual/qmlspringfollow/follow.qml b/tests/auto/declarative/visual/qmlspringfollow/follow.qml index 8a713a2..a85a778 100644 --- a/tests/auto/declarative/visual/qmlspringfollow/follow.qml +++ b/tests/auto/declarative/visual/qmlspringfollow/follow.qml @@ -44,7 +44,7 @@ Rectangle { } // Follow mouse - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: parent Rectangle { diff --git a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml index 21a19bc..da7f9b6 100644 --- a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml +++ b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml @@ -2,7 +2,7 @@ import Qt 4.6 Text { property string error: "not pressed" text: (new Date()).valueOf() - MouseRegion { + MouseArea { anchors.fill: parent onPressed: error="" } diff --git a/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml b/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml index 2478932..72e672d 100644 --- a/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml +++ b/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml @@ -11,7 +11,7 @@ Grid { anchors.fill: parent settings.autoLoadImages: false url: "test-img.html" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { parent.settings.autoLoadImages=true; label.text=""; parent.reload.trigger() } } diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml index 210c515..996602c 100644 --- a/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml @@ -24,7 +24,7 @@ Item { Text { }, Text { }, Text { }, - MouseRegion { } + MouseArea { } ] } diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml index 943634f..9f79c34 100644 --- a/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml @@ -24,7 +24,7 @@ Item { Text { }, Text { }, Text { }, - MouseRegion { } + MouseArea { } ] } diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml index ce986b5..335aeb8 100644 --- a/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml +++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml @@ -24,7 +24,7 @@ Item { Text { }, Text { }, Text { }, - MouseRegion { } + MouseArea { } ] } diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml index 25e9c62..97bad47 100644 --- a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml @@ -30,7 +30,7 @@ Item { Text { } } } - MouseRegion { } + MouseArea { } } } } diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml index ee3f9d1..36dda15 100644 --- a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml @@ -27,7 +27,7 @@ Item { Text { } Text { } } - MouseRegion { } + MouseArea { } } } } diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml index 4c46ec1..396e27d 100644 --- a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml +++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml @@ -30,7 +30,7 @@ Item { Text { } } } - MouseRegion { } + MouseArea { } } } } diff --git a/tools/qmlviewer/content/Browser.qml b/tools/qmlviewer/content/Browser.qml index 446045b..35120bc 100644 --- a/tools/qmlviewer/content/Browser.qml +++ b/tools/qmlviewer/content/Browser.qml @@ -90,7 +90,7 @@ Rectangle { font.pixelSize: 32 color: (wrapper.ListView.isCurrentItem && root.keyPressed) ? palette.highlightedText : palette.windowText } - MouseRegion { + MouseArea { id: mouseRegion anchors.fill: parent onClicked: { launch() } @@ -211,7 +211,7 @@ Rectangle { color: "transparent" Image { anchors.centerIn: parent; source: "images/up.png" } - MouseRegion { id: upRegion; anchors.centerIn: parent + MouseArea { id: upRegion; anchors.centerIn: parent width: 56 height: 56 onClicked: if (folders.parentFolder != "") up() -- cgit v0.12