mirror of https://github.com/Nheko-Reborn/nheko
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
4.2 KiB
115 lines
4.2 KiB
4 years ago
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||
3 years ago
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||
4 years ago
|
//
|
||
4 years ago
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
|
||
4 years ago
|
import QtQuick 2.6
|
||
|
import QtQuick.Controls 2.2
|
||
4 years ago
|
import im.nheko 1.0
|
||
|
|
||
5 years ago
|
// This class is for showing Reactions in the timeline row, not for
|
||
|
// adding new reactions via the emoji picker
|
||
5 years ago
|
Flow {
|
||
4 years ago
|
id: reactionFlow
|
||
|
|
||
|
// highlight colors for selfReactedEvent background
|
||
3 years ago
|
property real highlightHue: timelineRoot.palette.highlight.hslHue
|
||
|
property real highlightSat: timelineRoot.palette.highlight.hslSaturation
|
||
|
property real highlightLight: timelineRoot.palette.highlight.hslLightness
|
||
4 years ago
|
property string eventId
|
||
|
property alias reactions: repeater.model
|
||
|
|
||
|
spacing: 4
|
||
|
|
||
|
Repeater {
|
||
|
id: repeater
|
||
|
|
||
|
delegate: AbstractButton {
|
||
|
id: reaction
|
||
|
|
||
|
hoverEnabled: true
|
||
|
implicitWidth: contentItem.childrenRect.width + contentItem.leftPadding * 2
|
||
|
implicitHeight: contentItem.childrenRect.height
|
||
|
ToolTip.visible: hovered
|
||
3 years ago
|
ToolTip.delay: Nheko.tooltipDelay
|
||
4 years ago
|
onClicked: {
|
||
|
console.debug("Picked " + modelData.key + "in response to " + reactionFlow.eventId + ". selfReactedEvent: " + modelData.selfReactedEvent);
|
||
4 years ago
|
room.input.reaction(reactionFlow.eventId, modelData.key);
|
||
4 years ago
|
}
|
||
3 years ago
|
Component.onCompleted: {
|
||
|
ToolTip.text = Qt.binding(function() {
|
||
|
if (textMetrics.elidedText === textMetrics.text) {
|
||
|
return modelData.users;
|
||
|
}
|
||
|
return modelData.displayKey + "\n" + modelData.users;
|
||
|
})
|
||
|
}
|
||
4 years ago
|
|
||
|
contentItem: Row {
|
||
|
anchors.centerIn: parent
|
||
|
spacing: reactionText.implicitHeight / 4
|
||
|
leftPadding: reactionText.implicitHeight / 2
|
||
|
rightPadding: reactionText.implicitHeight / 2
|
||
|
|
||
|
TextMetrics {
|
||
|
id: textMetrics
|
||
|
|
||
|
font.family: Settings.emojiFont
|
||
|
elide: Text.ElideRight
|
||
|
elideWidth: 150
|
||
3 years ago
|
text: modelData.displayKey
|
||
4 years ago
|
}
|
||
|
|
||
|
Text {
|
||
|
id: reactionText
|
||
|
|
||
|
anchors.baseline: reactionCounter.baseline
|
||
3 years ago
|
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;
|
||
|
}
|
||
4 years ago
|
font.family: Settings.emojiFont
|
||
3 years ago
|
color: reaction.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.text
|
||
4 years ago
|
maximumLineCount: 1
|
||
|
}
|
||
|
|
||
|
Rectangle {
|
||
|
id: divider
|
||
|
|
||
|
height: Math.floor(reactionCounter.implicitHeight * 1.4)
|
||
|
width: 1
|
||
3 years ago
|
color: (reaction.hovered || modelData.selfReactedEvent !== '') ? timelineRoot.palette.highlight : timelineRoot.palette.text
|
||
4 years ago
|
}
|
||
|
|
||
|
Text {
|
||
|
id: reactionCounter
|
||
|
|
||
|
anchors.verticalCenter: divider.verticalCenter
|
||
|
text: modelData.count
|
||
|
font: reaction.font
|
||
3 years ago
|
color: reaction.hovered ? timelineRoot.palette.highlight : timelineRoot.palette.text
|
||
4 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
background: Rectangle {
|
||
|
anchors.centerIn: parent
|
||
|
implicitWidth: reaction.implicitWidth
|
||
|
implicitHeight: reaction.implicitHeight
|
||
3 years ago
|
border.color: (reaction.hovered || modelData.selfReactedEvent !== '') ? timelineRoot.palette.highlight : timelineRoot.palette.text
|
||
|
color: modelData.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.2) : timelineRoot.palette.window
|
||
4 years ago
|
border.width: 1
|
||
|
radius: reaction.height / 2
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
}
|