From 64745ece10fb36df1a89dd2cbf84d0e5aa0cc42d Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 30 Mar 2022 21:08:48 +0200 Subject: [PATCH] add simple internal notification popup, refactor MessageDialog --- electrum/gui/qml/components/MessageDialog.qml | 61 +++++++++++++++++++ .../gui/qml/components/NotificationPopup.qml | 57 +++++++++++++++++ electrum/gui/qml/components/main.qml | 61 ++----------------- 3 files changed, 124 insertions(+), 55 deletions(-) create mode 100644 electrum/gui/qml/components/MessageDialog.qml create mode 100644 electrum/gui/qml/components/NotificationPopup.qml diff --git a/electrum/gui/qml/components/MessageDialog.qml b/electrum/gui/qml/components/MessageDialog.qml new file mode 100644 index 000000000..cf8d86772 --- /dev/null +++ b/electrum/gui/qml/components/MessageDialog.qml @@ -0,0 +1,61 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Material 2.0 + +Dialog { + id: dialog + title: qsTr("Message") + + property bool yesno: false + property alias text: message.text + + signal yesClicked + signal noClicked + + parent: Overlay.overlay + modal: true + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + Overlay.modal: Rectangle { + color: "#aa000000" + } + + ColumnLayout { + TextArea { + id: message + Layout.preferredWidth: Overlay.overlay.width *2/3 + readOnly: true + wrapMode: TextInput.WordWrap + //textFormat: TextEdit.RichText // existing translations not richtext yet + background: Rectangle { + color: 'transparent' + } + } + + RowLayout { + Layout.alignment: Qt.AlignHCenter + Button { + text: qsTr('Ok') + visible: !yesno + onClicked: dialog.close() + } + Button { + text: qsTr('Yes') + visible: yesno + onClicked: { + yesClicked() + dialog.close() + } + } + Button { + text: qsTr('No') + visible: yesno + onClicked: { + noClicked() + dialog.close() + } + } + } + } +} diff --git a/electrum/gui/qml/components/NotificationPopup.qml b/electrum/gui/qml/components/NotificationPopup.qml new file mode 100644 index 000000000..ed6595bd4 --- /dev/null +++ b/electrum/gui/qml/components/NotificationPopup.qml @@ -0,0 +1,57 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Material 2.0 + +Rectangle { + id: root + + property alias text: textItem.text + + property bool hide: true + + color: Qt.lighter(Material.background, 1.5) + radius: constants.paddingXLarge + + width: root.parent.width * 2/3 + height: layout.height + x: (root.parent.width - width) / 2 + y: -height + + states: [ + State { + name: 'expanded'; when: !hide + PropertyChanges { target: root; y: 100 } + } + ] + + transitions: [ + Transition { + from: ''; to: 'expanded'; reversible: true + NumberAnimation { properties: 'y'; duration: 300; easing.type: Easing.InOutQuad } + } + ] + + RowLayout { + id: layout + width: parent.width + Text { + id: textItem + Layout.alignment: Qt.AlignHCenter + font.pixelSize: constants.fontSizeLarge + color: Material.foreground + } + } + + Timer { + id: closetimer + interval: 5000 + repeat: false + onTriggered: hide = true + } + + Component.onCompleted: { + hide = false + closetimer.start() + } +} diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml index 71bbaf2bd..91679a1f6 100644 --- a/electrum/gui/qml/components/main.qml +++ b/electrum/gui/qml/components/main.qml @@ -169,62 +169,13 @@ ApplicationWindow property alias messageDialog: _messageDialog Component { id: _messageDialog - Dialog { - id: dialog - title: qsTr("Message") - - property bool yesno: false - property alias text: message.text - - signal yesClicked - signal noClicked - - parent: Overlay.overlay - modal: true - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - Overlay.modal: Rectangle { - color: "#aa000000" - } - - ColumnLayout { - TextArea { - id: message - Layout.preferredWidth: Overlay.overlay.width *2/3 - readOnly: true - wrapMode: TextInput.WordWrap - //textFormat: TextEdit.RichText // existing translations not richtext yet - background: Rectangle { - color: 'transparent' - } - } + MessageDialog {} + } - RowLayout { - Layout.alignment: Qt.AlignHCenter - Button { - text: qsTr('Ok') - visible: !yesno - onClicked: dialog.close() - } - Button { - text: qsTr('Yes') - visible: yesno - onClicked: { - yesClicked() - dialog.close() - } - } - Button { - text: qsTr('No') - visible: yesno - onClicked: { - noClicked() - dialog.close() - } - } - } - } - } + property alias notificationPopup: _notificationPopup + Component { + id: _notificationPopup + NotificationPopup {} } Component.onCompleted: {