mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 14:48:15 +00:00
- InvertedMouseArea use a asynchronous call on pressed event - ListForm use an external style - ListForm supports outside click - ...
103 lines
2.6 KiB
JavaScript
103 lines
2.6 KiB
JavaScript
// ===================================================================
|
|
// Contains many common helpers.
|
|
// ===================================================================
|
|
|
|
// Load by default a window in the ui/views folder.
|
|
// If options.isString is equals to true, a marshalling component can
|
|
// be used.
|
|
//
|
|
// Supported options: isString, exitHandler.
|
|
//
|
|
// If exitHandler is used, window must implement exitStatus signal.
|
|
function openWindow (window, parent, options) {
|
|
var object
|
|
|
|
if (options && options.isString) {
|
|
object = Qt.createQmlObject(window, parent)
|
|
} else {
|
|
var component = Qt.createComponent(
|
|
'qrc:/ui/views/' + window + '.qml'
|
|
)
|
|
|
|
if (component.status !== Component.Ready) {
|
|
console.debug('Window not ready.')
|
|
if(component.status === Component.Error) {
|
|
console.debug('Error:' + component.errorString())
|
|
}
|
|
return // Error.
|
|
}
|
|
|
|
object = component.createObject(parent)
|
|
}
|
|
|
|
console.debug('Open window.')
|
|
|
|
object.closing.connect(function () {
|
|
console.debug('Destroy window.')
|
|
object.destroy()
|
|
})
|
|
object.exitStatus.connect(function (status) {
|
|
console.debug('Exit status: ' + status)
|
|
})
|
|
|
|
if (options && options.exitHandler) {
|
|
object.exitStatus.connect(
|
|
// Bind to access parent properties.
|
|
options.exitHandler.bind(parent)
|
|
)
|
|
}
|
|
|
|
object.show()
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Display a simple ConfirmDialog component.
|
|
// Wrap the openWindow function.
|
|
function openConfirmDialog (parent, options) {
|
|
openWindow(
|
|
'import QtQuick 2.7;' +
|
|
'import \'qrc:/ui/modules/Linphone/Dialog\';' +
|
|
'ConfirmDialog {' +
|
|
'descriptionText: \'' + options.descriptionText + '\';' +
|
|
'title: \'' + options.title + '\'' +
|
|
'}',
|
|
parent, {
|
|
isString: true,
|
|
exitHandler: options.exitHandler
|
|
}
|
|
)
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
function snakeToCamel (s) {
|
|
return s.replace(/(\_\w)/g, function (matches) {
|
|
return matches[1].toUpperCase()
|
|
})
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
function Timer (parent) {
|
|
return Qt.createQmlObject('import QtQuick 2.7; Timer { }', parent)
|
|
}
|
|
|
|
// A copy of `Window.setTimeout` from js.
|
|
// Use setTimeout.call(parentContext, delayTime, cb) to use it.
|
|
//
|
|
// delay is in milliseconds.
|
|
function setTimeout (delay, cb) {
|
|
var timer = new Timer(this)
|
|
|
|
timer.interval = delay
|
|
timer.repeat = false
|
|
timer.triggered.connect(cb)
|
|
timer.start()
|
|
|
|
return timer
|
|
}
|
|
|
|
function clearTimeout (timer) {
|
|
timer.destroy() // Not necessary: `timer.stop()`
|
|
}
|