matrixion/qml/Reactions.qml

101 lines
4.2 KiB
QML
Raw Permalink Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.6
import QtQuick.Controls 2.2
import im.nheko
2020-06-24 17:24:22 +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-04-16 03:13:01 +03:00
property string eventId
2020-10-08 22:11:21 +03:00
// highlight colors for selfReactedEvent background
2022-04-11 05:18:16 +03:00
property real highlightHue: timelineRoot.palette.highlight.hslHue
property real highlightLight: timelineRoot.palette.highlight.hslLightness
2022-04-16 03:13:01 +03:00
property real highlightSat: timelineRoot.palette.highlight.hslSaturation
2020-10-08 22:11:21 +03:00
property alias reactions: repeater.model
spacing: 4
Repeater {
id: repeater
delegate: AbstractButton {
id: reaction
2022-04-16 03:13:01 +03:00
ToolTip.delay: Nheko.tooltipDelay
ToolTip.visible: hovered
2020-10-08 22:11:21 +03:00
hoverEnabled: true
implicitHeight: contentItem.childrenRect.height
2022-04-16 03:13:01 +03:00
implicitWidth: contentItem.childrenRect.width + contentItem.leftPadding * 2
2020-10-08 22:11:21 +03:00
2022-04-16 03:13:01 +03:00
background: Rectangle {
anchors.centerIn: parent
border.color: (reaction.hovered || modelData.selfReactedEvent !== '') ? timelineRoot.palette.highlight : timelineRoot.palette.text
border.width: 1
color: modelData.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.2) : timelineRoot.palette.window
implicitHeight: reaction.implicitHeight
implicitWidth: reaction.implicitWidth
radius: reaction.height / 2
}
2020-10-08 22:11:21 +03:00
contentItem: Row {
anchors.centerIn: parent
leftPadding: reactionText.implicitHeight / 2
rightPadding: reactionText.implicitHeight / 2
2022-04-16 03:13:01 +03:00
spacing: reactionText.implicitHeight / 4
2020-10-08 22:11:21 +03:00
TextMetrics {
id: textMetrics
elide: Text.ElideRight
elideWidth: 150
2022-04-16 03:13:01 +03:00
font.family: Settings.emojiFont
text: modelData.displayKey
2020-10-08 22:11:21 +03:00
}
Text {
id: reactionText
anchors.baseline: reactionCounter.baseline
2022-04-16 03:13:01 +03:00
color: reaction.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.text
font.family: Settings.emojiFont
maximumLineCount: 1
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
}
Rectangle {
id: divider
2022-04-16 03:13:01 +03:00
color: (reaction.hovered || modelData.selfReactedEvent !== '') ? timelineRoot.palette.highlight : timelineRoot.palette.text
2020-10-08 22:11:21 +03:00
height: Math.floor(reactionCounter.implicitHeight * 1.4)
width: 1
}
Text {
id: reactionCounter
anchors.verticalCenter: divider.verticalCenter
2022-04-11 05:18:16 +03:00
color: reaction.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.text
2022-04-16 03:13:01 +03:00
font: reaction.font
text: modelData.count
2020-10-08 22:11:21 +03:00
}
}
2022-04-16 03:13:01 +03:00
Component.onCompleted: {
ToolTip.text = Qt.binding(function () {
if (textMetrics.elidedText === textMetrics.text) {
return modelData.users;
}
return modelData.displayKey + "\n" + modelData.users;
});
}
onClicked: {
console.debug("Picked " + modelData.key + "in response to " + reactionFlow.eventId + ". selfReactedEvent: " + modelData.selfReactedEvent);
room.input.reaction(reactionFlow.eventId, modelData.key);
2020-10-08 22:11:21 +03:00
}
}
}
}