matrixion/resources/qml/emoji/StickerPicker.qml

177 lines
5.8 KiB
QML
Raw Normal View History

2021-07-15 21:37:52 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-07-15 21:37:52 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "../"
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 18:45:55 +03:00
property string roomid
2021-07-19 18:49:57 +03:00
property alias model: gridView.model
2021-07-15 21:37:52 +03:00
property var textArea
2022-04-11 05:18:16 +03:00
property real highlightHue: timelineRoot.palette.highlight.hslHue
property real highlightSat: timelineRoot.palette.highlight.hslSaturation
property real highlightLight: timelineRoot.palette.highlight.hslLightness
2021-07-15 21:37:52 +03:00
readonly property int stickerDim: 128
readonly property int stickerDimPad: 128 + Nheko.paddingSmall
readonly property int stickersPerRow: 3
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);
}
margins: 0
bottomPadding: 1
leftPadding: 1
rightPadding: 1
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
width: stickersPerRow * stickerDimPad + 20
Rectangle {
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.window
2021-07-15 21:37:52 +03:00
height: columnView.implicitHeight + 4
width: stickersPerRow * stickerDimPad + 20
ColumnLayout {
id: columnView
spacing: 0
anchors.leftMargin: 3
anchors.rightMargin: 3
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 2
// Search field
TextField {
id: emojiSearch
Layout.topMargin: 3
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - 6
2022-04-11 05:18:16 +03:00
palette: timelineRoot.palette
2021-07-15 21:37:52 +03:00
background: null
2022-04-11 05:18:16 +03:00
placeholderTextColor: timelineRoot.palette.buttonText
color: timelineRoot.palette.text
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
}
ToolButton {
id: clearSearch
visible: emojiSearch.text !== ''
2022-04-11 05:18:16 +03:00
icon.source: "image://colorimage/:/icons/icons/ui/round-remove-button.svg?" + (clearSearch.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.buttonText)
2021-07-15 21:37:52 +03:00
focusPolicy: Qt.NoFocus
onClicked: emojiSearch.clear()
hoverEnabled: true
background: null
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
}
// clear the default hover effects.
Image {
height: parent.height - 2 * Nheko.paddingSmall
width: height
2022-04-11 05:18:16 +03:00
source: "image://colorimage/:/icons/icons/ui/round-remove-button.svg?" + (clearSearch.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.buttonText)
2021-07-15 21:37:52 +03:00
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
margins: Nheko.paddingSmall
}
}
}
}
// emoji grid
GridView {
id: gridView
2021-07-19 18:45:55 +03:00
model: roomid ? TimelineManager.completerFor("stickers", roomid) : null
2021-07-15 21:37:52 +03:00
Layout.preferredHeight: cellHeight * 3.5
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20
Layout.leftMargin: 4
cellWidth: stickerDimPad
cellHeight: stickerDimPad
boundsBehavior: Flickable.StopAtBounds
clip: true
currentIndex: -1 // prevent sorting from stealing focus
cacheBuffer: 500
2021-07-19 15:57:10 +03:00
2021-07-15 21:37:52 +03: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 21:37:52 +03:00
fillMode: Image.PreserveAspectFit
}
background: Rectangle {
anchors.fill: parent
2022-04-11 05:18:16 +03:00
color: hovered ? timelineRoot.palette.highlight : 'transparent'
2021-07-15 21:37:52 +03:00
radius: 5
}
}
ScrollBar.vertical: ScrollBar {
id: emojiScroll
}
}
}
}
}