implement emoji handler that replaces text 😂 with text

This commit is contained in:
hydr063n 2020-09-02 20:18:16 +02:00 committed by Iuri Matias
parent 0b6643ac2d
commit 1cc43c15e7
1 changed files with 58 additions and 0 deletions

View File

@ -16,6 +16,8 @@ Rectangle {
visible: chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember(profileModel.profile.pubKey)
property bool emojiEvent: false;
Audio {
id: sendMessageSound
source: "../../../../sounds/send_message.wav"
@ -53,6 +55,62 @@ Rectangle {
if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
sendMsg(event);
}
emojiEvent = emojiHandler(emojiEvent, event);
}
function emojiHandler(emojiEvent, event) {
var msg = chatsModel.plainText(Emoji.deparse(txtData.text).trim());
if (emojiEvent == false && event.key == Qt.Key_Colon) {
if (isSpace(msg.charAt(msg.length - 1)) == true) {
console.log('emoji event');
return true;
}
return false;
} else if (emojiEvent == true && isKeyValid(event.key) == true) {
console.log('popup');
return true;
} else if (emojiEvent == true && event.key == Qt.Key_Colon) {
var index = msg.indexOf(':', 0);
txtData.remove(index - 1, txtData.length);
txtData.insert(txtData.length, " EMOJI");
if (event) event.accepted = true;
return false;
} else if (emojiEvent == true && isKeyValid(event.key) == false) {
console.log('emoji event stopped');
return false;
}
return false;
}
function isKeyValid(key) {
if (isKeyAlpha(key) == true || isKeyDigit(key) == true || key == Qt.Key_Underscore || key == Qt.Key_Shift)
return true;
return false;
}
function isSpace(c) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
return true
return false
}
function isKeyAlpha(key) {
if (key >= Qt.Key_A && key <= Qt.Key_Z)
return true;
return false;
}
function isKeyDigit(key) {
if (key >= Qt.Key_0 && key <= Qt.Key_9)
return true;
return false;
}
FileDialog {