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
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2021-10-01 15:58:36 +00:00
|
|
|
import "../../../../shared"
|
|
|
|
import "../../../../shared/panels"
|
|
|
|
import "../../../../shared/status"
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2020-08-12 15:01:03 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
height: 20
|
|
|
|
width: childrenRect.width
|
|
|
|
|
2021-07-16 15:02:47 +00:00
|
|
|
property int imageMargin: 4
|
2021-10-01 15:58:36 +00:00
|
|
|
// property bool isCurrentUser
|
|
|
|
// property var emojiReactionsModel
|
|
|
|
// property bool isMessageActive
|
2021-07-16 15:02:47 +00:00
|
|
|
signal addEmojiClicked()
|
2021-10-01 15:58:36 +00:00
|
|
|
signal hoverChanged(bool hovered)
|
|
|
|
signal toggleReaction(int emojiID)
|
|
|
|
signal setMessageActive(string messageId, bool active)
|
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
|
2021-04-07 16:28:49 +00:00
|
|
|
height: 15
|
2021-01-25 20:50:42 +00:00
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: {
|
|
|
|
switch (modelData.emojiId) {
|
2021-09-28 15:04:06 +00:00
|
|
|
case 1: return Style.svg("emojiReactions/heart")
|
|
|
|
case 2: return Style.svg("emojiReactions/thumbsUp")
|
|
|
|
case 3: return Style.svg("emojiReactions/thumbsDown")
|
|
|
|
case 4: return Style.svg("emojiReactions/laughing")
|
|
|
|
case 5: return Style.svg("emojiReactions/sad")
|
|
|
|
case 6: return Style.svg("emojiReactions/angry")
|
2021-01-25 20:50:42 +00:00
|
|
|
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: {
|
2021-10-01 15:58:36 +00:00
|
|
|
toggleReaction(modelData.emojiId)
|
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
|
2021-09-28 15:04:06 +00:00
|
|
|
source: Style.svg("emoji")
|
2021-01-25 20:50:42 +00:00
|
|
|
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") {
|
2021-10-01 15:58:36 +00:00
|
|
|
setMessageActive(messageId, true);
|
2021-02-08 18:46:20 +00:00
|
|
|
}
|
2021-07-16 15:02:47 +00:00
|
|
|
root.addEmojiClicked();
|
2020-08-12 18:53:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-25 20:50:42 +00:00
|
|
|
|
|
|
|
StatusToolTip {
|
|
|
|
visible: addEmojiBtn.isHovered
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Add reaction"
|
|
|
|
text: qsTrId("add-reaction")
|
2021-01-25 20:50:42 +00:00
|
|
|
}
|
2020-08-12 15:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|