Commit 05d701fa authored by Ronan Abhamon's avatar Ronan Abhamon

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

parent 057ef4d5
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <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> <context>
<name>DropZone</name> <name>DropZone</name>
<message> <message>
...@@ -33,6 +44,14 @@ ...@@ -33,6 +44,14 @@
<source>addContact</source> <source>addContact</source>
<translation>ADD CONTACT</translation> <translation>ADD CONTACT</translation>
</message> </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>
<context> <context>
<name>conversation</name> <name>conversation</name>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <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> <context>
<name>DropZone</name> <name>DropZone</name>
<message> <message>
...@@ -33,6 +44,14 @@ ...@@ -33,6 +44,14 @@
<source>addContact</source> <source>addContact</source>
<translation>AJOUTER CONTACT</translation> <translation>AJOUTER CONTACT</translation>
</message> </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>
<context> <context>
<name>conversation</name> <name>conversation</name>
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<file>ui/components/contact/Contact.qml</file> <file>ui/components/contact/Contact.qml</file>
<file>ui/components/contact/ShortContactDescription.qml</file> <file>ui/components/contact/ShortContactDescription.qml</file>
<file>ui/components/contact/Avatar.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/DialogDescription.qml</file>
<file>ui/components/dialog/DialogPlus.qml</file> <file>ui/components/dialog/DialogPlus.qml</file>
<file>ui/components/form/CheckBoxText.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 { ...@@ -12,8 +12,24 @@ Window {
property alias descriptionText: description.text // Optionnal. property alias descriptionText: description.text // Optionnal.
property bool centeredButtons // Optionnal. property bool centeredButtons // Optionnal.
property bool disableExitStatus // Internal property.
signal exitStatus (int status)
modality: Qt.WindowModal 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 { ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
......
...@@ -2,17 +2,64 @@ ...@@ -2,17 +2,64 @@
// Contains many common helpers. // Contains many common helpers.
// =================================================================== // ===================================================================
function openWindow (windowName, parent) { // Load by default a window in the ui/views folder.
var component = Qt.createComponent( // If options.isString is equals to true, a marshalling component can
'qrc:/ui/views/' + windowName + '.qml' // be used.
); //
// Supported options: isString, exitHandler.
if (component.status !== Component.Ready) { //
console.debug('Window ' + windowName + ' not ready.') // If exitHandler is used, window must implement returnedValue
if(component.status === Component.Error) { // signal.
console.debug('Error:' + component.errorString()) function openWindow (window, parent, options) {
} var object
if (options && options.isString) {
object = Qt.createQmlObject(window, parent)
} else { } 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' ...@@ -6,6 +6,8 @@ import 'qrc:/ui/components/contact'
import 'qrc:/ui/components/form' import 'qrc:/ui/components/form'
import 'qrc:/ui/components/scrollBar' import 'qrc:/ui/components/scrollBar'
import 'qrc:/ui/scripts/utils.js' as Utils
ColumnLayout { ColumnLayout {
spacing: 2 spacing: 2
...@@ -169,7 +171,7 @@ ColumnLayout { ...@@ -169,7 +171,7 @@ ColumnLayout {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 15 anchors.leftMargin: 15
anchors.rightMargin: 15 anchors.rightMargin: 25
spacing: 15 spacing: 15
// Avatar. // Avatar.
...@@ -233,7 +235,13 @@ ColumnLayout { ...@@ -233,7 +235,13 @@ ColumnLayout {
ActionButton { ActionButton {
iconSize: parent.height iconSize: parent.height
icon: 'delete' 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