nheko/resources/qml/emoji/StickerPicker.qml

167 lines
5.3 KiB
QML
Raw Normal View History

2021-07-15 20:37:52 +02:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
// SPDX-FileCopyrightText: 2023 Nheko Contributors
2021-07-15 20:37:52 +02:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"
import QtGraphicalEffects 1.0
import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import im.nheko 1.0
import im.nheko.EmojiModel 1.0
Menu {
id: stickerPopup
property var callback
property var colors
2021-07-19 17:45:55 +02:00
property string roomid
2021-07-19 17:49:57 +02:00
property alias model: gridView.model
2021-07-15 20:37:52 +02:00
property var textArea
property real highlightHue: Nheko.colors.highlight.hslHue
property real highlightSat: Nheko.colors.highlight.hslSaturation
property real highlightLight: Nheko.colors.highlight.hslLightness
readonly property int stickerDim: 128
readonly property int stickerDimPad: 128 + Nheko.paddingSmall
readonly property int stickersPerRow: 3
2021-07-19 17:45:55 +02:00
function show(showAt, roomid_, callback) {
2021-07-15 20:37:52 +02:00
console.debug("Showing sticker picker");
2021-07-19 17:45:55 +02:00
roomid = roomid_;
2021-07-15 20:37:52 +02:00
stickerPopup.callback = callback;
popup(showAt ? showAt : null);
}
2023-01-12 21:41:08 +01:00
margins: 2
bottomPadding: 0
leftPadding: 0
rightPadding: 0
topPadding: 0
2021-07-15 20:37:52 +02:00
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
width: stickersPerRow * stickerDimPad + 20
Rectangle {
color: Nheko.colors.window
2023-01-12 21:41:08 +01:00
height: columnView.implicitHeight + Nheko.paddingSmall*2
2021-07-15 20:37:52 +02:00
width: stickersPerRow * stickerDimPad + 20
ColumnLayout {
id: columnView
2023-01-12 21:41:08 +01:00
spacing: Nheko.paddingSmall
anchors.leftMargin: Nheko.paddingSmall
anchors.rightMargin: Nheko.paddingSmall
2021-07-15 20:37:52 +02:00
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
// Search field
TextField {
id: emojiSearch
2023-01-12 21:41:08 +01:00
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall
2021-07-15 20:37:52 +02: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)
forceActiveFocus();
else
clear();
2021-07-15 20:37:52 +02:00
}
Timer {
id: searchTimer
interval: 350 // tweak as needed?
onTriggered: stickerPopup.model.searchString = emojiSearch.text
}
2023-01-12 21:41:08 +01:00
ImageButton {
2021-07-15 20:37:52 +02:00
id: clearSearch
visible: emojiSearch.text !== ''
2023-01-12 21:41:08 +01:00
image: ":/icons/icons/ui/round-remove-button.svg"
2021-07-15 20:37:52 +02:00
focusPolicy: Qt.NoFocus
onClicked: emojiSearch.clear()
hoverEnabled: true
anchors {
2023-01-12 21:41:08 +01:00
top: parent.top
bottom: parent.bottom
2021-07-15 20:37:52 +02:00
right: parent.right
2023-01-12 21:41:08 +01:00
rightMargin: Nheko.paddingSmall
2021-07-15 20:37:52 +02:00
}
}
}
// emoji grid
GridView {
id: gridView
2021-07-19 17:45:55 +02:00
model: roomid ? TimelineManager.completerFor("stickers", roomid) : null
2021-07-15 20:37:52 +02:00
Layout.preferredHeight: cellHeight * 3.5
2023-01-12 21:41:08 +01:00
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall
2021-07-15 20:37:52 +02:00
cellWidth: stickerDimPad
cellHeight: stickerDimPad
boundsBehavior: Flickable.StopAtBounds
clip: true
currentIndex: -1 // prevent sorting from stealing focus
cacheBuffer: 500
2021-07-19 14:57:10 +02:00
ScrollHelper {
flickable: parent
anchors.fill: parent
enabled: !Settings.mobileMode
}
2021-07-15 20:37:52 +02:00
// Individual emoji
delegate: AbstractButton {
width: stickerDim
height: stickerDim
hoverEnabled: true
ToolTip.text: ":" + model.shortcode + ": - " + model.body
ToolTip.visible: hovered
// TODO: maybe add favorites at some point?
onClicked: {
console.debug("Picked " + model.shortcode);
stickerPopup.close();
callback(model.originalRow);
}
contentItem: Image {
height: stickerDim
width: stickerDim
source: model.url.replace("mxc://", "image://MxcImage/") + "?scale"
2021-07-15 20:37:52 +02:00
fillMode: Image.PreserveAspectFit
}
background: Rectangle {
anchors.fill: parent
color: hovered ? Nheko.colors.highlight : 'transparent'
radius: 5
}
}
ScrollBar.vertical: ScrollBar {
id: emojiScroll
}
}
}
}
}