Set RS emoji font as default if no emoji native font is detected

This commit is contained in:
Angela Mazzurco 2017-08-02 17:34:29 +02:00
parent 1cdb3db548
commit 0a5b3508da
3 changed files with 33 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.2
Rectangle { Rectangle {
id: emojiButton id: emojiButton
property var fontName
Text { Text {
id: emojiText id: emojiText
@ -11,6 +12,7 @@ Rectangle {
text: qsTr(eCatText) text: qsTr(eCatText)
font.pixelSize: emojiButton.width - 8 font.pixelSize: emojiButton.width - 8
anchors.centerIn: parent anchors.centerIn: parent
font.family: fontName
} }

View File

@ -5,6 +5,8 @@ Rectangle {
id: emojiCategoryButton id: emojiCategoryButton
property string categoryName property string categoryName
property var fontName
function completedHandler() { function completedHandler() {
categoryName = eCatName categoryName = eCatName
@ -38,6 +40,7 @@ Rectangle {
text: qsTr(eCatText) text: qsTr(eCatText)
font.pixelSize: emojiCategoryButton.width - 8 font.pixelSize: emojiCategoryButton.width - 8
anchors.centerIn: parent anchors.centerIn: parent
font.family: fontName
} }

View File

@ -1,6 +1,7 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import "emoji.js" as EmojiJSON import "emoji.js" as EmojiJSON
//import "../../fonts/."
Rectangle { Rectangle {
id: emojiPicker id: emojiPicker
@ -9,6 +10,10 @@ Rectangle {
property int buttonWidth: 40 property int buttonWidth: 40
property TextArea textArea 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 //displays all Emoji of one categroy by modifying the ListModel of emojiGrid
function categoryChangedHandler (newCategoryName){ function categoryChangedHandler (newCategoryName){
emojiByCategory.clear() emojiByCategory.clear()
@ -35,6 +40,22 @@ Rectangle {
textArea.insert(textArea.cursorPosition, strAppnd) 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 //parses JSON, publishes button handlers and inits textArea
function completedHandler() { function completedHandler() {
// emojiParsedJson = JSON.parse(EmojiJSON.emoji_json) // emojiParsedJson = JSON.parse(EmojiJSON.emoji_json)
@ -63,7 +84,6 @@ Rectangle {
} }
} }
//all emoji of one category //all emoji of one category
ListModel { ListModel {
id: emojiByCategory id: emojiByCategory
@ -81,6 +101,7 @@ Rectangle {
width: buttonWidth width: buttonWidth
height: buttonWidth height: buttonWidth
color: emojiPicker.color color: emojiPicker.color
fontName: rootFontName
} }
} }
@ -112,6 +133,7 @@ Rectangle {
width: buttonWidth width: buttonWidth
height: buttonWidth height: buttonWidth
color: emojiPicker.color color: emojiPicker.color
fontName: rootFontName
} }
} }
@ -119,6 +141,10 @@ Rectangle {
id: emojiCategoryButtons id: emojiCategoryButtons
} }
Component.onCompleted: completedHandler() Component.onCompleted:
{
selectFont()
completedHandler()
}
} }