2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-07 07:57:56 +03:00
|
|
|
//
|
2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-01-12 17:03:39 +03:00
|
|
|
import QtQuick 2.6
|
|
|
|
import QtQuick.Controls 2.2
|
2020-06-24 17:24:22 +03:00
|
|
|
import im.nheko 1.0
|
|
|
|
|
2020-05-22 04:21:35 +03:00
|
|
|
// This class is for showing Reactions in the timeline row, not for
|
|
|
|
// adding new reactions via the emoji picker
|
2020-05-04 01:59:05 +03:00
|
|
|
Flow {
|
2020-10-08 22:11:21 +03:00
|
|
|
id: reactionFlow
|
|
|
|
|
2022-08-20 06:22:32 +03:00
|
|
|
// lower-contrast colors to avoid distracting from text & to enhance hover effect
|
|
|
|
property color gentleHighlight: Qt.hsla(Nheko.colors.highlight.hslHue, Nheko.colors.highlight.hslSaturation, Nheko.colors.highlight.hslLightness, 0.8)
|
|
|
|
property color gentleText: Qt.hsla(Nheko.colors.text.hslHue, Nheko.colors.text.hslSaturation, Nheko.colors.text.hslLightness, 0.6)
|
2020-10-08 22:11:21 +03:00
|
|
|
property string eventId
|
|
|
|
property alias reactions: repeater.model
|
|
|
|
|
|
|
|
spacing: 4
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: repeater
|
|
|
|
|
|
|
|
delegate: AbstractButton {
|
|
|
|
id: reaction
|
|
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
ToolTip.visible: hovered
|
2022-01-01 08:37:15 +03:00
|
|
|
ToolTip.delay: Nheko.tooltipDelay
|
2020-10-08 22:11:21 +03:00
|
|
|
onClicked: {
|
|
|
|
console.debug("Picked " + modelData.key + "in response to " + reactionFlow.eventId + ". selfReactedEvent: " + modelData.selfReactedEvent);
|
2021-05-28 23:14:59 +03:00
|
|
|
room.input.reaction(reactionFlow.eventId, modelData.key);
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
2022-03-09 12:25:23 +03:00
|
|
|
Component.onCompleted: {
|
|
|
|
ToolTip.text = Qt.binding(function() {
|
|
|
|
if (textMetrics.elidedText === textMetrics.text) {
|
|
|
|
return modelData.users;
|
|
|
|
}
|
|
|
|
return modelData.displayKey + "\n" + modelData.users;
|
|
|
|
})
|
|
|
|
}
|
2023-05-27 04:10:02 +03:00
|
|
|
leftPadding: textMetrics.height / 2
|
|
|
|
rightPadding: textMetrics.height / 2
|
2020-10-08 22:11:21 +03:00
|
|
|
|
|
|
|
contentItem: Row {
|
2023-05-27 04:10:02 +03:00
|
|
|
spacing: textMetrics.height / 4
|
2020-10-08 22:11:21 +03:00
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
id: textMetrics
|
|
|
|
|
|
|
|
font.family: Settings.emojiFont
|
|
|
|
elide: Text.ElideRight
|
|
|
|
elideWidth: 150
|
2022-01-01 08:37:15 +03:00
|
|
|
text: modelData.displayKey
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: reactionText
|
|
|
|
|
|
|
|
anchors.baseline: reactionCounter.baseline
|
2022-03-09 20:37:50 +03:00
|
|
|
text: {
|
|
|
|
// When an emoji font is selected that doesn't have …, it is dropped from elidedText. So we add it back.
|
|
|
|
if (textMetrics.elidedText !== modelData.displayKey) {
|
|
|
|
if (!textMetrics.elidedText.endsWith("…")) {
|
|
|
|
return textMetrics.elidedText + "…";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return textMetrics.elidedText;
|
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
font.family: Settings.emojiFont
|
2022-08-20 06:22:32 +03:00
|
|
|
color: (reaction.hovered || modelData.selfReactedEvent !== '') ? Nheko.colors.highlightedText: Nheko.colors.text
|
2020-10-08 22:11:21 +03:00
|
|
|
maximumLineCount: 1
|
2023-05-27 04:10:02 +03:00
|
|
|
visible: !modelData.key.startsWith("mxc://")
|
|
|
|
}
|
|
|
|
Image {
|
|
|
|
anchors.verticalCenter: divider.verticalCenter
|
|
|
|
height: textMetrics.height
|
|
|
|
width: textMetrics.height
|
|
|
|
source: modelData.key.startsWith("mxc://") ? (modelData.key.replace("mxc://", "image://MxcImage/") + "?scale") : ""
|
|
|
|
visible: modelData.key.startsWith("mxc://")
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: divider
|
|
|
|
|
|
|
|
height: Math.floor(reactionCounter.implicitHeight * 1.4)
|
|
|
|
width: 1
|
2022-08-20 06:22:32 +03:00
|
|
|
color: reaction.hovered ? Nheko.colors.text: gentleText
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: reactionCounter
|
|
|
|
|
|
|
|
anchors.verticalCenter: divider.verticalCenter
|
|
|
|
text: modelData.count
|
|
|
|
font: reaction.font
|
2022-08-20 06:22:32 +03:00
|
|
|
color: (reaction.hovered || modelData.selfReactedEvent !== '') ? Nheko.colors.highlightedText: Nheko.colors.windowText
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
implicitWidth: reaction.implicitWidth
|
|
|
|
implicitHeight: reaction.implicitHeight
|
2022-08-20 06:22:32 +03:00
|
|
|
border.color: reaction.hovered ? Nheko.colors.text: gentleText
|
|
|
|
color: reaction.hovered ? Nheko.colors.highlight : (modelData.selfReactedEvent !== '' ? gentleHighlight : Nheko.colors.window)
|
2020-10-08 22:11:21 +03:00
|
|
|
border.width: 1
|
|
|
|
radius: reaction.height / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-05-04 01:59:05 +03:00
|
|
|
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|