2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2023-01-02 06:25:33 +03:00
|
|
|
// SPDX-FileCopyrightText: 2023 Nheko Contributors
|
2021-03-07 07:57:56 +03:00
|
|
|
//
|
2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-10-08 22:11:21 +03:00
|
|
|
import "../"
|
|
|
|
import QtGraphicalEffects 1.0
|
2021-01-12 17:03:39 +03:00
|
|
|
import QtQuick 2.9
|
2020-06-17 22:34:02 +03:00
|
|
|
import QtQuick.Controls 2.3
|
2021-01-12 17:03:39 +03:00
|
|
|
import QtQuick.Layouts 1.3
|
2021-12-13 21:09:03 +03:00
|
|
|
import QtQuick.Window 2.15
|
2020-05-13 07:35:26 +03:00
|
|
|
import im.nheko 1.0
|
|
|
|
import im.nheko.EmojiModel 1.0
|
|
|
|
|
2021-03-23 20:05:43 +03:00
|
|
|
Menu {
|
2020-10-08 22:11:21 +03:00
|
|
|
id: emojiPopup
|
2020-07-20 01:42:48 +03:00
|
|
|
|
2020-11-16 20:41:29 +03:00
|
|
|
property var callback
|
2020-05-13 07:35:26 +03:00
|
|
|
property var colors
|
|
|
|
property alias model: gridView.model
|
|
|
|
property var textArea
|
|
|
|
property string emojiCategory: "people"
|
2021-05-13 09:23:56 +03:00
|
|
|
property real highlightHue: Nheko.colors.highlight.hslHue
|
|
|
|
property real highlightSat: Nheko.colors.highlight.hslSaturation
|
|
|
|
property real highlightLight: Nheko.colors.highlight.hslLightness
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2020-11-16 20:41:29 +03:00
|
|
|
function show(showAt, callback) {
|
|
|
|
console.debug("Showing emojiPicker");
|
|
|
|
emojiPopup.callback = callback;
|
2021-03-23 20:05:43 +03:00
|
|
|
popup(showAt ? showAt : null);
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2023-01-12 22:04:22 +03:00
|
|
|
margins: 2
|
|
|
|
bottomPadding: 0
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
|
|
|
topPadding: 0
|
2020-05-13 07:35:26 +03:00
|
|
|
modal: true
|
|
|
|
focus: true
|
2020-05-14 03:19:15 +03:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
2021-07-03 23:45:36 +03:00
|
|
|
//height: columnView.implicitHeight + 4
|
|
|
|
//width: columnView.implicitWidth
|
|
|
|
width: 7 * 52 + 20
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
color: Nheko.colors.window
|
2023-01-12 22:04:22 +03:00
|
|
|
height: columnView.implicitHeight + Nheko.paddingSmall*2
|
2021-07-03 23:45:36 +03:00
|
|
|
width: 7 * 52 + 20
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: columnView
|
|
|
|
|
2023-01-12 22:04:22 +03:00
|
|
|
spacing: Nheko.paddingSmall
|
|
|
|
anchors.leftMargin: Nheko.paddingSmall
|
|
|
|
anchors.rightMargin: Nheko.paddingSmall
|
2021-07-03 23:45:36 +03:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
// Search field
|
|
|
|
TextField {
|
|
|
|
id: emojiSearch
|
|
|
|
|
2023-01-12 22:04:22 +03:00
|
|
|
Layout.preferredWidth: 7 * 52 + 20 - Nheko.paddingSmall
|
2021-07-03 23:45:36 +03:00
|
|
|
palette: Nheko.colors
|
|
|
|
background: null
|
|
|
|
placeholderTextColor: Nheko.colors.buttonText
|
|
|
|
color: Nheko.colors.text
|
|
|
|
placeholderText: qsTr("Search")
|
|
|
|
selectByMouse: true
|
|
|
|
rightPadding: clearSearch.width
|
|
|
|
onTextChanged: searchTimer.restart()
|
|
|
|
onVisibleChanged: {
|
|
|
|
if (visible)
|
2023-01-12 22:04:22 +03:00
|
|
|
forceActiveFocus();
|
2021-08-19 16:39:35 +03:00
|
|
|
else
|
2023-01-12 22:04:22 +03:00
|
|
|
clear();
|
2021-07-03 23:45:36 +03:00
|
|
|
}
|
2021-04-18 21:21:03 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
Timer {
|
|
|
|
id: searchTimer
|
2021-04-18 21:21:03 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
interval: 350 // tweak as needed?
|
|
|
|
onTriggered: {
|
|
|
|
emojiPopup.model.searchString = emojiSearch.text;
|
|
|
|
emojiPopup.model.category = Emoji.Category.Search;
|
|
|
|
}
|
2021-04-18 21:21:03 +03:00
|
|
|
}
|
|
|
|
|
2023-01-12 22:04:22 +03:00
|
|
|
ImageButton {
|
2021-07-03 23:45:36 +03:00
|
|
|
id: clearSearch
|
2021-04-18 21:21:03 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
visible: emojiSearch.text !== ''
|
2023-01-12 22:04:22 +03:00
|
|
|
|
|
|
|
image: ":/icons/icons/ui/round-remove-button.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
onClicked: emojiSearch.clear()
|
|
|
|
hoverEnabled: true
|
|
|
|
anchors {
|
2023-01-12 22:04:22 +03:00
|
|
|
top: parent.top
|
|
|
|
bottom: parent.bottom
|
2021-07-03 23:45:36 +03:00
|
|
|
right: parent.right
|
2023-01-12 22:04:22 +03:00
|
|
|
rightMargin: Nheko.paddingSmall
|
2021-07-03 23:45:36 +03:00
|
|
|
}
|
2021-04-18 21:21:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
// emoji grid
|
|
|
|
GridView {
|
|
|
|
id: gridView
|
2021-04-18 21:21:03 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
Layout.preferredHeight: cellHeight * 5
|
|
|
|
Layout.preferredWidth: 7 * 52 + 20
|
|
|
|
cellWidth: 52
|
|
|
|
cellHeight: 52
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
clip: true
|
|
|
|
currentIndex: -1 // prevent sorting from stealing focus
|
2021-07-15 18:56:32 +03:00
|
|
|
cacheBuffer: 500
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2022-01-27 03:14:18 +03:00
|
|
|
ScrollHelper {
|
|
|
|
flickable: parent
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: !Settings.mobileMode
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
// Individual emoji
|
|
|
|
delegate: AbstractButton {
|
|
|
|
width: 48
|
|
|
|
height: 48
|
|
|
|
hoverEnabled: true
|
2022-04-23 23:37:44 +03:00
|
|
|
ToolTip.text: model.toolTip
|
2021-07-03 23:45:36 +03:00
|
|
|
ToolTip.visible: hovered
|
|
|
|
// TODO: maybe add favorites at some point?
|
|
|
|
onClicked: {
|
|
|
|
console.debug("Picked " + model.unicode);
|
|
|
|
emojiPopup.close();
|
|
|
|
callback(model.unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// give the emoji a little oomf
|
2022-01-27 03:14:18 +03:00
|
|
|
// DropShadow {
|
|
|
|
// width: parent.width
|
|
|
|
// height: parent.height
|
|
|
|
// horizontalOffset: 3
|
|
|
|
// verticalOffset: 3
|
|
|
|
// radius: 8
|
|
|
|
// samples: 17
|
|
|
|
// color: "#80000000"
|
|
|
|
// source: parent.contentItem
|
|
|
|
// }
|
2021-07-03 23:45:36 +03:00
|
|
|
|
|
|
|
contentItem: Text {
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
font.family: Settings.emojiFont
|
|
|
|
font.pixelSize: 36
|
2022-01-01 08:37:15 +03:00
|
|
|
text: model.unicode.replace('\ufe0f', '')
|
2021-07-03 23:45:36 +03:00
|
|
|
color: Nheko.colors.text
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
color: hovered ? Nheko.colors.highlight : 'transparent'
|
|
|
|
radius: 5
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
|
|
id: emojiScroll
|
2020-05-13 07:35:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
// Separator
|
|
|
|
Rectangle {
|
|
|
|
visible: emojiSearch.text === ''
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 1
|
|
|
|
color: emojiPopup.Nheko.theme.separator
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
// Category picker row
|
|
|
|
RowLayout {
|
|
|
|
visible: emojiSearch.text === ''
|
|
|
|
Layout.bottomMargin: 0
|
|
|
|
Layout.preferredHeight: 42
|
|
|
|
implicitHeight: 42
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
|
|
|
|
|
|
// Display the normal categories
|
|
|
|
Repeater {
|
|
|
|
|
|
|
|
model: ListModel {
|
|
|
|
// TODO: Would like to get 'simple' icons for the categories
|
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/people.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.People
|
|
|
|
}
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/nature.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Nature
|
|
|
|
}
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/foods.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Food
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/activity.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Activity
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/travel.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Travel
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/objects.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Objects
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/symbols.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Symbols
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
ListElement {
|
2021-11-14 04:23:10 +03:00
|
|
|
image: ":/icons/icons/emoji-categories/flags.svg"
|
2021-07-03 23:45:36 +03:00
|
|
|
category: Emoji.Category.Flags
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
delegate: AbstractButton {
|
|
|
|
Layout.preferredWidth: 36
|
|
|
|
Layout.preferredHeight: 36
|
|
|
|
hoverEnabled: true
|
2022-06-30 06:39:19 +03:00
|
|
|
leftPadding: 2
|
|
|
|
rightPadding: 2
|
|
|
|
topPadding: 2
|
|
|
|
bottomPadding: 2
|
2021-07-03 23:45:36 +03:00
|
|
|
ToolTip.text: {
|
|
|
|
switch (model.category) {
|
|
|
|
case Emoji.Category.People:
|
|
|
|
return qsTr('People');
|
|
|
|
case Emoji.Category.Nature:
|
|
|
|
return qsTr('Nature');
|
|
|
|
case Emoji.Category.Food:
|
|
|
|
return qsTr('Food');
|
|
|
|
case Emoji.Category.Activity:
|
|
|
|
return qsTr('Activity');
|
|
|
|
case Emoji.Category.Travel:
|
|
|
|
return qsTr('Travel');
|
|
|
|
case Emoji.Category.Objects:
|
|
|
|
return qsTr('Objects');
|
|
|
|
case Emoji.Category.Symbols:
|
|
|
|
return qsTr('Symbols');
|
|
|
|
case Emoji.Category.Flags:
|
|
|
|
return qsTr('Flags');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolTip.visible: hovered
|
|
|
|
onClicked: {
|
|
|
|
//emojiPopup.model.category = model.category;
|
|
|
|
gridView.positionViewAtIndex(emojiPopup.model.sourceModel.categoryToIndex(model.category), GridView.Beginning);
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
onPressed: mouse.accepted = false
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
contentItem: Image {
|
|
|
|
horizontalAlignment: Image.AlignHCenter
|
|
|
|
verticalAlignment: Image.AlignVCenter
|
2022-01-03 00:13:15 +03:00
|
|
|
smooth: true
|
|
|
|
mipmap: true
|
2023-01-12 09:34:17 +03:00
|
|
|
sourceSize.width: 32
|
|
|
|
sourceSize.height: 32
|
2021-07-03 23:45:36 +03:00
|
|
|
source: "image://colorimage/" + model.image + "?" + (hovered ? Nheko.colors.highlight : Nheko.colors.buttonText)
|
|
|
|
}
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2021-07-03 23:45:36 +03:00
|
|
|
background: Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
color: emojiPopup.model.category === model.category ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.2) : 'transparent'
|
|
|
|
radius: 5
|
|
|
|
border.color: emojiPopup.model.category === model.category ? Nheko.colors.highlight : 'transparent'
|
|
|
|
}
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:19:15 +03:00
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2020-05-14 03:19:15 +03:00
|
|
|
}
|
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
}
|