diff --git a/tests/languages/en.ts b/tests/languages/en.ts index 2779aa880..32656388c 100644 --- a/tests/languages/en.ts +++ b/tests/languages/en.ts @@ -1,6 +1,17 @@ + + ConfirmDialog + + cancel + CANCEL + + + confirm + CONFIRM + + DropZone @@ -33,6 +44,14 @@ addContact ADD CONTACT + + removeContactDescription + Do you really want remove this contact from your book? + + + removeContactTitle + Delete confirmation + conversation diff --git a/tests/languages/fr.ts b/tests/languages/fr.ts index 18f74db06..52a2d811b 100644 --- a/tests/languages/fr.ts +++ b/tests/languages/fr.ts @@ -1,6 +1,17 @@ + + ConfirmDialog + + cancel + ANNULER + + + confirm + CONFIRMER + + DropZone @@ -33,6 +44,14 @@ addContact AJOUTER CONTACT + + removeContactDescription + Voulez-vous vraiment supprimer ce contact de votre carnet ? + + + removeContactTitle + Confirmation de la suppression + conversation diff --git a/tests/resources.qrc b/tests/resources.qrc index 34d9517a0..3a54ab526 100644 --- a/tests/resources.qrc +++ b/tests/resources.qrc @@ -9,6 +9,7 @@ ui/components/contact/Contact.qml ui/components/contact/ShortContactDescription.qml ui/components/contact/Avatar.qml + ui/components/dialog/ConfirmDialog.qml ui/components/dialog/DialogDescription.qml ui/components/dialog/DialogPlus.qml ui/components/form/CheckBoxText.qml diff --git a/tests/ui/components/dialog/ConfirmDialog.qml b/tests/ui/components/dialog/ConfirmDialog.qml new file mode 100644 index 000000000..a408b66fa --- /dev/null +++ b/tests/ui/components/dialog/ConfirmDialog.qml @@ -0,0 +1,24 @@ +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 +} diff --git a/tests/ui/components/dialog/DialogPlus.qml b/tests/ui/components/dialog/DialogPlus.qml index 68f52dfef..c4ae89651 100644 --- a/tests/ui/components/dialog/DialogPlus.qml +++ b/tests/ui/components/dialog/DialogPlus.qml @@ -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 diff --git a/tests/ui/scripts/utils.js b/tests/ui/scripts/utils.js index f629f2cb9..4c9ba4a1d 100644 --- a/tests/ui/scripts/utils.js +++ b/tests/ui/scripts/utils.js @@ -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 + } + ) } diff --git a/tests/ui/views/mainWindow/contacts.qml b/tests/ui/views/mainWindow/contacts.qml index 0184a7889..632f40485 100644 --- a/tests/ui/views/mainWindow/contacts.qml +++ b/tests/ui/views/mainWindow/contacts.qml @@ -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') + }) } } }