From 35343e5158ca441f8001c0a91685f4e93b53cb03 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:22:57 +0200 Subject: Toast: Add a variety of new toast colors; Session complete rewrite; A lot of bugfixing; New available toast colors/types: ToastType.Standard, ToastType.Info, ToastType.Warning ToastType.Success, ToastType.Error --- src/Toast.qml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/Toast.qml') diff --git a/src/Toast.qml b/src/Toast.qml index 0de53a9..7a18dc8 100644 --- a/src/Toast.qml +++ b/src/Toast.qml @@ -27,6 +27,7 @@ import QtQuick 2.0 import QtQuick.Controls 2.0 import QtQuick.Controls.Material 2.3 +import rwa.toast.type 1.0 /** * adapted from StackOverflow: @@ -50,8 +51,11 @@ Control { * * @param {string} text Text to show * @param {real} duration Duration to show in milliseconds, defaults to 3000 + * @param {enum} type Type of toast. Available is: + * ToastType.Standard, ToastType.Info, ToastType.Warning + * ToastType.Success, ToastType.Error */ - function show(text, duration) { + function show(text, duration, type) { message.text = text; // checks if parameter was passed @@ -60,6 +64,23 @@ Control { } else { time = defaultTime; } + + if (typeof type !== "undefined" ) { + if (type === ToastType.ToastStandard) { + selectedColor = "#dcdedc"; + } else if (type === ToastType.ToastInfo) { + selectedColor = "#0d5eaf"; + } else if (type === ToastType.ToastSuccess) { + selectedColor = "#0daf36"; + } else if (type === ToastType.ToastWarning) { + selectedColor = "#efef2a"; + } else if (type === ToastType.ToastError) { + selectedColor = "#ed1212"; + } + } else { + selectedColor = "#dcdedc"; + } + animation.start(); } @@ -72,6 +93,7 @@ Control { id: root + property color selectedColor: "#dcdedc" readonly property real defaultTime: 3000 property real time: defaultTime readonly property real fadeTime: 300 @@ -88,6 +110,8 @@ Control { background: Rectangle { color: (Material.theme == Material.Dark) ? "#212121" : "#dcdedc" + border.color: selectedColor + border.width: 1.5 radius: margin } -- cgit v1.2.3