| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "../" |
| 6 |
import QtQuick |
| 7 |
import QtQuick.Controls |
| 8 |
import QtQuick.Layouts |
| 9 |
import im.nheko |
| 10 |
|
| 11 |
Menu { |
| 12 |
id: stickerPopup |
| 13 |
|
| 14 |
property var callback |
| 15 |
property string roomid |
| 16 |
property alias model: gridView.model |
| 17 |
required property bool emoji |
| 18 |
property var textArea |
| 19 |
property real highlightHue: palette.highlight.hslHue |
| 20 |
property real highlightSat: palette.highlight.hslSaturation |
| 21 |
property real highlightLight: palette.highlight.hslLightness |
| 22 |
readonly property int stickerDim: emoji ? 48 : 128 |
| 23 |
readonly property int stickerDimPad: stickerDim + Nheko.paddingSmall |
| 24 |
readonly property int stickersPerRow: emoji ? 7 : 3 |
| 25 |
readonly property int sidebarAvatarSize: 24 |
| 26 |
|
| 27 |
function show(showAt, roomid_, callback) { |
| 28 |
console.debug("Showing sticker picker"); |
| 29 |
roomid = roomid_; |
| 30 |
stickerPopup.callback = callback; |
| 31 |
popup(showAt ? showAt : null); |
| 32 |
} |
| 33 |
|
| 34 |
margins: 2 |
| 35 |
bottomPadding: 0 |
| 36 |
leftPadding: 0 |
| 37 |
rightPadding: 0 |
| 38 |
topPadding: 0 |
| 39 |
modal: true |
| 40 |
focus: true |
| 41 |
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside |
| 42 |
width: sidebarAvatarSize + Nheko.paddingSmall + stickersPerRow * stickerDimPad + 20 |
| 43 |
|
| 44 |
Rectangle { |
| 45 |
color: palette.window |
| 46 |
height: columnView.implicitHeight + Nheko.paddingSmall*2 |
| 47 |
width: sidebarAvatarSize + Nheko.paddingSmall + stickersPerRow * stickerDimPad + 20 |
| 48 |
|
| 49 |
GridLayout { |
| 50 |
id: columnView |
| 51 |
|
| 52 |
anchors.leftMargin: Nheko.paddingSmall |
| 53 |
anchors.rightMargin: Nheko.paddingSmall |
| 54 |
anchors.bottom: parent.bottom |
| 55 |
anchors.left: parent.left |
| 56 |
anchors.right: parent.right |
| 57 |
columns: 2 |
| 58 |
rows: 2 |
| 59 |
|
| 60 |
// Search field |
| 61 |
TextField { |
| 62 |
id: emojiSearch |
| 63 |
|
| 64 |
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall |
| 65 |
Layout.row: 0 |
| 66 |
Layout.column: 1 |
| 67 |
background: null |
| 68 |
placeholderTextColor: palette.buttonText |
| 69 |
placeholderText: qsTr("Search") |
| 70 |
selectByMouse: true |
| 71 |
rightPadding: clearSearch.width |
| 72 |
onTextChanged: searchTimer.restart() |
| 73 |
onVisibleChanged: { |
| 74 |
if (visible) |
| 75 |
forceActiveFocus(); |
| 76 |
else |
| 77 |
clear(); |
| 78 |
} |
| 79 |
|
| 80 |
Timer { |
| 81 |
id: searchTimer |
| 82 |
|
| 83 |
interval: 350 // tweak as needed? |
| 84 |
onTriggered: stickerPopup.model.searchString = emojiSearch.text |
| 85 |
} |
| 86 |
|
| 87 |
ImageButton { |
| 88 |
id: clearSearch |
| 89 |
|
| 90 |
visible: emojiSearch.text !== '' |
| 91 |
|
| 92 |
image: ":/icons/icons/ui/round-remove-button.svg" |
| 93 |
focusPolicy: Qt.NoFocus |
| 94 |
onClicked: emojiSearch.clear() |
| 95 |
hoverEnabled: true |
| 96 |
anchors { |
| 97 |
top: parent.top |
| 98 |
bottom: parent.bottom |
| 99 |
right: parent.right |
| 100 |
rightMargin: Nheko.paddingSmall |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
// sticker grid |
| 106 |
ListView { |
| 107 |
id: gridView |
| 108 |
|
| 109 |
model: roomid ? TimelineManager.completerFor(stickerPopup.emoji ? "emojigrid" : "stickergrid", roomid) : null |
| 110 |
Layout.row: 1 |
| 111 |
Layout.column: 1 |
| 112 |
Layout.preferredHeight: cellHeight * (stickersPerRow + 0.5) |
| 113 |
Layout.preferredWidth: stickersPerRow * stickerDimPad + 20 - Nheko.paddingSmall |
| 114 |
property int cellHeight: stickerDimPad |
| 115 |
boundsBehavior: Flickable.StopAtBounds |
| 116 |
clip: true |
| 117 |
currentIndex: -1 // prevent sorting from stealing focus |
| 118 |
|
| 119 |
section.property: "packname" |
| 120 |
section.criteria: ViewSection.FullString |
| 121 |
section.delegate: Rectangle { |
| 122 |
width: gridView.width |
| 123 |
height: childrenRect.height |
| 124 |
color: palette.alternateBase |
| 125 |
|
| 126 |
required property string section |
| 127 |
|
| 128 |
Text { |
| 129 |
anchors.left: parent.left |
| 130 |
anchors.right: parent.right |
| 131 |
text: parent.section |
| 132 |
font.bold: true |
| 133 |
color: palette.text |
| 134 |
} |
| 135 |
} |
| 136 |
section.labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart |
| 137 |
|
| 138 |
spacing: Nheko.paddingSmall |
| 139 |
|
| 140 |
// Individual emoji |
| 141 |
delegate: Row { |
| 142 |
required property var row; |
| 143 |
|
| 144 |
spacing: Nheko.paddingSmall |
| 145 |
|
| 146 |
Repeater { |
| 147 |
model: row |
| 148 |
|
| 149 |
delegate: AbstractButton { |
| 150 |
id: del |
| 151 |
|
| 152 |
required property var modelData |
| 153 |
|
| 154 |
width: stickerDim |
| 155 |
height: stickerDim |
| 156 |
hoverEnabled: true |
| 157 |
ToolTip.text: ":" + modelData.shortcode + ": - " + (modelData.unicode ? modelData.unicodeName : modelData.body) |
| 158 |
ToolTip.visible: hovered |
| 159 |
// TODO: maybe add favorites at some point? |
| 160 |
onClicked: { |
| 161 |
console.debug("Picked " + modelData); |
| 162 |
stickerPopup.close(); |
| 163 |
if (!stickerPopup.emoji) { |
| 164 |
// return descriptor to calculate sticker to send |
| 165 |
callback(modelData.descriptor); |
| 166 |
} else if (modelData.unicode) { |
| 167 |
// return the emoji unicode as both plain text and markdown |
| 168 |
callback(modelData.unicode, modelData.unicode); |
| 169 |
} else { |
| 170 |
// return the emoji url as plain text and a markdown link as markdown |
| 171 |
callback(modelData.url, modelData.markdown); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
contentItem: DelegateChooser { |
| 176 |
roleValue: del.modelData.unicode != undefined |
| 177 |
|
| 178 |
DelegateChoice { |
| 179 |
roleValue: true |
| 180 |
|
| 181 |
Text { |
| 182 |
width: stickerDim |
| 183 |
height: stickerDim |
| 184 |
horizontalAlignment: Text.AlignHCenter |
| 185 |
verticalAlignment: Text.AlignVCenter |
| 186 |
font.family: Settings.emojiFont != "" ? Settings.emojiFont : undefined |
| 187 |
font.pixelSize: 36 |
| 188 |
text: del.modelData.unicode.replace('\ufe0f', '') |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
DelegateChoice { |
| 193 |
roleValue: false |
| 194 |
Image { |
| 195 |
height: stickerDim |
| 196 |
width: stickerDim |
| 197 |
source: del.modelData.url.replace("mxc://", "image://MxcImage/") + "?scale" |
| 198 |
fillMode: Image.PreserveAspectFit |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
background: Rectangle { |
| 204 |
anchors.fill: parent |
| 205 |
color: hovered ? palette.highlight : 'transparent' |
| 206 |
radius: 5 |
| 207 |
} |
| 208 |
|
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
ScrollBar.vertical: ScrollBar { |
| 214 |
id: emojiScroll |
| 215 |
} |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
ListView { |
| 220 |
Layout.row: 1 |
| 221 |
Layout.column: 0 |
| 222 |
Layout.preferredWidth: sidebarAvatarSize |
| 223 |
Layout.fillHeight: true |
| 224 |
Layout.rightMargin: Nheko.paddingSmall |
| 225 |
|
| 226 |
model: gridView.model ? gridView.model.sections : null |
| 227 |
spacing: Nheko.paddingSmall |
| 228 |
clip: true |
| 229 |
|
| 230 |
delegate: Avatar { |
| 231 |
height: sidebarAvatarSize |
| 232 |
width: sidebarAvatarSize |
| 233 |
url: modelData.url.replace("mxc://", "image://MxcImage/") |
| 234 |
textColor: modelData.url.startsWith("mxc://") ? palette.text : palette.buttonText |
| 235 |
displayName: modelData.name |
| 236 |
roomid: modelData.name |
| 237 |
|
| 238 |
hoverEnabled: true |
| 239 |
ToolTip.visible: hovered |
| 240 |
ToolTip.delay: Nheko.tooltipDelay |
| 241 |
ToolTip.text: modelData.name |
| 242 |
onClicked: gridView.positionViewAtIndex(modelData.firstRowWith, ListView.Beginning) |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
ImageButton { |
| 247 |
Layout.row: 0 |
| 248 |
Layout.column: 0 |
| 249 |
Layout.preferredWidth: sidebarAvatarSize |
| 250 |
Layout.preferredHeight: sidebarAvatarSize |
| 251 |
Layout.rightMargin: Nheko.paddingSmall |
| 252 |
|
| 253 |
image: ":/icons/icons/ui/settings.svg" |
| 254 |
|
| 255 |
hoverEnabled: true |
| 256 |
ToolTip.visible: hovered |
| 257 |
ToolTip.delay: Nheko.tooltipDelay |
| 258 |
ToolTip.text: qsTr("Change what packs are enabled, remove packs, or create new ones") |
| 259 |
onClicked: TimelineManager.openImagePackSettings(stickerPopup.roomid) |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
} |