Set emoji font declaration global for all app

This commit is contained in:
Angela Mazzurco 2017-08-02 18:09:40 +02:00
parent 0a5b3508da
commit 54c8e26fee
2 changed files with 35 additions and 22 deletions

View File

@ -1,7 +1,6 @@
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
@ -10,9 +9,7 @@ Rectangle {
property int buttonWidth: 40 property int buttonWidth: 40
property TextArea textArea property TextArea textArea
FontLoader { id: emojiFont; source: "/fonts/OpenSansEmoji.ttf" } property var rootFontName: theme.emojiFontName
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){
@ -40,22 +37,6 @@ 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)
@ -143,7 +124,6 @@ Rectangle {
Component.onCompleted: Component.onCompleted:
{ {
selectFont()
completedHandler() completedHandler()
} }
} }

View File

@ -558,4 +558,37 @@ ApplicationWindow
onTriggered: linkCopiedPopup.close() onTriggered: linkCopiedPopup.close()
} }
} }
FontLoader { id: emojiFont; source: "/fonts/OpenSansEmoji.ttf" }
QtObject
{
id: theme
property var emojiFontName: emojiFont.name
property var supportedEmojiFonts: ["Android Emoji"]
property var rootFontName: emojiFont.name
// If native emoji font exists use it, else use RS emoji font
function selectFont ()
{
var fontFamilies = Qt.fontFamilies()
fontFamilies.some(function (f)
{
if (supportedEmojiFonts.indexOf(f) !== -1)
{
emojiFontName = f
return true
}
return false
})
}
Component.onCompleted:
{
selectFont()
}
}
} }