From 0a5b3508dad398a37f39c2dd41c2ee6ee3506fa8 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 2 Aug 2017 17:34:29 +0200 Subject: [PATCH] Set RS emoji font as default if no emoji native font is detected --- .../src/components/emoji/EmojiButton.qml | 2 ++ .../components/emoji/EmojiCategoryButton.qml | 3 ++ .../src/components/emoji/EmojiPicker.qml | 30 +++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/components/emoji/EmojiButton.qml b/retroshare-qml-app/src/components/emoji/EmojiButton.qml index b75ec5f31..3720d9f5c 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiButton.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiButton.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.2 Rectangle { id: emojiButton + property var fontName Text { id: emojiText @@ -11,6 +12,7 @@ Rectangle { text: qsTr(eCatText) font.pixelSize: emojiButton.width - 8 anchors.centerIn: parent + font.family: fontName } diff --git a/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml b/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml index 19e846d3e..12983cf5b 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml @@ -5,6 +5,8 @@ Rectangle { id: emojiCategoryButton property string categoryName + property var fontName + function completedHandler() { categoryName = eCatName @@ -38,6 +40,7 @@ Rectangle { text: qsTr(eCatText) font.pixelSize: emojiCategoryButton.width - 8 anchors.centerIn: parent + font.family: fontName } diff --git a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml index 2818fd789..7e9c4baa8 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import "emoji.js" as EmojiJSON +//import "../../fonts/." Rectangle { id: emojiPicker @@ -9,6 +10,10 @@ Rectangle { property int buttonWidth: 40 property TextArea textArea + FontLoader { id: emojiFont; source: "/fonts/OpenSansEmoji.ttf" } + property var supportedEmojiFonts: ["Android Emoji"] + property var rootFontName: emojiFont.name + //displays all Emoji of one categroy by modifying the ListModel of emojiGrid function categoryChangedHandler (newCategoryName){ emojiByCategory.clear() @@ -35,6 +40,22 @@ Rectangle { textArea.insert(textArea.cursorPosition, strAppnd) } + // If native emoji font exists use it, else use RS emoji font + function selectFont () + { + var fontFamilies = Qt.fontFamilies() + return fontFamilies.some(function (f) + { + if (supportedEmojiFonts.indexOf(f) !== -1) + { + console.log("Compatible native emoji font found: " +f) + rootFontName = f + return true + } + return false + }) + } + //parses JSON, publishes button handlers and inits textArea function completedHandler() { // emojiParsedJson = JSON.parse(EmojiJSON.emoji_json) @@ -63,7 +84,6 @@ Rectangle { } } - //all emoji of one category ListModel { id: emojiByCategory @@ -81,6 +101,7 @@ Rectangle { width: buttonWidth height: buttonWidth color: emojiPicker.color + fontName: rootFontName } } @@ -112,6 +133,7 @@ Rectangle { width: buttonWidth height: buttonWidth color: emojiPicker.color + fontName: rootFontName } } @@ -119,6 +141,10 @@ Rectangle { id: emojiCategoryButtons } - Component.onCompleted: completedHandler() + Component.onCompleted: + { + selectFont() + completedHandler() + } }