mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
feat(Common/InvertedMouseArea): check if already exists a MouseArea at children root
This commit is contained in:
parent
e442609e8c
commit
ba804f5d04
3 changed files with 53 additions and 3 deletions
|
|
@ -11,18 +11,30 @@ Item {
|
|||
id: item
|
||||
|
||||
property bool _mouseAlwaysOutside
|
||||
property var _mouseArea
|
||||
property var _mouseArea: null
|
||||
|
||||
// When emitted, returns a function to test if the click
|
||||
// is on a specific item. It takes only a item parameter.
|
||||
signal pressed (var pointIsInItem)
|
||||
|
||||
function _createMouseArea () {
|
||||
var parent = Utils.getTopParent(item, true)
|
||||
var mouseArea = Utils.find(parent.children, function (element) {
|
||||
return Utils.qmlTypeof(element, 'QQuickMouseArea')
|
||||
})
|
||||
|
||||
Utils.assert(
|
||||
_mouseArea === mouseArea,
|
||||
'It already exists a different `MouseArea` at window root. (' +
|
||||
'`local mouse area`=' + _mouseArea + ', `root mouse area`=' +
|
||||
mouseArea + ')'
|
||||
)
|
||||
|
||||
if (_mouseArea == null) {
|
||||
_mouseArea = builder.createObject()
|
||||
}
|
||||
|
||||
_mouseArea.parent = Utils.getTopParent(item, true)
|
||||
_mouseArea.parent = parent
|
||||
_mouseAlwaysOutside =
|
||||
_mouseArea.parent !== Utils.getTopParent(item)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ Item {
|
|||
var children = root.children
|
||||
|
||||
// Can be the `invertedMouseArea` of other message.
|
||||
// Or another? It's a problem in this case...
|
||||
var mouseArea = children[children.length - 1]
|
||||
|
||||
if (Utils.qmlTypeof(mouseArea, 'QQuickMouseArea')) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
// Contains many common helpers.
|
||||
// ===================================================================
|
||||
|
||||
.pragma library
|
||||
|
||||
.import 'uri-tools.js' as UriTools
|
||||
|
||||
// ===================================================================
|
||||
|
|
@ -354,3 +356,40 @@ function includes (obj, value, startIndex) {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function _indexFinder (array, cb, context) {
|
||||
var length = array.length
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (cb(array[index], index, array)) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function _keyFinder (obj, cb, context) {
|
||||
var keys = Object.keys(obj)
|
||||
var length = keys.length
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var key = keys[i]
|
||||
if (cb(obj[key], key, obj)) {
|
||||
return key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the first matching value in a array or object.
|
||||
// The matching value is obtained if `cb` returns true.
|
||||
function find (obj, cb, context) {
|
||||
cb = _computeOptimizedCb(cb, context)
|
||||
|
||||
var finder = isArray(obj) ? _indexFinder : _keyFinder
|
||||
var key = finder(obj, cb, context)
|
||||
|
||||
return key != null && key !== -1 ? obj[key] : null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue