From afc901b017e58386b76a4c1e806a6c2eb5f247bb Mon Sep 17 00:00:00 2001 From: Black Hat Date: Wed, 11 Jul 2018 16:07:04 +0800 Subject: [PATCH] Add rainbow support. --- qml/form/RoomForm.qml | 46 ++++++++++++++++++++++++------------------- qml/main.qml | 20 ++++++++++--------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index b6be10a..d2a9f77 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -193,36 +193,42 @@ Item { return } - var type = "m.text" var PREFIX_ME = '/me ' - var PREFIX_RAINBOW = '/rainbow' + var PREFIX_RAINBOW = '/rainbow ' + var PREFIX_HTML = '/html ' + var PREFIX_MARKDOWN = '/md ' + if (text.indexOf(PREFIX_ME) === 0) { text = text.substr(PREFIX_ME.length) - type = "m.emote" + currentRoom.postMessage("m.emote", text) + return } if (text.indexOf(PREFIX_RAINBOW) === 0) { text = text.substr(PREFIX_RAINBOW.length) + + var parsedText = "" + var rainbowColor = ["#ee0000", "#ff7700", "#eeee00", "#00bb00", "#0000ee", "#dd00dd", "#880088"] + for (var i = 0; i < text.length; i++) { + parsedText = parsedText + "" + text.charAt(i) + "" + } + currentRoom.postHtmlMessage(text, parsedText, "m.text") + return } - - var result = parse(text) - var parsedText = result[0] - var isMarkdown = result [1] - - if (isMarkdown) currentRoom.postHtmlMessage(text, parsedText, type) - else currentRoom.postMessage(type, text) - } - - function parse(text) { - if (!testHTML(text)) { + if (text.indexOf(PREFIX_HTML) === 0) { + text = text.substr(PREFIX_HTML.length) + var re = new RegExp("<.*?>") + var plainText = text.replace(re, "") + currentRoom.postHtmlMessage(plainText, text, "m.text") + return + } + if (text.indexOf(PREFIX_MARKDOWN) === 0) { + text = text.substr(PREFIX_MARKDOWN.length) var parsedText = Markdown.markdown_parser(text) - if (testHTML(parsedText)) return [parsedText, true] + currentRoom.postHtmlMessage(text, parsedText, "m.text") + return } - return [text, false] - } - function testHTML(text) { - var re = new RegExp("(<([^>]+)>)") - return re.test(text) + currentRoom.postMessage("m.text", text) } } diff --git a/qml/main.qml b/qml/main.qml index d14de15..dda7a2d 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -28,16 +28,18 @@ ApplicationWindow { property alias token: matriqueController.token } - // Platform.SystemTrayIcon { - // visible: true - // iconSource: "qrc:/asset/img/icon.png" +// Platform.SystemTrayIcon { +// id: trayIcon - // onActivated: { - // window.show() - // window.raise() - // window.requestActivate() - // } - // } +// visible: true +// iconSource: "qrc:/asset/img/icon.png" + +// onActivated: { +// window.show() +// window.raise() +// window.requestActivate() +// } +// } Controller { id: matriqueController