Commit 05d701fa authored by Ronan's avatar Ronan
Browse files

feat(scripts/utils): supports window creation and returned status

parent 057ef4d5
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>ConfirmDialog</name>
<message>
<source>cancel</source>
<translation>CANCEL</translation>
</message>
<message>
<source>confirm</source>
<translation>CONFIRM</translation>
</message>
</context>
<context>
<name>DropZone</name>
<message>
......@@ -33,6 +44,14 @@
<source>addContact</source>
<translation>ADD CONTACT</translation>
</message>
<message>
<source>removeContactDescription</source>
<translation>Do you really want remove this contact from your book?</translation>
</message>
<message>
<source>removeContactTitle</source>
<translation>Delete confirmation</translation>
</message>
</context>
<context>
<name>conversation</name>
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>ConfirmDialog</name>
<message>
<source>cancel</source>
<translation>ANNULER</translation>
</message>
<message>
<source>confirm</source>
<translation>CONFIRMER</translation>
</message>
</context>
<context>
<name>DropZone</name>
<message>
......@@ -33,6 +44,14 @@
<source>addContact</source>
<translation>AJOUTER CONTACT</translation>
</message>
<message>
<source>removeContactDescription</source>
<translation>Voulez-vous vraiment supprimer ce contact de votre carnet ?</translation>
</message>
<message>
<source>removeContactTitle</source>
<translation>Confirmation de la suppression</translation>
</message>
</context>
<context>
<name>conversation</name>
......
......@@ -9,6 +9,7 @@
<file>ui/components/contact/Contact.qml</file>
<file>ui/components/contact/ShortContactDescription.qml</file>
<file>ui/components/contact/Avatar.qml</file>
<file>ui/components/dialog/ConfirmDialog.qml</file>
<file>ui/components/dialog/DialogDescription.qml</file>
<file>ui/components/dialog/DialogPlus.qml</file>
<file>ui/components/form/CheckBoxText.qml</file>
......
import QtQuick 2.7
import 'qrc:/ui/components/form'
// ===================================================================
DialogPlus {
buttons: [
DarkButton {
onClicked: exit(0)
text: qsTr('cancel')
},
DarkButton {
onClicked: exit(1)
text: qsTr('confirm')
}
]
centeredButtons: true
id: dialog
maximumWidth: 370
maximumHeight: 150
minimumWidth: 370
minimumHeight: 150
}
......@@ -12,8 +12,24 @@ Window {
property alias descriptionText: description.text // Optionnal.
property bool centeredButtons // Optionnal.
property bool disableExitStatus // Internal property.
signal exitStatus (int status)
modality: Qt.WindowModal
// Handle normal windows close.
onClosing: !disableExitStatus && exitStatus(0)
// Derived class must use this function instead of close.
function exit (status) {
if (!disableExitStatus) {
disableExitStatus = true
exitStatus(status)
close()
}
}
ColumnLayout {
anchors.fill: parent
spacing: 0
......
......@@ -2,17 +2,64 @@
// Contains many common helpers.
// ===================================================================
function openWindow (windowName, parent) {
var component = Qt.createComponent(
'qrc:/ui/views/' + windowName + '.qml'
);
if (component.status !== Component.Ready) {
console.debug('Window ' + windowName + ' not ready.')
if(component.status === Component.Error) {
console.debug('Error:' + component.errorString())
}
// 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 returnedValue
// signal.
function openWindow (window, parent, options) {
var object
if (options && options.isString) {
object = Qt.createQmlObject(window, parent)
} else {
component.createObject(parent).show()
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()
})
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/components/dialog\';' +
'ConfirmDialog {' +
'descriptionText: \'' + options.descriptionText + '\';' +
'title: \'' + options.title + '\'' +
'}',
parent, {
isString: true,
exitHandler: options.exitHandler
}
)
}
......@@ -6,6 +6,8 @@ import 'qrc:/ui/components/contact'
import 'qrc:/ui/components/form'
import 'qrc:/ui/components/scrollBar'
import 'qrc:/ui/scripts/utils.js' as Utils
ColumnLayout {
spacing: 2
......@@ -169,7 +171,7 @@ ColumnLayout {
RowLayout {
anchors.fill: parent
anchors.leftMargin: 15
anchors.rightMargin: 15
anchors.rightMargin: 25
spacing: 15
// Avatar.
......@@ -233,7 +235,13 @@ ColumnLayout {
ActionButton {
iconSize: parent.height
icon: 'delete'
onClicked: console.log('action: delete')
onClicked: Utils.openConfirmDialog(contact, {
descriptionText: qsTr('removeContactDescription'),
exitHandler: function (status) {
console.log('remove contact', status)
},
title: qsTr('removeContactTitle')
})
}
}
}
......
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