Commit d9b4dff2 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Utils): sort qml functions by name

parent dec3dfa3
......@@ -10,6 +10,105 @@
// QML helpers.
// ===================================================================
// Destroy timeout.
function clearTimeout (timer) {
timer.stop() // NECESSARY.
timer.destroy()
}
// -------------------------------------------------------------------
// Connect a signal to a function only for one call.
function connectOnce (signal, cb) {
var func = function () {
signal.disconnect(func)
cb.apply(this, arguments)
}
signal.connect(func)
return func
}
// -------------------------------------------------------------------
function encodeUrisToQmlFormat (text, options) {
var images = ''
if (options == null) {
options = {}
}
text = text
.replace(/</g, '\u2063&lt;')
.replace(/>/g, '\u2063&gt;')
.replace(UriTools.URI_REGEX, function (match) {
// If it's a simple URL, transforms it in URI.
if (startsWith(match, 'www.')) {
match = 'http://' + match
}
var ext = getExtension(match)
if (includes([ 'jpg', 'jpeg', 'gif', 'png', 'svg' ], ext)) {
images += '<a href="' + match + '"><img' + (
options.imagesWidth != null
? ' width="' + options.imagesWidth + '"'
: ''
) + (
options.imagesHeight != null
? ' height="' + options.imagesHeight + '"'
: ''
) + ' src="' + match + '" /></a>'
}
return '<a href="' + match + '">' + match + '</a>'
})
if (images.length > 0) {
images = '<div>' + images + '</div>'
}
return images.concat('<p>' + text + '</p>')
}
// -------------------------------------------------------------------
// Returns the top (root) parent of one object.
function getTopParent (object, useFakeParent) {
function _getTopParent (object, useFakeParent) {
return (useFakeParent && object.$parent) || object.parent
}
var parent = _getTopParent(object, useFakeParent)
var p
while ((p = _getTopParent(parent, useFakeParent)) != null) {
parent = p
}
return parent
}
// -------------------------------------------------------------------
// Display a simple ConfirmDialog component.
// Wrap the openWindow function.
function openConfirmDialog (parent, options) {
return openWindow(
'import QtQuick 2.7;' +
'import Common 1.0;' +
'ConfirmDialog {' +
'descriptionText: \'' + options.descriptionText + '\';' +
'title: \'' + options.title + '\'' +
'}',
parent, {
isString: true,
exitHandler: options.exitHandler
}
)
}
// -------------------------------------------------------------------
// Load by default a window in the ui/views folder.
// If options.isString is equals to true, a marshalling component can
// be used.
......@@ -54,25 +153,6 @@ function openWindow (window, parent, options) {
// -------------------------------------------------------------------
// Display a simple ConfirmDialog component.
// Wrap the openWindow function.
function openConfirmDialog (parent, options) {
return openWindow(
'import QtQuick 2.7;' +
'import Common 1.0;' +
'ConfirmDialog {' +
'descriptionText: \'' + options.descriptionText + '\';' +
'title: \'' + options.title + '\'' +
'}',
parent, {
isString: true,
exitHandler: options.exitHandler
}
)
}
// -------------------------------------------------------------------
// A copy of `Window.setTimeout` from js.
// delay is in milliseconds.
function setTimeout (parent, delay, cb) {
......@@ -88,41 +168,22 @@ function setTimeout (parent, delay, cb) {
return timer
}
// Destroy timeout.
function clearTimeout (timer) {
timer.stop() // NECESSARY.
timer.destroy()
}
// -------------------------------------------------------------------
// Connect a signal to a function only for one call.
function connectOnce (signal, cb) {
var func = function () {
signal.disconnect(func)
cb.apply(this, arguments)
}
signal.connect(func)
return func
}
// -------------------------------------------------------------------
// Returns the top (root) parent of one object.
function getTopParent (object, useFakeParent) {
function _getTopParent (object, useFakeParent) {
return (useFakeParent && object.$parent) || object.parent
}
var parent = _getTopParent(object, useFakeParent)
var p
while ((p = _getTopParent(parent, useFakeParent)) != null) {
parent = p
}
// Test if a point is in a item.
//
// `source` is the item that generated the point.
// `target` is the item to test.
// `point` is the point to test.
function pointIsInItem (source, target, point) {
point = source.mapToItem(target.parent, point.x, point.y)
return parent
return (
point.x >= target.x &&
point.y >= target.y &&
point.x < target.x + target.width &&
point.y < target.y + target.height
)
}
// -------------------------------------------------------------------
......@@ -142,65 +203,6 @@ function qmlTypeof (object, className) {
)
}
// -------------------------------------------------------------------
function encodeUrisToQmlFormat (text, options) {
var images = ''
if (options == null) {
options = {}
}
text = text
.replace(/</g, '\u2063&lt;')
.replace(/>/g, '\u2063&gt;')
.replace(UriTools.URI_REGEX, function (match) {
// If it's a simple URL, transforms it in URI.
if (startsWith(match, 'www.')) {
match = 'http://' + match
}
var ext = getExtension(match)
if (includes([ 'jpg', 'jpeg', 'gif', 'png', 'svg' ], ext)) {
images += '<a href="' + match + '"><img' + (
options.imagesWidth != null
? ' width="' + options.imagesWidth + '"'
: ''
) + (
options.imagesHeight != null
? ' height="' + options.imagesHeight + '"'
: ''
) + ' src="' + match + '" /></a>'
}
return '<a href="' + match + '">' + match + '</a>'
})
if (images.length > 0) {
images = '<div>' + images + '</div>'
}
return images.concat('<p>' + text + '</p>')
}
// -------------------------------------------------------------------
// Test if a point is in a item.
//
// `source` is the item that generated the point.
// `target` is the item to test.
// `point` is the point to test.
function pointIsInItem (source, target, point) {
point = source.mapToItem(target.parent, point.x, point.y)
return (
point.x >= target.x &&
point.y >= target.y &&
point.x < target.x + target.width &&
point.y < target.y + target.height
)
}
// ===================================================================
// GENERIC.
// ===================================================================
......
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