fix(InvertedMouseArea): use coding conventions

This commit is contained in:
Ronan Abhamon 2016-09-23 10:56:13 +02:00
parent aa790dc0cf
commit 7fe0ab9608

View file

@ -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()
}