From 7fe0ab960878c1bf8391c5185272ea9a75a1ad73 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 23 Sep 2016 10:56:13 +0200 Subject: [PATCH] fix(InvertedMouseArea): use coding conventions --- .../invertedMouseArea/InvertedMouseArea.qml | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/ui/components/invertedMouseArea/InvertedMouseArea.qml b/tests/ui/components/invertedMouseArea/InvertedMouseArea.qml index 211f999e0..c04eaff93 100644 --- a/tests/ui/components/invertedMouseArea/InvertedMouseArea.qml +++ b/tests/ui/components/invertedMouseArea/InvertedMouseArea.qml @@ -5,16 +5,18 @@ import QtQuick 2.0 // =================================================================== Item { - property var mouseArea + id: item + + property var _mouseArea signal pressed - function createMouseArea () { - if (mouseArea == null) { - mouseArea = builder.createObject(this) + function _createMouseArea () { + if (_mouseArea == null) { + _mouseArea = builder.createObject(this) } - mouseArea.parent = (function () { + _mouseArea.parent = (function () { // Search root. var p = item @@ -26,14 +28,14 @@ Item { })() } - function deleteMouseArea () { - if (mouseArea != null) { - mouseArea.destroy() - mouseArea = null + function _deleteMouseArea () { + if (_mouseArea != null) { + _mouseArea.destroy() + _mouseArea = null } } - function isInItem (point) { + function _isInItem (point) { return ( point.x >= item.x && point.y >= item.y && @@ -42,13 +44,21 @@ Item { ) } - id: item + // It's necessary to use a `enabled` variable. + // See: http://doc.qt.io/qt-5/qml-qtqml-component.html#completed-signal + // + // The creation order of components in a view is undefined, + // so the mouse area mustt be created only when `enabled == true`. + // + // In the first view render, `enabled` must equal false. + Component.onCompleted: enabled && _createMouseArea() + Component.onDestruction: _deleteMouseArea() onEnabledChanged: { - deleteMouseArea() + _deleteMouseArea() if (enabled) { - createMouseArea() + _createMouseArea() } } @@ -64,7 +74,7 @@ Item { // Propagate event. mouse.accepted = false - if (!isInItem( + if (!_isInItem( mapToItem(item.parent, mouse.x, mouse.y) )) { // Outside!!! @@ -73,14 +83,4 @@ Item { } } } - - // It's necessary to use a `enabled` variable. - // See: http://doc.qt.io/qt-5/qml-qtqml-component.html#completed-signal - // - // The creation order of components in a view is undefined, - // so the mouse area mustt be created only when `enabled == true`. - // - // In the first view render, `enabled` must equal false. - Component.onCompleted: enabled && createMouseArea() - Component.onDestruction: deleteMouseArea() }