matrixion/resources/qml/emoji/StickerPicker.qml

266 lines
9.8 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
2021-07-15 21:37:52 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"
2023-06-02 01:43:38 +03:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import im.nheko
import im.nheko.EmojiModel
2021-07-15 21:37:52 +03:00
Menu {
id: stickerPopup
property var callback
2021-07-19 18:45:55 +03:00
property string roomid
2021-07-19 18:49:57 +03:00
property alias model: gridView.model
2023-05-25 20:07:13 +03:00
required property bool emoji
2021-07-15 21:37:52 +03:00
property var textArea
property real highlightHue: palette.highlight.hslHue
property real highlightSat: palette.highlight.hslSaturation
property real highlightLight: palette.highlight.hslLightness
2023-05-25 20:07:13 +03:00
readonly property int stickerDim: emoji ? 48 : 128
readonly property int stickerDimPad: stickerDim + Nheko.paddingSmall
readonly property int stickersPerRow: emoji ? 7 : 3
readonly property int sidebarAvatarSize: 24
2021-07-15 21:37:52 +03:00
2021-07-19 18:45:55 +03:00
function show(showAt, roomid_, callback) {
2021-07-15 21:37:52 +03:00
console.debug("Showing sticker picker");
2021-07-19 18:45:55 +03:00
roomid = roomid_;
2021-07-15 21:37:52 +03:00
stickerPopup.callback = callback;
popup(showAt ? showAt : null);
}
2023-01-12 23:41:08 +03:00
margins: 2
bottomPadding: 0
leftPadding: 0
rightPadding: 0
topPadding: 0
2021-07-15 21:37:52 +03:00
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
width: sidebarAvatarSize + Nheko.paddingSmall + stickersPerRow * stickerDimPad + 20
2021-07-15 21:37:52 +03:00
Rectangle {
color: palette.window
2023-01-12 23:41:08 +03:00
height: columnView.implicitHeight + Nheko.paddingSmall*2
width: sidebarAvatarSize + Nheko.paddingSmall + stickersPerRow * stickerDimPad + 20
2021-07-15 21:37:52 +03:00
GridLayout {
2021-07-15 21:37:52 +03:00
id: columnView
2023-01-12 23:41:08 +03:00
anchors.leftMargin: Nheko.paddingSmall
anchors.rightMargin: Nheko.paddingSmall
2021-07-15 21:37:52 +03:00
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
columns: 2
rows: 2
2021-07-15 21:37:52 +03:00
// Search field
TextField {
id: emojiSearch
2023-01-12 23:41:08 +03:00
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall
Layout.row: 0
Layout.column: 1
2021-07-15 21:37:52 +03:00
background: null
placeholderTextColor: palette.buttonText
2021-07-15 21:37:52 +03:00
placeholderText: qsTr("Search")
selectByMouse: true
rightPadding: clearSearch.width
onTextChanged: searchTimer.restart()
onVisibleChanged: {
if (visible)
forceActiveFocus();
else
clear();
2021-07-15 21:37:52 +03:00
}
Timer {
id: searchTimer
interval: 350 // tweak as needed?
onTriggered: stickerPopup.model.searchString = emojiSearch.text
}
2023-01-12 23:41:08 +03:00
ImageButton {
2021-07-15 21:37:52 +03:00
id: clearSearch
visible: emojiSearch.text !== ''
2023-01-12 23:41:08 +03:00
image: ":/icons/icons/ui/round-remove-button.svg"
2021-07-15 21:37:52 +03:00
focusPolicy: Qt.NoFocus
onClicked: emojiSearch.clear()
hoverEnabled: true
anchors {
2023-01-12 23:41:08 +03:00
top: parent.top
bottom: parent.bottom
2021-07-15 21:37:52 +03:00
right: parent.right
2023-01-12 23:41:08 +03:00
rightMargin: Nheko.paddingSmall
2021-07-15 21:37:52 +03:00
}
}
}
2023-05-19 04:15:55 +03:00
// sticker grid
ListView {
2021-07-15 21:37:52 +03:00
id: gridView
2023-05-25 20:07:13 +03:00
model: roomid ? TimelineManager.completerFor(stickerPopup.emoji ? "emojigrid" : "stickergrid", roomid) : null
Layout.row: 1
Layout.column: 1
2023-05-25 20:07:13 +03:00
Layout.preferredHeight: cellHeight * (stickersPerRow + 0.5)
2023-01-12 23:41:08 +03:00
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall
2023-05-19 04:15:55 +03:00
property int cellHeight: stickerDimPad
2021-07-15 21:37:52 +03:00
boundsBehavior: Flickable.StopAtBounds
clip: true
currentIndex: -1 // prevent sorting from stealing focus
2023-05-19 04:15:55 +03:00
section.property: "packname"
section.criteria: ViewSection.FullString
section.delegate: Rectangle {
width: gridView.width
height: childrenRect.height
color: palette.alternateBase
required property string section
Text {
anchors.left: parent.left
anchors.right: parent.right
text: parent.section
font.bold: true
}
}
2023-05-19 04:15:55 +03:00
section.labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
2021-07-15 21:37:52 +03:00
spacing: Nheko.paddingSmall
2021-07-15 21:37:52 +03:00
// Individual emoji
2023-05-19 04:15:55 +03:00
delegate: Row {
required property var row;
spacing: Nheko.paddingSmall
2023-05-19 04:15:55 +03:00
Repeater {
model: row
delegate: AbstractButton {
2023-05-25 20:07:13 +03:00
id: del
required property var modelData
width: stickerDim
height: stickerDim
hoverEnabled: true
2023-05-26 00:26:39 +03:00
ToolTip.text: ":" + modelData.shortcode + ": - " + (modelData.unicode ? modelData.unicodeName : modelData.body)
ToolTip.visible: hovered
// TODO: maybe add favorites at some point?
onClicked: {
2023-05-25 20:07:13 +03:00
console.debug("Picked " + modelData);
stickerPopup.close();
2023-05-25 20:07:13 +03:00
if (!stickerPopup.emoji) {
// return descriptor to calculate sticker to send
callback(modelData.descriptor);
} else if (modelData.unicode) {
// return the emoji unicode as both plain text and markdown
callback(modelData.unicode, modelData.unicode);
} else {
// return the emoji url as plain text and a markdown link as markdown
callback(modelData.url, modelData.markdown);
}
}
2023-05-25 20:07:13 +03:00
contentItem: DelegateChooser {
roleValue: del.modelData.unicode != undefined
DelegateChoice {
roleValue: true
Text {
width: stickerDim
height: stickerDim
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.family: Settings.emojiFont
font.pixelSize: 36
text: del.modelData.unicode.replace('\ufe0f', '')
}
}
DelegateChoice {
roleValue: false
Image {
height: stickerDim
width: stickerDim
source: del.modelData.url.replace("mxc://", "image://MxcImage/") + "?scale"
fillMode: Image.PreserveAspectFit
}
}
}
background: Rectangle {
anchors.fill: parent
color: hovered ? palette.highlight : 'transparent'
radius: 5
}
}
2021-07-15 21:37:52 +03:00
}
}
ScrollBar.vertical: ScrollBar {
id: emojiScroll
}
}
ListView {
Layout.row: 1
Layout.column: 0
Layout.preferredWidth: sidebarAvatarSize
Layout.fillHeight: true
Layout.rightMargin: Nheko.paddingSmall
model: gridView.model ? gridView.model.sections : null
spacing: Nheko.paddingSmall
clip: true
delegate: Avatar {
height: sidebarAvatarSize
width: sidebarAvatarSize
url: modelData.url.replace("mxc://", "image://MxcImage/")
2023-06-08 03:08:40 +03:00
textColor: modelData.url.startsWith("mxc://") ? palette.text : palette.buttonText
displayName: modelData.name
roomid: modelData.name
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: modelData.name
onClicked: gridView.positionViewAtIndex(modelData.firstRowWith, ListView.Beginning)
}
}
ImageButton {
Layout.row: 0
Layout.column: 0
Layout.preferredWidth: sidebarAvatarSize
Layout.preferredHeight: sidebarAvatarSize
Layout.rightMargin: Nheko.paddingSmall
image: ":/icons/icons/ui/settings.svg"
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: qsTr("Change what packs are enabled, remove packs, or create new ones")
onClicked: TimelineManager.openImagePackSettings(stickerPopup.roomid)
}
2021-07-15 21:37:52 +03:00
}
}
}