2020-08-12 15:01:03 +00:00
|
|
|
import QtQuick 2.3
|
2020-11-23 09:50:00 +00:00
|
|
|
import QtQuick.Controls 2.13
|
2021-01-25 20:50:42 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2020-08-12 15:01:03 +00:00
|
|
|
import "../../../../../shared"
|
2021-01-25 20:50:42 +00:00
|
|
|
import "../../../../../shared/status"
|
2020-08-12 15:01:03 +00:00
|
|
|
import "../../../../../imports"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
property int imageMargin: 4
|
2021-01-25 20:50:42 +00:00
|
|
|
signal hoverChanged(bool hovered)
|
|
|
|
|
2020-08-12 15:01:03 +00:00
|
|
|
id: root
|
|
|
|
height: 20
|
|
|
|
width: childrenRect.width
|
|
|
|
|
2020-12-02 06:24:36 +00:00
|
|
|
function lastTwoItems(nodes) {
|
|
|
|
return nodes.join(qsTr(" and "));
|
2020-11-23 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 16:24:45 +00:00
|
|
|
function showReactionAuthors(fromAccounts, emojiId) {
|
|
|
|
let tooltip
|
|
|
|
if (fromAccounts.length === 1) {
|
|
|
|
tooltip = fromAccounts[0]
|
|
|
|
} else if (fromAccounts.length === 2) {
|
|
|
|
tooltip = lastTwoItems(fromAccounts);
|
|
|
|
} else {
|
|
|
|
var leftNode = [];
|
|
|
|
var rightNode = [];
|
|
|
|
const maxReactions = 12
|
|
|
|
let maximum = Math.min(maxReactions, fromAccounts.length)
|
2020-11-23 22:50:40 +00:00
|
|
|
|
2021-02-02 16:24:45 +00:00
|
|
|
if (fromAccounts.length > maxReactions) {
|
|
|
|
leftNode = fromAccounts.slice(0, maxReactions);
|
|
|
|
rightNode = fromAccounts.slice(maxReactions, fromAccounts.length);
|
|
|
|
return (rightNode.length === 1) ?
|
|
|
|
lastTwoItems([leftNode.join(", "), rightNode[0]]) :
|
|
|
|
lastTwoItems([leftNode.join(", "), qsTr("%1 more").arg(rightNode.length)]);
|
|
|
|
}
|
2020-11-23 22:50:40 +00:00
|
|
|
|
2021-02-02 16:24:45 +00:00
|
|
|
leftNode = fromAccounts.slice(0, maximum - 1);
|
|
|
|
rightNode = fromAccounts.slice(maximum - 1, fromAccounts.length);
|
|
|
|
tooltip = lastTwoItems([leftNode.join(", "), rightNode[0]])
|
2020-11-23 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 16:24:45 +00:00
|
|
|
tooltip += qsTr(" reacted with ");
|
|
|
|
|
|
|
|
switch (emojiId) {
|
|
|
|
case 1: return tooltip + ":heart:"
|
|
|
|
case 2: return tooltip + ":thumbsup:"
|
|
|
|
case 3: return tooltip + ":thumbsdown:"
|
|
|
|
case 4: return tooltip + ":laughing:"
|
|
|
|
case 5: return tooltip + ":cry:"
|
|
|
|
case 6: return tooltip + ":angry:"
|
|
|
|
default: return tooltip
|
|
|
|
}
|
2020-11-23 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
Row {
|
|
|
|
spacing: root.imageMargin
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: reactionRepeater
|
|
|
|
width: childrenRect.width
|
2021-02-01 20:37:50 +00:00
|
|
|
model: emojiReactionsModel
|
2020-08-12 15:01:03 +00:00
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
Rectangle {
|
|
|
|
property bool isHovered: false
|
|
|
|
|
|
|
|
id: emojiContainer
|
|
|
|
width: emojiImage.width + emojiCount.width + (root.imageMargin * 2) + + 8
|
|
|
|
height: 20
|
|
|
|
radius: 10
|
2021-02-02 16:54:29 +00:00
|
|
|
color: modelData.currentUserReacted ?
|
|
|
|
(isHovered ? Style.current.emojiReactionActiveBackgroundHovered : Style.current.secondaryBackground) :
|
|
|
|
(isHovered ? Style.current.emojiReactionBackgroundHovered : Style.current.emojiReactionBackground)
|
2021-01-25 20:50:42 +00:00
|
|
|
|
2021-02-02 16:24:45 +00:00
|
|
|
StatusToolTip {
|
2021-01-25 20:50:42 +00:00
|
|
|
visible: mouseArea.containsMouse
|
2021-02-10 16:32:45 +00:00
|
|
|
maxWidth: 400
|
2021-02-02 16:24:45 +00:00
|
|
|
text: showReactionAuthors(modelData.fromAccounts, modelData.emojiId)
|
2021-01-25 20:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rounded corner to cover one corner
|
|
|
|
Rectangle {
|
|
|
|
color: parent.color
|
2021-02-02 16:54:29 +00:00
|
|
|
width: 10
|
|
|
|
height: 10
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.top: parent.top
|
2021-02-10 20:41:00 +00:00
|
|
|
anchors.left: !isCurrentUser || appSettings.useCompactMode ? parent.left : undefined
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.leftMargin: 0
|
2021-02-10 20:41:00 +00:00
|
|
|
anchors.right: !isCurrentUser || appSettings.useCompactMode ? undefined : parent.right
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.rightMargin: 0
|
|
|
|
radius: 2
|
|
|
|
z: -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a workaround to get a "border" around the rectangle including the weird rectangle
|
|
|
|
Loader {
|
|
|
|
active: modelData.currentUserReacted
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: -1
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: -1
|
|
|
|
z: -2
|
|
|
|
|
|
|
|
sourceComponent: Component {
|
|
|
|
Rectangle {
|
|
|
|
width: emojiContainer.width + 2
|
|
|
|
height: emojiContainer.height + 2
|
|
|
|
radius: emojiContainer.radius
|
|
|
|
color: Style.current.primary
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
color: parent.color
|
2021-02-02 16:54:29 +00:00
|
|
|
width: 10
|
|
|
|
height: 10
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.top: parent.top
|
2021-02-10 20:41:00 +00:00
|
|
|
anchors.left: !isCurrentUser || appSettings.useCompactMode ? parent.left : undefined
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.leftMargin: 0
|
2021-02-10 20:41:00 +00:00
|
|
|
anchors.right: !isCurrentUser || appSettings.useCompactMode ? undefined : parent.right
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.rightMargin: 0
|
|
|
|
radius: 2
|
|
|
|
z: -1
|
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: emojiImage
|
|
|
|
width: 15
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: {
|
|
|
|
const basePath = "../../../../img/emojiReactions/"
|
|
|
|
switch (modelData.emojiId) {
|
|
|
|
case 1: return basePath + "heart.svg"
|
|
|
|
case 2: return basePath + "thumbsUp.svg"
|
|
|
|
case 3: return basePath + "thumbsDown.svg"
|
|
|
|
case 4: return basePath + "laughing.svg"
|
|
|
|
case 5: return basePath + "sad.svg"
|
|
|
|
case 6: return basePath + "angry.svg"
|
|
|
|
default: return ""
|
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: root.imageMargin
|
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
StyledText {
|
|
|
|
id: emojiCount
|
|
|
|
text: modelData.count
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: emojiImage.right
|
|
|
|
anchors.leftMargin: root.imageMargin
|
|
|
|
font.pixelSize: 12
|
|
|
|
color: modelData.currentUserReacted ? Style.current.textColorTertiary : Style.current.textColor
|
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onEntered: {
|
|
|
|
root.hoverChanged(true)
|
|
|
|
emojiContainer.isHovered = true
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
root.hoverChanged(false)
|
|
|
|
emojiContainer.isHovered = false
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
chatsModel.toggleReaction(messageId, modelData.emojiId)
|
2020-08-12 15:01:03 +00:00
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 09:50:00 +00:00
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
}
|
2020-11-23 09:50:00 +00:00
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
Item {
|
|
|
|
width: addEmojiBtn.width + addEmojiBtn.anchors.leftMargin // there is more margin between the button and the emojis than between each emoji
|
|
|
|
height: addEmojiBtn.height
|
2020-08-12 15:01:03 +00:00
|
|
|
|
|
|
|
SVGImage {
|
2021-01-25 20:50:42 +00:00
|
|
|
property bool isHovered: false
|
|
|
|
|
|
|
|
id: addEmojiBtn
|
|
|
|
source: "../../../../img/emoji.svg"
|
|
|
|
width: 16.5
|
|
|
|
height: 16.5
|
2020-08-12 15:01:03 +00:00
|
|
|
anchors.left: parent.left
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.leftMargin: 2.5
|
|
|
|
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 20:50:42 +00:00
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: addEmojiBtn
|
|
|
|
antialiasing: true
|
|
|
|
source: addEmojiBtn
|
|
|
|
color: addEmojiBtn.isHovered ? Style.current.primary : Style.current.secondaryText
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
2020-08-12 18:53:59 +00:00
|
|
|
|
|
|
|
MouseArea {
|
2021-01-25 20:50:42 +00:00
|
|
|
anchors.fill: addEmojiBtn
|
2020-08-12 18:53:59 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
2021-01-25 20:50:42 +00:00
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: addEmojiBtn.isHovered = true
|
|
|
|
onExited: addEmojiBtn.isHovered = false
|
2020-08-12 18:53:59 +00:00
|
|
|
onClicked: {
|
2021-02-08 18:46:20 +00:00
|
|
|
if (typeof isMessageActive !== "undefined") {
|
|
|
|
isMessageActive = true
|
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
clickMessage(false, false, false, null, true)
|
2020-08-12 18:53:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
|
|
|
|
StatusToolTip {
|
|
|
|
visible: addEmojiBtn.isHovered
|
|
|
|
text: qsTr("Add reaction")
|
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|