// SPDX-FileCopyrightText: 2022 Tobias Fella // SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-2.0-or-later // // Adapted from NeoChat's src/chatbar/EmojiGrid.qml. // // Upstream's copyright line carries no address; it is reproduced as it stands. // // the sticker branch and the custom-emoji branch are gone - neither has anything // behind it here - so the grid is only ever emoji and only ever emits chosen(). import QtQuick import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami import koutnet.app QQC2.ScrollView { id: root property alias model: emojis.model property alias count: emojis.count // where the grid was left scrolled to, so that a category put away and // brought back is where it was rather than at its top again property alias contentY: emojis.contentY required property int targetIconSize // the room around every emoji, which is what upstream's // stickersEmojiPickerItemSkip is between its item and the next property int cellSkip: 0 required property Item header signal chosen(string unicode) onActiveFocusChanged: if (activeFocus) { emojis.forceActiveFocus(); } GridView { id: emojis anchors.fill: parent anchors.rightMargin: parent.QQC2.ScrollBar.vertical.visible ? parent.QQC2.ScrollBar.vertical.width : 0 currentIndex: -1 keyNavigationEnabled: true onActiveFocusChanged: if (activeFocus && currentIndex === -1) { currentIndex = 0; } else { currentIndex = -1; } onModelChanged: currentIndex = -1 // the skip is between the cells rather than around them, so the last // column of a row ends at the edge of the grid cellWidth: root.targetIconSize + root.cellSkip cellHeight: root.targetIconSize + root.cellSkip KeyNavigation.up: root.header clip: true delegate: EmojiDelegate { id: emojiDelegate checked: emojis.currentIndex === model.index emoji: modelData.unicode name: modelData.shortName description: modelData.description width: root.targetIconSize height: root.targetIconSize Keys.onEnterPressed: clicked() Keys.onReturnPressed: clicked() onClicked: { root.chosen(modelData.unicode); EmojiModel.emojiUsed(modelData.shortName); } Keys.onSpacePressed: pressAndHold() onPressAndHold: { if (EmojiModel.tones(modelData.shortName).length === 0) { return; } let tones = tonesPopupComponent.createObject(emojiDelegate, { shortName: modelData.shortName, unicode: modelData.unicode, categoryIconSize: root.targetIconSize }) as EmojiTonesPicker; tones.open(); tones.forceActiveFocus(); } showTones: !!modelData && EmojiModel.tones(modelData.shortName).length > 0 } Kirigami.PlaceholderMessage { anchors.centerIn: parent icon.name: "preferences-desktop-emoticons" text: i18nc("@info shown when a search matches no emoji", "No emojis") visible: emojis.count === 0 } } Component { id: tonesPopupComponent EmojiTonesPicker { onChosen: emoji => root.chosen(emoji) } } }