From a58948b9d0bb08287d464741a1e48aa2cbdbbc1c Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Wed, 15 Mar 2023 08:34:54 +0100 Subject: [PATCH] add new snippet 'snippets/toast' (like android 'Toast') --- snippets/busy/lisp/main.lisp | 19 ---------- snippets/busy/run.lisp | 20 ++++++++++- snippets/toast/qml/ext/Toast.qml | 60 ++++++++++++++++++++++++++++++++ snippets/toast/qml/main.qml | 9 +++++ snippets/toast/readme.md | 4 +++ snippets/toast/run.lisp | 7 ++++ 6 files changed, 99 insertions(+), 20 deletions(-) delete mode 100644 snippets/busy/lisp/main.lisp create mode 100644 snippets/toast/qml/ext/Toast.qml create mode 100644 snippets/toast/qml/main.qml create mode 100644 snippets/toast/readme.md create mode 100644 snippets/toast/run.lisp diff --git a/snippets/busy/lisp/main.lisp b/snippets/busy/lisp/main.lisp deleted file mode 100644 index 9944c68..0000000 --- a/snippets/busy/lisp/main.lisp +++ /dev/null @@ -1,19 +0,0 @@ -(in-package :qml-user) - -(defun request () - "Runs request in a thread, returns after thread finished." - (q> |playing| "busy" t) ; start animation - (let (response) - ;; worker thread - (mp:process-run-function - :request - (lambda () - (sleep 3) ; working hard... - (setf response :ok) - (qexit))) - ;; main thread - (qexec (* 60 1000)) ; timeout (ms) - (q> |playing| "busy" nil) ; stop animation - response)) - -(qsingle-shot 1000 'request) diff --git a/snippets/busy/run.lisp b/snippets/busy/run.lisp index 981eaf4..9944c68 100644 --- a/snippets/busy/run.lisp +++ b/snippets/busy/run.lisp @@ -1 +1,19 @@ -(load "lisp/main.lisp") +(in-package :qml-user) + +(defun request () + "Runs request in a thread, returns after thread finished." + (q> |playing| "busy" t) ; start animation + (let (response) + ;; worker thread + (mp:process-run-function + :request + (lambda () + (sleep 3) ; working hard... + (setf response :ok) + (qexit))) + ;; main thread + (qexec (* 60 1000)) ; timeout (ms) + (q> |playing| "busy" nil) ; stop animation + response)) + +(qsingle-shot 1000 'request) diff --git a/snippets/toast/qml/ext/Toast.qml b/snippets/toast/qml/ext/Toast.qml new file mode 100644 index 0000000..64cb798 --- /dev/null +++ b/snippets/toast/qml/ext/Toast.qml @@ -0,0 +1,60 @@ +import QtQuick 2.15 + +Rectangle { + id: toast + objectName: "toast" + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + z: 99 + width: msg.contentWidth + 70 + height: msg.contentHeight + 30 + color: "#303030" + border.width: 2 + border.color: "white" + radius: height / 2 + opacity: 0 + visible: false + + function message(text) { // called from Lisp + toast.visible = true + msg.text = text + anim.start() + } + + Text { + id: msg + font.pixelSize: 16 + font.bold: true + anchors.centerIn: parent + color: "white" + wrapMode: Text.WordWrap + width: toast.parent.width - 2 * toast.radius - 10 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + SequentialAnimation { + id: anim + onFinished: { toast.visible = false } + + OpacityAnimator { + from: 0 + to: 0.8 + target: toast + easing.type: Easing.InOutQuart + duration: 500 + } + + PauseAnimation { + duration: 3000 + } + + OpacityAnimator { + from: 0.8 + to: 0 + target: toast + easing.type: Easing.InOutQuart + duration: 1500 + } + } +} diff --git a/snippets/toast/qml/main.qml b/snippets/toast/qml/main.qml new file mode 100644 index 0000000..9e006a0 --- /dev/null +++ b/snippets/toast/qml/main.qml @@ -0,0 +1,9 @@ +import QtQuick 2.15 +import 'ext/' as Ext + +Rectangle { + width: 300 + height: 500 + + Ext.Toast {} +} diff --git a/snippets/toast/readme.md b/snippets/toast/readme.md new file mode 100644 index 0000000..7e96880 --- /dev/null +++ b/snippets/toast/readme.md @@ -0,0 +1,4 @@ +Description +----------- + +An info message similar to a `Toast` on android. diff --git a/snippets/toast/run.lisp b/snippets/toast/run.lisp new file mode 100644 index 0000000..6090b6f --- /dev/null +++ b/snippets/toast/run.lisp @@ -0,0 +1,7 @@ +(in-package :qml-user) + +(defun toast (message) + (qjs |message| "toast" message)) + +(qsingle-shot 1000 (lambda () (toast "You look tired, go get some coffee."))) +