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
retroshare-qml-app/src

View File

@ -1,18 +1,15 @@
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
property EmojiCategoryButton currSelEmojiButton property EmojiCategoryButton currSelEmojiButton
property variant emojiParsedJson property variant emojiParsedJson
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){
@ -38,22 +35,6 @@ Rectangle {
strAppnd += selectedEmoji strAppnd += selectedEmoji
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
@ -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()
}
}
} }