Warning, /network/tokodon/src/content/ui/Components/Emoji/EmojiGrid.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls 2 as QQC2
0006 import org.kde.kirigami 2 as Kirigami
0007 import org.kde.tokodon
0008 
0009 QQC2.ScrollView {
0010     id: emojiGrid
0011 
0012     property alias model: emojis.model
0013     property alias count: emojis.count
0014     required property int targetIconSize
0015     readonly property int emojisPerRow: emojis.width / targetIconSize
0016     required property bool withCustom
0017     readonly property var searchCategory: EmojiModel.Search
0018     required property QtObject header
0019 
0020     signal chosen(string unicode)
0021 
0022     onActiveFocusChanged: if (activeFocus) {
0023         emojis.forceActiveFocus()
0024     }
0025 
0026     GridView {
0027         id: emojis
0028 
0029         anchors.fill: parent
0030         anchors.rightMargin: parent.QQC2.ScrollBar.vertical.visible ? parent.QQC2.ScrollBar.vertical.width : 0
0031 
0032         currentIndex: -1
0033         keyNavigationEnabled: true
0034         onActiveFocusChanged: if (activeFocus && currentIndex === -1) {
0035             currentIndex = 0
0036         } else {
0037             currentIndex = -1
0038         }
0039         onModelChanged: currentIndex = -1
0040 
0041         cellWidth: emojis.width / emojiGrid.emojisPerRow
0042         cellHeight: emojiGrid.targetIconSize
0043 
0044         KeyNavigation.up: emojiGrid.header
0045 
0046         clip: true
0047 
0048         delegate: EmojiDelegate {
0049             id: emojiDelegate
0050             checked: emojis.currentIndex === model.index
0051             emoji: modelData.unicode
0052             name: modelData.shortName
0053 
0054             width: emojis.cellWidth
0055             height: emojis.cellHeight
0056 
0057             isImage: modelData.isCustom
0058             Keys.onEnterPressed: clicked()
0059             Keys.onReturnPressed: clicked()
0060             onClicked: {
0061                 emojiGrid.chosen(modelData.isCustom ? (":" + modelData.shortName + ":") : modelData.unicode)
0062                 EmojiModel.emojiUsed(AccountManager.selectedAccount, name)
0063             }
0064             Keys.onSpacePressed: pressAndHold()
0065             onPressAndHold: {
0066                 if (EmojiModel.tones(modelData.shortName).length === 0) {
0067                     return;
0068                 }
0069                 let tones = tonesPopupComponent.createObject(emojiDelegate, {shortName: modelData.shortName, unicode: modelData.unicode, categoryIconSize: emojiGrid.targetIconSize})
0070                 tones.open()
0071                 tones.forceActiveFocus()
0072             }
0073             showTones: !!modelData && EmojiModel.tones(modelData.shortName).length > 0
0074         }
0075 
0076         Kirigami.PlaceholderMessage {
0077             anchors.centerIn: parent
0078             text: i18n("No emojis")
0079             visible: emojis.count === 0
0080         }
0081     }
0082     Component {
0083         id: tonesPopupComponent
0084         EmojiTonesPicker {
0085             onChosen: emojiGrid.chosen(emoji)
0086         }
0087     }
0088 }