Commit 7fe0ab96 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(InvertedMouseArea): use coding conventions

parent aa790dc0
...@@ -5,16 +5,18 @@ import QtQuick 2.0 ...@@ -5,16 +5,18 @@ import QtQuick 2.0
// =================================================================== // ===================================================================
Item { Item {
property var mouseArea id: item
property var _mouseArea
signal pressed signal pressed
function createMouseArea () { function _createMouseArea () {
if (mouseArea == null) { if (_mouseArea == null) {
mouseArea = builder.createObject(this) _mouseArea = builder.createObject(this)
} }
mouseArea.parent = (function () { _mouseArea.parent = (function () {
// Search root. // Search root.
var p = item var p = item
...@@ -26,14 +28,14 @@ Item { ...@@ -26,14 +28,14 @@ Item {
})() })()
} }
function deleteMouseArea () { function _deleteMouseArea () {
if (mouseArea != null) { if (_mouseArea != null) {
mouseArea.destroy() _mouseArea.destroy()
mouseArea = null _mouseArea = null
} }
} }
function isInItem (point) { function _isInItem (point) {
return ( return (
point.x >= item.x && point.x >= item.x &&
point.y >= item.y && point.y >= item.y &&
...@@ -42,13 +44,21 @@ Item { ...@@ -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: { onEnabledChanged: {
deleteMouseArea() _deleteMouseArea()
if (enabled) { if (enabled) {
createMouseArea() _createMouseArea()
} }
} }
...@@ -64,7 +74,7 @@ Item { ...@@ -64,7 +74,7 @@ Item {
// Propagate event. // Propagate event.
mouse.accepted = false mouse.accepted = false
if (!isInItem( if (!_isInItem(
mapToItem(item.parent, mouse.x, mouse.y) mapToItem(item.parent, mouse.x, mouse.y)
)) { )) {
// Outside!!! // Outside!!!
...@@ -73,14 +83,4 @@ Item { ...@@ -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()
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment