feat: add emoji search
(cherry picked from commit 3cc9a98ce584a48f6c430a57126bd548e9dedc7e)
This commit is contained in:
parent
549f1ff7f2
commit
13d2cf73fb
|
@ -11,6 +11,7 @@ import "./emojiList.js" as EmojiJSON
|
||||||
Popup {
|
Popup {
|
||||||
property var addToChat: function () {}
|
property var addToChat: function () {}
|
||||||
property var categories: []
|
property var categories: []
|
||||||
|
property string searchString: searchBox.text
|
||||||
|
|
||||||
id: popup
|
id: popup
|
||||||
modal: false
|
modal: false
|
||||||
|
@ -40,7 +41,6 @@ Popup {
|
||||||
categoryNames[emoji.category] = newCategories.length
|
categoryNames[emoji.category] = newCategories.length
|
||||||
newCategories.push([])
|
newCategories.push([])
|
||||||
}
|
}
|
||||||
|
|
||||||
newCategories[categoryNames[emoji.category]].push(emoji)
|
newCategories[categoryNames[emoji.category]].push(emoji)
|
||||||
})
|
})
|
||||||
if (newCategories[categoryNames.recent].length === 0) {
|
if (newCategories[categoryNames.recent].length === 0) {
|
||||||
|
@ -53,6 +53,10 @@ Popup {
|
||||||
categories = newCategories
|
categories = newCategories
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOpened: {
|
||||||
|
searchBox.forceActiveFocus(Qt.MouseFocusReason)
|
||||||
|
}
|
||||||
|
|
||||||
contentItem: ColumnLayout {
|
contentItem: ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
@ -146,7 +150,9 @@ Popup {
|
||||||
id: emojiSectionsRepeater
|
id: emojiSectionsRepeater
|
||||||
model: popup.categories
|
model: popup.categories
|
||||||
|
|
||||||
EmojiSection {}
|
EmojiSection {
|
||||||
|
searchString: popup.searchString
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,22 @@ import "../../../../shared"
|
||||||
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
property string searchString: ""
|
||||||
|
property string searchStringLowercase: searchString.toLowerCase()
|
||||||
property int imageWidth: 26
|
property int imageWidth: 26
|
||||||
property int imageMargin: 4
|
property int imageMargin: 4
|
||||||
|
property var emojis: []
|
||||||
|
property var allEmojis: []
|
||||||
|
|
||||||
id: emojiSection
|
id: emojiSection
|
||||||
|
visible: emojis.length > 0 || !!(modelData && modelData.length && modelData[0].empty && searchString === "")
|
||||||
|
|
||||||
anchors.top: index === 0 ? parent.top : parent.children[index - 1].bottom
|
anchors.top: index === 0 ? parent.top : parent.children[index - 1].bottom
|
||||||
anchors.topMargin: index === 0 ? 0 : Style.current.padding
|
anchors.topMargin: index === 0 ? 0 : Style.current.padding
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: childrenRect.height + Style.current.padding
|
// childrenRect caused a binding loop here
|
||||||
|
height: this.visible ? emojiGrid.height + categoryText.height + noRecentText.height + Style.current.padding : 0
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
id: categoryText
|
id: categoryText
|
||||||
|
@ -24,6 +30,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
id: noRecentText
|
||||||
visible: !!(modelData && modelData.length && modelData[0].empty)
|
visible: !!(modelData && modelData.length && modelData[0].empty)
|
||||||
text: qsTr("No recent emojis")
|
text: qsTr("No recent emojis")
|
||||||
color: Style.current.darkGrey
|
color: Style.current.darkGrey
|
||||||
|
@ -32,17 +39,35 @@ Item {
|
||||||
anchors.topMargin: Style.current.smallPadding
|
anchors.topMargin: Style.current.smallPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSearchStringLowercaseChanged: {
|
||||||
|
if (emojiSection.searchStringLowercase === "") {
|
||||||
|
this.emojis = this.allEmojis
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.emojis = this.allEmojis.filter(function (emoji) {
|
||||||
|
return emoji.name.includes(emojiSection.searchStringLowercase) ||
|
||||||
|
emoji.shortname.includes(emojiSection.searchStringLowercase) ||
|
||||||
|
emoji.aliases.some(a => a.includes(emojiSection.searchStringLowercase))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
var myEmojis = []
|
||||||
modelData.forEach(function (emoji) {
|
modelData.forEach(function (emoji) {
|
||||||
if (emoji.empty) {
|
if (emoji.empty) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emojiModel.append({filename: emoji.unicode + '.png'})
|
myEmojis.push({
|
||||||
|
filename: emoji.unicode + '.png',
|
||||||
|
name: emoji.name,
|
||||||
|
shortname: emoji.shortname,
|
||||||
|
name: emoji.name,
|
||||||
|
aliases: emoji.aliases
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
// We use two arrays for filtering purposes
|
||||||
|
this.emojis = myEmojis
|
||||||
ListModel {
|
this.allEmojis = myEmojis
|
||||||
id: emojiModel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GridView {
|
GridView {
|
||||||
|
@ -54,12 +79,13 @@ Item {
|
||||||
visible: count > 0
|
visible: count > 0
|
||||||
cellWidth: emojiSection.imageWidth + emojiSection.imageMargin * 2
|
cellWidth: emojiSection.imageWidth + emojiSection.imageMargin * 2
|
||||||
cellHeight: emojiSection.imageWidth + emojiSection.imageMargin * 2
|
cellHeight: emojiSection.imageWidth + emojiSection.imageMargin * 2
|
||||||
model: emojiModel
|
model: emojiSection.emojis
|
||||||
focus: true
|
focus: true
|
||||||
clip: true
|
clip: true
|
||||||
interactive: false
|
interactive: false
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
|
id: emojiContainer
|
||||||
width: emojiGrid.cellWidth
|
width: emojiGrid.cellWidth
|
||||||
height: emojiGrid.cellHeight
|
height: emojiGrid.cellHeight
|
||||||
|
|
||||||
|
@ -71,14 +97,14 @@ Item {
|
||||||
SVGImage {
|
SVGImage {
|
||||||
width: emojiSection.imageWidth
|
width: emojiSection.imageWidth
|
||||||
height: emojiSection.imageWidth
|
height: emojiSection.imageWidth
|
||||||
source: "../../../../imports/twemoji/26x26/" + filename
|
source: "../../../../imports/twemoji/26x26/" + modelData.filename
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
const extenstionIndex = filename.lastIndexOf('.');
|
const extenstionIndex = modelData.filename.lastIndexOf('.');
|
||||||
let iconCodePoint = filename
|
let iconCodePoint = modelData.filename
|
||||||
if (extenstionIndex > -1) {
|
if (extenstionIndex > -1) {
|
||||||
iconCodePoint = iconCodePoint.substring(0, extenstionIndex)
|
iconCodePoint = iconCodePoint.substring(0, extenstionIndex)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue