aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Toast.qml99
-rw-r--r--ToastManager.qml57
-rw-r--r--main.qml33
-rw-r--r--qml.qrc2
4 files changed, 178 insertions, 13 deletions
diff --git a/Toast.qml b/Toast.qml
new file mode 100644
index 0000000..044f509
--- /dev/null
+++ b/Toast.qml
@@ -0,0 +1,99 @@
+import QtQuick 2.0
+
+/**
+ * adapted from StackOverflow:
+ * http://stackoverflow.com/questions/26879266/make-toast-in-android-by-qml
+ * GitHub Gist: https://gist.github.com/jonmcclung/bae669101d17b103e94790341301c129
+ */
+
+/**
+ * @brief An Android-like timed message text in a box that self-destroys when finished if desired
+ */
+Rectangle {
+
+ /**
+ * Public
+ */
+
+ /**
+ * @brief Shows this Toast
+ *
+ * @param {string} text Text to show
+ * @param {real} duration Duration to show in milliseconds, defaults to 3000
+ */
+ function show(text, duration) {
+ message.text = text;
+ if (typeof duration !== "undefined") { // checks if parameter was passed
+ time = Math.max(duration, 2 * fadeTime);
+ }
+ else {
+ time = defaultTime;
+ }
+ animation.start();
+ }
+
+ property bool selfDestroying: false // whether this Toast will self-destroy when it is finished
+
+ /**
+ * Private
+ */
+
+ id: root
+
+ readonly property real defaultTime: 3000
+ property real time: defaultTime
+ readonly property real fadeTime: 300
+
+ property real margin: 10
+
+ anchors {
+ left: parent.left
+ right: parent.right
+ margins: margin
+ }
+
+ height: message.height + margin
+ radius: margin
+
+ opacity: 0
+ color: "#222222"
+
+ Text {
+ id: message
+ color: "white"
+ wrapMode: Text.Wrap
+ horizontalAlignment: Text.AlignHCenter
+ anchors {
+ top: parent.top
+ left: parent.left
+ right: parent.right
+ margins: margin / 2
+ }
+ }
+
+ SequentialAnimation on opacity {
+ id: animation
+ running: false
+
+
+ NumberAnimation {
+ to: .9
+ duration: fadeTime
+ }
+
+ PauseAnimation {
+ duration: time - 2 * fadeTime
+ }
+
+ NumberAnimation {
+ to: 0
+ duration: fadeTime
+ }
+
+ onRunningChanged: {
+ if (!running && selfDestroying) {
+ root.destroy();
+ }
+ }
+ }
+}
diff --git a/ToastManager.qml b/ToastManager.qml
new file mode 100644
index 0000000..8bb419b
--- /dev/null
+++ b/ToastManager.qml
@@ -0,0 +1,57 @@
+import QtQuick 2.0
+
+/**
+ * adapted from StackOverflow:
+ * http://stackoverflow.com/questions/26879266/make-toast-in-android-by-qml
+ * GitHub Gist: https://gist.github.com/jonmcclung/bae669101d17b103e94790341301c129
+ * @brief Manager that creates Toasts dynamically
+ */
+ListView {
+ /**
+ * Public
+ */
+
+ /**
+ * @brief Shows a Toast
+ *
+ * @param {string} text Text to show
+ * @param {real} duration Duration to show in milliseconds, defaults to 3000
+ */
+ function show(text, duration) {
+ model.insert(0, {text: text, duration: duration});
+ }
+
+ /**
+ * Private
+ */
+
+ id: root
+
+ z: Infinity
+ spacing: 5
+ anchors.fill: parent
+ anchors.bottomMargin: 10
+ verticalLayoutDirection: ListView.BottomToTop
+
+ interactive: false
+
+ displaced: Transition {
+ NumberAnimation {
+ properties: "y"
+ easing.type: Easing.InOutQuad
+ }
+ }
+
+ delegate: Toast {
+ Component.onCompleted: {
+ if (typeof duration === "undefined") {
+ show(text);
+ }
+ else {
+ show(text, duration);
+ }
+ }
+ }
+
+ model: ListModel {id: model}
+}
diff --git a/main.qml b/main.qml
index abd189c..1496c31 100644
--- a/main.qml
+++ b/main.qml
@@ -12,6 +12,10 @@ ApplicationWindow {
property int normal_width: 700
property int normal_height: 400
+ ToastManager {
+ id: toast
+ }
+
width: normal_width
height: normal_height
@@ -28,8 +32,8 @@ ApplicationWindow {
title: qsTr("Remote Support for your Desktop")
onClosing: {
- mainqmladaptor.onCloseHandler();
- console.log("Cleanup done, can close!");
+// mainqmladaptor.onCloseHandler();
+// console.log("Cleanup done, can close!");
}
Button {
@@ -175,6 +179,7 @@ ApplicationWindow {
onClicked: {
mainqmladaptor.handleCopyToClipboardButtonClick(url_text.text);
+ toast.show(qsTr("Copied URL into clipboard!"));
}
ToolTip.text: qsTr("Copy the URL into the clipboard")
@@ -191,18 +196,16 @@ ApplicationWindow {
width: parent.width - copy_url_to_clipboard_button.width - 5
height: parent.height/2
text: session.url
+ verticalAlignment: Text.AlignVCenter
+ horizontalAlignment: Text.AlignRight
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 0
+ anchors.left: parent.left
+ anchors.leftMargin: 0
font.bold: true
font.pointSize: 14
fontSizeMode: Text.Fit
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- anchors.topMargin: 0
- anchors.left: parent.left
- anchors.leftMargin: 0
- anchors.top: your_url_text.bottom
- verticalAlignment: Text.AlignVCenter
- horizontalAlignment: Text.AlignRight
- anchors.bottom: pin_text.top
- anchors.bottomMargin: 5
}
Label {
@@ -212,12 +215,11 @@ ApplicationWindow {
height: parent.height/2
text: qsTr("Remote Support URL")
font.pointSize: 14
- fontSizeMode: Text.Fit
anchors.left: parent.left
anchors.leftMargin: 0
+ fontSizeMode: Text.Fit
anchors.top: parent.top
anchors.topMargin: 0
- anchors.bottom: your_pin_text.top
verticalAlignment: Text.AlignBottom
anchors.bottomMargin: 5
clip: false
@@ -263,6 +265,7 @@ ApplicationWindow {
onClicked: {
mainqmladaptor.handleCopyToClipboardButtonClick(pin_text.text);
+ toast.show(qsTr("Copied PIN into clipboard!"));
}
ToolTip.text: qsTr("Copy the pin into the clipboard")
@@ -564,9 +567,13 @@ ApplicationWindow {
+
+
+
+
/*##^## Designer {
D{i:1;anchors_x:0;anchors_y:339}D{i:5;anchors_x:0}D{i:7;anchors_x:15;anchors_y:115}
-D{i:14;anchors_x:47}D{i:10;anchors_y:154}D{i:19;anchors_height:35;anchors_x:73;anchors_y:35}
+D{i:14;anchors_x:47;anchors_y:0}D{i:15;anchors_height:50}D{i:10;anchors_y:154}D{i:19;anchors_height:35;anchors_x:73;anchors_y:35}
D{i:20;anchors_y:0}D{i:16;anchors_height:35;anchors_width:350;anchors_x:379;anchors_y:183}
D{i:24;anchors_x:15;anchors_y:17}D{i:22;anchors_x:0;anchors_y:0}
}
diff --git a/qml.qrc b/qml.qrc
index 6653eea..8302df5 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -17,5 +17,7 @@
<file>src/RWADBusAdaptor.h</file>
<file>src/session.cpp</file>
<file>src/session.h</file>
+ <file>ToastManager.qml</file>
+ <file>Toast.qml</file>
</qresource>
</RCC>