aboutsummaryrefslogtreecommitdiff
path: root/src/Toast.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/Toast.qml')
-rw-r--r--src/Toast.qml44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/Toast.qml b/src/Toast.qml
index eb65b20..7a18dc8 100644
--- a/src/Toast.qml
+++ b/src/Toast.qml
@@ -1,8 +1,8 @@
/*
* This file is part of Remote Support Desktop
* https://gitlab.das-netzwerkteam.de/RemoteWebApp/remote-support-desktop
- * Copyright 2020-2021 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de>
- * Copyright 2020-2021 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
+ * Copyright 2020, 2021 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de>
+ * Copyright 2020, 2021 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or modify
@@ -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:
@@ -36,7 +37,8 @@ import QtQuick.Controls.Material 2.3
*/
/**
- * @brief An Android-like timed message text in a box that self-destroys when finished if desired
+ * @brief An Android-like timed message text in
+ * a box that self-destroys when finished if desired
*/
Control {
@@ -49,20 +51,41 @@ 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;
- if (typeof duration !== "undefined") { // checks if parameter was passed
+
+ // checks if parameter was passed
+ if (typeof duration !== "undefined") {
time = Math.max(duration, 2 * fadeTime);
- }
- else {
+ } else {
time = defaultTime;
}
- console.log("Showing a new toast with display time: " + time);
+
+ 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();
}
- property bool selfDestroying: false // whether this Toast will self-destroy when it is finished
+ // whether this Toast will self-destroy when it is finished
+ property bool selfDestroying: false
/**
* Private
@@ -70,6 +93,7 @@ Control {
id: root
+ property color selectedColor: "#dcdedc"
readonly property real defaultTime: 3000
property real time: defaultTime
readonly property real fadeTime: 300
@@ -86,6 +110,8 @@ Control {
background: Rectangle {
color: (Material.theme == Material.Dark) ? "#212121" : "#dcdedc"
+ border.color: selectedColor
+ border.width: 1.5
radius: margin
}